PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
sc=ppscreen
B=sc:size()
Bw=B.width
Bh=B.height
pos=pppoint
sqrt=math.sqrt
sin=math.sin
rand=math.random
se=ppsemml[1]

sc=0
gameover=false

o=ppoffscreen.new()
o:create(32,32)
o:circle(16,16,15)
o.hitmask=1
o.hitlength=8

o:pos(
  g:layout(
    o:size(),true,true,B))

function obj()
local r=pprect(0,0,32,32)
r.x=rand(0,Bw)
r.y=rand(0,Bh)
r.d=pos()
r.d.x=0
r.d.y=rand(10,20)/10
r.r=rand(10,600)
r.q=0
r.p=rand(-10,10)/1000
r.idle=function(s)
 s.q=s.q+s.p
 s:move(s.d)
 if s.y>Bh+16 then
  s.y=-16
 end
end
r.draw=function(s)
 local p
 p=s+pos(sin(s.q)*s.r,0)
 g:circle(
   p-pos(8,8),16,g.red)
 local h
 h=pprect(
   p.x-24,p.y-24,32,32)
 h.hitmask=1
 h.hitlength=16
 return h
end
return r
end

t={}
for i=1,50 do
local p=obj()
p.y=p.y-Bh
t[#t+1]=p
end

pt=pprect()
pt.hitmask=1
pt.hitlength=24
pt.set=function(s)
s.x=rand(0,Bw-32)
s.y=-32
end
pt.draw=function(s)
g:circle(
  pt+pppoint(16,16),16,
  g.yellow)
end
pt:set()

function start()
 if not gameover then
 pt.y=pt.y+1
 if pt.y>Bh then
  pt.y=-32
 end
 end
 pt:draw()
 if not gameover then
   o:drag(pptouch(),B)
 end
 o:draw()
 if not gameover then
  for i=1,#t do
   t[i]:idle()
  end
 end
 local h={}
 for i=1,#t do
  local u
  u=t[i]:draw()
  h[#h+1]=u
 end
 pphitcheck(h,{o},
  function(a,b)
   if not gameover then
     se:stop()
     se:play("o4cgcgcg")
   end
   gameover=true
  end)
 pphitcheck({pt},{o},
  function(a,b)
   sc=sc+1
   se:play("o7c")
   a:set()
  end)
 g:print("SCORE "..sc)
 if gameover then
   g:pos(88,160)
   g:print("GAME OVER",g.red)
 end
end