ཻ޻˻ོཻཻཻཻཻཻཻ""""""""""""""""""""""""""""3333333333333333333333333333DDDDDDDDDDDDDDDDDDDDDDDDDDDD`fffvgffgvffgvffwwffgvfgffvpww q pp````````PP@0      **:JJJ        %? """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""".""""""""".""""""""".""""""""""""""""""""""""""""""""""""""""""""""""""""""޻."""""""޻."""""""޻."""""""""""""""""⽻""""""⽻""""""⽻"""""""""""""""""޻."""""޻."""""޻.""""""""""""""""˻."""""˻."""""˻.""""""""""""""""޻."""""޻."""""޻."""""""""""""""".""""".""""".""""""""""""""""޻."""""޻."""""޻.""""""""""""""""޻."""""޻."""""޻.""""""""""""""""޻."""""޻."""""޻.""""""""""""""""޻."""""޻."""""޻.""""""""""""""""޻."""""޻."""""޻.""""""""""""""""޻."""""޻."""""޻."""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDD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DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDύύύύ޻޻޻޻˻˻˻˻ὼὼὼὼύύύύύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻύۻ -- title: Tower Stacker -- author: pngwen -- desc: Stack the tower! -- license: MIT License (change this to your license of choice) -- input: gamepad -- version: 1.0 -- script: lua function BOOT() resetGame() t=0 end function sfxSad() sfx(0,"G-2",15) end function sfxHappy() sfx(1,"G-4",15) end function resetGame() dx=1 score=0 yoff=0 colors={1,2,3,4,9} c1=choose(colors) c2=choose(colors) piece={x=240,y=136,dx=0,dy=0,c=0,w=0} blocks={{x=0,y=55,w=100,c=c1}, {x=70,y=95,w=100,c=c2}} frame=title end function updateBlock() blocks[1].x=blocks[1].x+dx if blocks[1].x>239-blocks[1].w or blocks[1].x<0 then dx=-dx end end function drawTower() local y for i=1,#blocks do drawBlock(blocks[i]) end end function drawWindows(b) local x,n if b.w<32 then return end n=b.w//24 x=b.x+b.w/2-(n*24)/2+4 for i=1,n do spr(1,x,b.y+yoff+10,0,1,0,0,2,2) x=x+24 end end function drawBlock(b) local y=b.y+yoff if b.w<1 then return end rect(b.x,y,b.w,40,b.c) drawWindows(b) line(b.x,y+39,b.x+b.w-1,y+39,14) end function playerInput() if not btnp(4) then return false end cutBlock() dframe=0 frame=dropBlocks return true end function cutBlock() local x1,x2,ow x1=math.floor(blocks[1].x) x2=math.floor(blocks[2].x) dw=0 ow=blocks[1].w if x1x2 then dw=x2-x1 piece.dx=1 piece.x=x1+blocks[1].w+dw end blocks[1].w=blocks[1].w+dw piece.dy=3 piece.y=blocks[1].y piece.c=blocks[1].c piece.w=math.abs(dw) piece.w=math.min(piece.w,ow) if piece.w<4 and blocks[1].w>=1 then sfxHappy() else sfxSad() end end function handlePiece() if piece.x>=240 or piece.y>=136 or piece.w==0 then return end rect(piece.x,piece.y,piece.w,40,piece.c) piece.x=piece.x+piece.dx piece.y=piece.y+piece.dy end function dropBlocks() if #blocks==3 and blocks[1].w>=1 then yoff=yoff+2 end dframe=dframe+1 drawTower() handlePiece() if dframe>20 then finishDrop() end end function finishDrop() local y=blocks[1].y if blocks[1].w<1 then frame=gameOver return end if #blocks<3 then y=y-40 blocks[3]={y=blocks[2].y} blocks[2].y=blocks[1].y end for i=3,2,-1 do blocks[i].x=blocks[i-1].x blocks[i].c=blocks[i-1].c blocks[i].w=blocks[i-1].w end blocks[1].y=y blocks[1].c=choose(colors) yoff=0 dx=math.abs(dx)+0.05 blocks[1].x=0 score=score+1 frame=play end function choose(l) local c=l[math.random(#l)] return c end function play() if not playerInput() then updateBlock() end drawTower() end function gameOver() local cx,msg msg="GAME OVER" cx=print(msg,-100,-100,12,false,2) cx=120-cx/2 drawTower() print(msg,cx,20,13,false,2) if btnp(4) then frame=title end end function status() local msg=score if score==1 then msg=msg.." story" else msg=msg.." stories" end local w=print(msg,-100,-100) print(msg,238-w,2,12) end function title() local lx1,lx2,y,tx,str lx1=24*math.sin(0.05*t)+16 lx2=24*math.cos(0.05*t) y=10 str="/z to Stack" tx=print(str,-10,-10)+9 tx=120-tx/2 map(0,1,25,5,lx1,y,0) map(0,7,33,5,lx2,y+48,0) spr(217,184,112,0,1,0,0,56,24) spr(197,tx,112,0) print(str,tx+9,114,12) if btnp(4) then resetGame() score=1 frame=play end end function TIC() t=t+1 cls(0) frame() status() end