PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph

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

se=ppsemml[1]

function rect(c,d,k)
local r
r=pprect(0,0,d,d)
r.r=d/2
r.k=k
r.draw=function(s)
g:circle(s,s.r,c)
end
r.cal=function(s,p,d)
local l
l=s:length(p)
if l<s.r then
l=(s:pos()-p:pos())*s.k/l
d=d+l*d:length()
end
return d
end
return r
end

b=rect(g.white,16)
b:pos(Bw/2,Bh-100)
b.d=pppoint()
b.idle=function(s)
s:pos(s:pos()+s.d)
s.d=s.d*0.97
if s.x<0 or s.x>Bw then
 s.d.x=-s.d.x
end
if s.y<0 or s.y>Bh then
 s.d.y=-s.d.y
end
if s.d:length()<0.05 then
 s.d=pppoint()
end
end

t=rect(g.cyan,24)
t:pos(Bw/2,100)
dx=math.random(0,100)
t:move(dx-50,0)

c=rect(g.yellow,24)
c.touch=false

function slop(r,b,x,y)
local a
a=rect(g.green,r,b)
a:pos(x,y)
return a
end

p={}
a=slop(200,1/40,160,160)
p[#p+1]=a
a=slop(200,1/80,100,260)
p[#p+1]=a
a=slop(300,1/100,200,360)
p[#p+1]=a

bt=ppbutton("RETRY")
bt:pos(
 g:layout(bt,true,true,B))
bt:move(0,32)

cupin=false
hit=0

function start()
local tc
tc=pptouch()
if b.d:length()==0 then
  d=ppvkey:dir(4)
  if d>=0 then
  local q
  q=b:pos()
  q=q+ppvkey:delta()/2
  c:pos(q)
  c:draw()
  c.touch=true
  else
  if c.touch then
  c.touch=false
  local d=ppvkey:delta()/20
  b.d=b.d-d
  hit=hit+1
  se:play("O6c")
  end
  end
end
if b.d:length()<8 then
 if b:length(t)<8 then
    if not cupin then
      cupin=true
      b.d=pppoint()
      b:pos(t)
      se:play("O7crcrc")
    end
 end
end
for i,v in ipairs(p) do
b.d=v:cal(b,b.d)
end
b:idle()
b:draw()
t:draw()
for i,v in ipairs(p) do
 v:draw()
end
if cupin then
if bt:idle(tc) then
  b:pos(Bw/2,Bh-100)
  b.d=pppoint()
  t:pos(Bw/2,100)
  dx=math.random(0,100)
  t:move(dx-50,0)
  hit=0
  cupin=false
end
bt:draw()
g:pos(bt)
g:move(0,-32)
g:print("CUP IN!",g.yellow)
end
g:pos(0,0)
g:print("PAT "..hit)
end