0,]']>S}Wup8d%qy)6o;]AsVl3>???????????????????? /// T T T//////////////////////""""""""""""""""""""""""""""""""""""""""""""""""""""""`"""""""""`"""""""f"""""f""""f"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""."""""."""""."""""DDDDDDDDDDDDDDDDDDDDDDDDDDDNDDDDNDDDDNDDDDDDDDDDDDDDDDN -- title: fruity knife -- author: rodigu -- desc: fruit ninja demake for the uiuc fablab summer camps -- site: rodigu.github.com -- license: MIT License (change this to your license of choice) -- version: 0.1 -- script: lua Fruits = {} CutFruits = {} SCORE = 0 HEALTH = 3 function createFruit(id,x,y,xspeed,yspeed,cut) return { x=x, y=y, id=id, vel={x=xspeed,y=yspeed}, acc={x=0,y=.1}, cut=cut } end function xyUpdate(a,b) a.x = a.x + b.x a.y = a.y + b.y end function updateFruit(f,canCut) xyUpdate(f,f.vel) xyUpdate(f.vel,f.acc) bottomRight = {x=f.x+8*3,y=f.y+8*3} local x,y=mouse() if pointInRect(x,y,f,bottomRight) and (canCut) and (not f.cut) then f.cut = true sfx(0,math.random(10,30)) SCORE=SCORE+1 table.insert(CutFruits,createFruit(f.id+1,f.x,f.y,-1,-1,false)) table.insert(CutFruits,createFruit(f.id+2,f.x,f.y,1,-1,false)) end if f.y > 140 and canCut then f.vel.y = math.random() * (-2) - 3.5 f.y = 136 f.x = math.random(0,240-3*8) if not f.cut then HEALTH=HEALTH-1 sfx(1,15) end f.cut = false end if f.y > 140 and not canCut then removeCutFruit(f) end end function removeCutFruit(fruit) local idx = -1 for i,f in ipairs(CutFruits) do if fruit==f then idx = i break end end table.remove(CutFruits,idx) end function pointInRect(x,y,top,bottom) return x < bottom.x and x > top.x and y > top.y and y < bottom.y end function drawFruit(f) if f.cut then return end spr(f.id,f.x,f.y,0,3) end function newFruit(id) return createFruit(id,math.random(0,240-3*8),136,0,(math.random() * (-2)) - 3.5,false) end table.insert(Fruits,newFruit(256)) table.insert(Fruits,newFruit(272)) mouseTrack = {} function updateMouseTrack() local x,y = mouse() if #mouseTrack > 10 then table.remove(mouseTrack,1) end table.insert(mouseTrack,{x=x,y=y}) end function drawMouseTrail() prev = mouseTrack[1] for _,p in pairs(mouseTrack) do line(prev.x,prev.y,p.x,p.y,12) prev = p end end function updateHealth() for i=1,3 do if i<=HEALTH then spr(260,10+8*2*i,2,0,2) else spr(261,10+8*2*i,2,0,2) end end end function TIC() poke(0x3FFB,3) cls() updateMouseTrack() drawMouseTrail() for _,f in pairs(Fruits) do updateFruit(f,true) drawFruit(f) end for _,f in pairs(CutFruits) do updateFruit(f) drawFruit(f) end print(SCORE,240/2-4*2,5,12,true,2) updateHealth() end