67 lines
1.1 KiB
Lua
67 lines
1.1 KiB
Lua
|
deck={
|
||
|
suits={"p","s","c","w"},
|
||
|
cards={},
|
||
|
|
||
|
rank_name="a23456789tjqk"
|
||
|
}
|
||
|
-- pentacles, swords, cups, wands
|
||
|
for suit in all(deck.suits) do
|
||
|
for rank=1,13 do
|
||
|
add(deck.cards,{suit=suit,rank=rank})
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- arcana
|
||
|
for rank=0,21 do
|
||
|
add(deck.cards,{suit="a",rank=rank})
|
||
|
end
|
||
|
|
||
|
assert(#deck.cards==74)
|
||
|
deck.aces={1,14,27,40}
|
||
|
for i in all(deck.aces) do
|
||
|
assert(deck.cards[i].rank==1)
|
||
|
end
|
||
|
|
||
|
function deck:draw_card(x,y,c,shadow)
|
||
|
local meta=deck.cards[c]
|
||
|
|
||
|
local s,fg
|
||
|
|
||
|
local bg,shadowbg
|
||
|
if meta.suit=='a' then
|
||
|
bg,shadowbg=1,1
|
||
|
if (shadow) bg,shadowbg=1,0
|
||
|
else
|
||
|
bg,shadowbg=7,7
|
||
|
--if (shadow) bg,shadowbg=7,6
|
||
|
end
|
||
|
|
||
|
rectfill(x,y,x+8,y+4,bg)
|
||
|
rectfill(x,y+5,x+8,y+15,shadowbg)
|
||
|
|
||
|
if (meta.suit=='p') s,fg=0,4
|
||
|
if (meta.suit=='s') s,fg=1,12
|
||
|
if (meta.suit=='c') s,fg=2,2
|
||
|
if (meta.suit=='w') s,fg=3,3
|
||
|
if (meta.suit=='a') fg=15
|
||
|
|
||
|
if meta.suit=='a' then
|
||
|
local rank=""..meta.rank
|
||
|
pal(7,15)
|
||
|
print(meta.rank,x+5-#rank*2,y+1,7)
|
||
|
spr(4,x,y+8)
|
||
|
pal()
|
||
|
else
|
||
|
local name=sub(deck.rank_name,meta.rank,meta.rank)
|
||
|
rectfill(x,y,x+3,y+6,fg)
|
||
|
print(name,x,y+1,7)
|
||
|
pal(7,fg)
|
||
|
spr(s,x+5,y+1)
|
||
|
if not shadow then
|
||
|
spr(15+meta.rank,x,y+8)
|
||
|
end
|
||
|
pal()
|
||
|
end
|
||
|
|
||
|
return fg
|
||
|
end
|