PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph
B=ppscreen:size()
Bh=B.height
floor=math.floor

se=ppsemml[1]

o=ppoffscreen.new()
function rect(i)
local r
r=pprect(i*64,0,64,100)
return r
end
o:create(64*7,100*1)
o:fill(rect(1),g.white)
o:box(rect(1),g.black)
o:fill(rect(2),g.black)
o:fill(rect(3),g.yellow)
o:fill(rect(4),g.white)
o:fill(rect(4):inset(16),g.red)
o:fill(rect(5),g.black)
o:fill(rect(5):inset(16),g.red)
o:fill(rect(6),g.blue)
o:bind()

m=ppmap.new()
m:addLayer("chip")
m:mapSize(10,10)
m:clip(0,0,10,10)
m:tileSize(64,100)
m:texture(o:texture())

m.set=function(s,y)
 local x
 for x=0,4 do
   s:tile(x,y,2)
 end
 x=math.random(1,5)-1
 s:tile(x,y,1)
end

m.goal=function(s)
for x=0,5 do
s:tile(x,0,4)
end
end

m.start=function(s)
for x=0,5 do
s:tile(x,5,7)
end
end

for y=1,10 do
 m:set(y)
end
m:start()

function btn(x)
local r
r=pprect(x*64,0,64,200)
r.y=Bh-r.height
return r
end

bt={}
for i=0,4 do
bt[#bt+1]=btn(i)
end

gameover=false
goal=false
ct=0
tm=0

function start()
t=pptouch()
if not gameover 
and not goal then
tm=tm+1
for i,r in ipairs(bt) do
 if r:hitCheck(t) then
 end
 if r.touch then
   if r.pretouch==nil
   then
     r.pretouch=true
     if m:tile(i-1,4)==4
     then
       se:play("o6cgcgcg")
       goal=true
     else
       if m:tile(i-1,4)==2
       then
         gameover=true
         se:play("o4cgcgcg")
         m:tile(i-1,4,5)
       else
         se:play("o7c")
         m:tile(i-1,4,6)
       end
     end
     m:scroll(0,1)
     ct=ct+1
     if ct==48 then
       m:goal()
     else
       m:set(0)
     end
   end
 else
   r.pretouch=nil
 end
end
end
m:draw()
g:scale(2)
if goal then
s="GOAL!"
z=ppfont:size(s)*2
g:pos(
  g:layout(z,true,true,B)/2)
g:move(8,-16)
g:print(s,g.red)
elseif gameover then
s="GAME OVER"
z=ppfont:size(s)*2
g:pos(
  g:layout(z,true,true,B)/2)
g:print(s,g.red)
end
g:move(0,16)
g:print(
  floor(tm*100/60)/100,g.red)
g:scale(1)
end