PicoPicoGameEngine

Quick Links

Source Code

B=ppscreen:size()
B.y=64
B.height=B.height-64

g=ppgraph

function bt(x,c,f)
 local b
 b=pprect(x,0,64,64)
 b.col=c
 b.doevent=f
 b.draw=function(s)
   if s.touch then
     g:fill(s,g.red)
   else
     g:fill(s,s.col)
   end
 end
 return b
end

b={}
b[#b+1]=bt(0,g.blue,
function(s)
 ppgame:start(blue_scn)
end)
b[#b+1]=bt(64,g.green,
function(s)
 ppgame:start(green_scn)
end)
b[#b+1]=bt(128,g.cyan,
function(s)
 ppgame:start(cyan_scn)
end)

function dobt()
 pt=pptouch()
 for i,b in ipairs(b) do
 if b:hitCheck(pt) then
   b:doevent()
   return true
 end
 b:draw()
 end
end

function blue_scn()
 while true do
 g:fill(B,g.blue)
 g:pos(0,64)
 g:print("BLUE")
 if dobt() then
   break
 end
 g:update()
 end
end

function green_scn()
 while true do
 g:fill(B,g.green)
 g:pos(0,64)
 g:print("GREEN")
 if dobt() then
   break
 end
 g:update()
 end
end

function cyan_scn()
 while true do
 g:fill(B,g.cyan)
 g:pos(0,64)
 g:print("CYAN")
 if dobt() then
   break
 end
 g:update()
 end
end

ppgame:start(blue_scn)