feat: add clearing

main
Louis Pearson 2024-02-15 01:13:16 -07:00
parent f2716a9816
commit d39e6a2585
1 changed files with 49 additions and 11 deletions

View File

@ -42,6 +42,12 @@ c_hover=nil
hand=nil hand=nil
locations={} locations={}
debug=false debug=false
render_list={}
mouse_pos=nil
last_left=false
current_stack=8
is_clearing=false
left_hold={length=1200,length_display=600,start=nil}
function create_deck() function create_deck()
local cards={} local cards={}
@ -90,7 +96,7 @@ function BOOT()
if debug then if debug then
for i=13,1,-1 do for i=13,1,-1 do
for a=1,4 do for a=1,4 do
table.insert(stacks[7+a], { table.insert(stacks[14-a], {
x=0,y=0,state=0, x=0,y=0,state=0,
rank=i, rank=i,
suit=a suit=a
@ -110,16 +116,12 @@ function BOOT()
end end
end end
render_list={}
function TIC() function TIC()
render_list={} render_list={}
update() update()
draw() draw()
end end
mouse_pos=nil
last_left=false
current_stack=8
function update() function update()
-- --
for j,stack in ipairs(stacks) do for j,stack in ipairs(stacks) do
@ -133,13 +135,24 @@ function update()
end end
end end
end end
local c_up=btnp(0,60,6) local c_up=btnp(0,30,6)
local c_down=btnp(1,60,6) local c_down=btnp(1,30,6)
local c_left=btnp(2,60,6) local c_left=btnp(2,30,6)
local c_right=btnp(3,60,6) local c_right=btnp(3,30,6)
local c_sel=btnp(5,60,6) local c_sel=btnp(5)
local c_back=btnp(4,60,6) local c_back=btnp(4)
local c_moved=c_up or c_down or c_left or c_right local c_moved=c_up or c_down or c_left or c_right
if not left_hold.start and c_sel then
left_hold.start=time()
elseif left_hold.start and not btn(5) then
left_hold.start=nil
elseif left_hold.start and btn(5) then
local elapsed=time()-left_hold.start
if elapsed>left_hold.length then
is_clearing=true
left_hold.start=nil
end
end
if not c_hover then if not c_hover then
if c_up or c_down or c_left or c_right then if c_up or c_down or c_left or c_right then
c_hover={8,#stacks[8]} c_hover={8,#stacks[8]}
@ -297,6 +310,20 @@ function update()
table.insert(render_list,c) table.insert(render_list,c)
end end
end end
if is_clearing then
hand=nil
local clear_count=0
for a=8,13 do
for i=3,6 do
if #stacks[a]==0 then break end
if move_sel({a,#stacks[a]}, {i,#stacks[i]}) then
clear_count=clear_count+1
break
end
end
end
if clear_count==0 then is_clearing=false end
end
last_left=left last_left=left
end end
@ -456,6 +483,17 @@ function draw()
end end
spr(49,x,y,14) spr(49,x,y,14)
end end
if left_hold.start then
local elapsed=time()-left_hold.start
local color=2
if elapsed/left_hold.length>0.5 then color=4 end
if elapsed > left_hold.length_display then
rect(200,0,40*(elapsed/left_hold.length),8,color)
end
end
if is_clearing then
rect(200,0,40,8,6)
end
end end
function render_card(c,x,y,state,below) function render_card(c,x,y,state,below)