PicoPicoGameEngine

Quick Links

ピコピココード

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

tex=pptex:load("main.png")

function obj(x,y)
local r
r=pprect()
r.t=1
r.n={}
r.x=x
r.y=y
r.s=0.1
r.init=function(s)
end
r.idle=function(s)
end
r.draw=function(s)
 s.t=s.t+s.s
 if s.t>=#s.n+1 then
   s.t=1
 end
 g:put(s.x,s.y,
       s.n[floor(s.t)],tex)
end
r.copy=function(s,x,y)
 local t
 t=obj(x,y)
 t.n=s.n
 t.s=s.s
 t.init=s.init
 t.idle=s.idle
 t.draw=s.draw
 t:init()
 return t
end
return r
end

function drawbg()
 g:fill(B,g.cyan)
 g:fill(0,200,Bw,Bh-200,g.green)
 g:fill(0,400,Bw,Bh-400,{0,128,0,255})
end

c=obj(0,0)
c.n={2,3}

man={}
man[#man+1]=c:copy(160-16,240)
man[#man+1]=c:copy(160-48,240-32)
man[#man+1]=c:copy(160+48,240+32)

c=obj(0,0)
c.n={4,5}
c.s=0.025
c.idle=function(s)
 s:move(0.2,0)
 if s.x>Bw then
   s.x=-32
 end
end

cl={}
cl[#cl+1]=c:copy(60,80)
cl[#cl+1]=c:copy(160,50)
cl[#cl+1]=c:copy(240,60)
cl[#cl+1]=c:copy(280,40)

c=obj(0,0)
c.n={6}
c.s=0.025
c.init=function(s)
 s.h=0
 s.dy=-8
 s.r=0
end
c.idle=function(s)
 s:move(1,0)
 if s.x>Bw then
   s.x=-32
 end
 s.h=s.h+s.dy
 s.dy=s.dy+0.4
 if s.h>0 then
   s.dy=-8
 end
 s.r=s.r+0.05
 if s.r>2*math.pi then
   s.r=s.r-2*math.pi
 end
end
c.draw=function(s)
g:put(s.x,s.y+16,7,tex)
g:pivot(s.x+16,s.y+s.h+16)
g:rotate(s.r)
g:put(s.x,s.y+s.h,
       s.n[1],tex)
g:rotate(0)
end

rk={}
rk[#rk+1]=c:copy(0,200)
rk[#rk+1]=c:copy(100,240)
rk[#rk+1]=c:copy(160,200)
rk[#rk+1]=c:copy(240,240)
rk[#rk+1]=c:copy( 80,300)
rk[#rk+1]=c:copy(140,280)

function start()
 drawbg()
 for i,o in ipairs(cl)
 do
   o:idle()
   o:draw()
 end
 for i,o in ipairs(rk)
 do
   o:idle()
   o:draw()
 end
 for i,o in ipairs(man)
 do
   o:idle()
   o:draw()
 end
end