PicoPicoGameEngine

Quick Links

ピコピココード

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

se=ppsemml[1]

function bar(x,y)
local r=pprect(x,y,64,4)
r.draw=function(s)
 g:fill(s)
end
return r
end

function ball(x,y)
local r=pprect(x,y,4,4)
r.d=pppoint(1,1)
r.idle=function(s,r,l)
s:move(s.d)
if s.x<0 or s.x>Bw-4 then
s.d.x=-s.d.x
end
if r:intersect(s)
then
s.d.y=-s.d.y
se:play("o7c")
local d
d=s.x+2-(r.width/2+r.x)
s.d.x=d/(r.width/2)
end
if l:intersect(s)
then
s.d.y=-s.d.y
se:play("o7c")
local d
d=s.x+2-(l.width/2+l.x)
s.d.x=d/(l.width/2)
end
end
r.draw=function(s)
 g:fill(s)
end
return r
end

c=ppsprite.new()
c:tileSize(64,4)

l=bar(0,0)
r=bar(0,Bh-4)

b=ball(160,(Bh-4)/2)

function mato()
local t
t=pppoint()
t.r=16
t.draw=function(s)
 g:circle(s.x,s.y,
   s.r,g.yellow)
end
t.set=function(s)
 local t
 t=math.random(16,Bw-16)
 s.x=t
 s.y=Bh/2
end
t:set()
return t
end

t={}
t[#t+1]=mato()
t[#t+1]=mato()
t[#t+1]=mato()

sc=0

function start()
c:drag(pptouch(),B)
l.x=c.x
r.x=c.x
for i=1,4 do
b:idle(r,l)
end
l:draw()
r:draw()
b:draw()
for i,t in ipairs(t) do
t:draw()
if t:length(b)<16 then
 t:set()
 sc=sc+1
 se:play("o7a")
end
end
g:pos(100,100)
g:print("SCORE "..sc)
end