diff --git a/solitaire.lua b/solitaire.lua index 668e821..0356a8d 100644 --- a/solitaire.lua +++ b/solitaire.lua @@ -42,6 +42,12 @@ c_hover=nil hand=nil locations={} 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() local cards={} @@ -90,7 +96,7 @@ function BOOT() if debug then for i=13,1,-1 do for a=1,4 do - table.insert(stacks[7+a], { + table.insert(stacks[14-a], { x=0,y=0,state=0, rank=i, suit=a @@ -110,16 +116,12 @@ function BOOT() end end -render_list={} function TIC() render_list={} update() draw() end -mouse_pos=nil -last_left=false -current_stack=8 function update() -- for j,stack in ipairs(stacks) do @@ -133,13 +135,24 @@ function update() end end end - local c_up=btnp(0,60,6) - local c_down=btnp(1,60,6) - local c_left=btnp(2,60,6) - local c_right=btnp(3,60,6) - local c_sel=btnp(5,60,6) - local c_back=btnp(4,60,6) + local c_up=btnp(0,30,6) + local c_down=btnp(1,30,6) + local c_left=btnp(2,30,6) + local c_right=btnp(3,30,6) + local c_sel=btnp(5) + local c_back=btnp(4) 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 c_up or c_down or c_left or c_right then c_hover={8,#stacks[8]} @@ -296,6 +309,20 @@ function update() c.below=j==2 table.insert(render_list,c) 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 end @@ -456,6 +483,17 @@ function draw() end spr(49,x,y,14) 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 function render_card(c,x,y,state,below)