PicoPicoGameEngine

Quick Links

ピコピココード

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

dragging=false

function obj()
local r
local x,y,w,h
w=rand(32,128)
h=rand(32,128)
x=rand(0,Bw-w)
y=rand(0,Bh-h)
r=pprect(x,y,w,h)
r.t1=function(s,t)
if #t>0 and not dragging then
if s:contain(t[1]) then
s.idle=s.t2
s.st=pppoint(s)
s.stouch=t[1]
s.touched=true
dragging=true
end
end
end
r.t2=function(s,t)
if #t==0 then
s.idle=s.t1
s.touched=nil
dragging=false
return
end
s:pos(s.st+t[1]-s.stouch)
end
r.idle=r.t1
r.draw=function(s)
if s.touched then
g:fill(s,g.red)
end
g:box(s)
end
return r
end

r={}
for i=1,10 do
r[#r+1]=obj()
end

function start()
touch=pptouch()
for i,o in ipairs(r) do
o:idle(touch)
r[#r-i+1]:draw()
end
end