PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
rand=math.random
B=ppscreen:size()
Bw=B.width
Bh=B.height

se=ppsemml[1]

sc=0

gameover=false

function obj()
local o
o=pprect()
o.col=g.white
o.draw=function(s)
g:circle(s,16,s.col)
end
return o
end

m=obj()
m.col=g.cyan
m:pos((Bw-32)/2,Bh/2)
m.dy=0
m.hitmask=1
m.hitlength=16
m.idle=function(s)
s.y=s.y+s.dy
s.dy=s.dy+0.1
end

o=ppsprite.new()
o:pos(m)

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,16,g.yellow)
end
pt:set()

e={}
for i=1,3 do
local t
t=obj()
t.dx=i
t.col=g.red
t.hitmask=1
t.hitlength=16
t.set=function(s)
s.y=rand(Bh/3,Bh)
s.x=rand(0,Bw)
end
t.idle=function(s)
s:move(-s.dx,0)
if s.x<-16 then
s:set()
s.x=Bw+16
end
end
t:set()
e[#e+1]=t
end

function start()
o:drag(pptouch(),B)
m.x=o.x+16
m:idle()
m:draw()
local d=(Bh-m.y)-Bh/2
if m.dy>12 then
d=0
end
m.y=m.y+d
for i=1,#e do
if not gameover then
e[i]:idle()
e[i].y=e[i].y+d
end
e[i]:draw()
end
if not gameover then
pt.y=pt.y+d
if pt.y>Bh then
 pt.y=-32
end
end
pt:draw()
if m.dy>0 then
pphitcheck(e,{m},
 function(a,b)
   b.dy=-6
  se:stop()
  se:play("o4c")
 end)
end
pphitcheck({pt},{m},
 function(a,b)
   sc=sc+1
   se:play("o7c")
   a:set()
 end)
if m.y>Bh then
if not gameover then
  se:play("o4cgcgcg")
end
  gameover=true
end
 g:print("SCORE "..sc)
 if gameover then
   g:pos(88,160)
   g:print("GAME OVER",g.red)
 end
end