PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph
s=ppscreen:size()

o=ppoffscreen.new()
o:create(32,32)
o:fill(0,0,32,32,g.green)
o:fill(4,4,24,24,{0,0,0,0})
o:hflip()
o:bind()

bt=ppbutton("MOVE!")
bt.bgcolor=g.blue
bt.width=300
bt.height=100
bt:pos(
  g:layout(
    bt:size(),true,true))
bt.bg.tile=1
bt.bg.texture=o:texture()
bt.bg.edge=4
bt.tp=pppoint(bt)

bt.moveidle=function(s)
  local q=pppoint(s)
  local d=(s.tp-q)/10
  if d.x<0 then
    d.x = math.floor(d.x)
  else
    d.x = math.ceil(d.x)
  end
  if d.y<0 then
    d.y = math.floor(d.y)
  else
    d.y = math.ceil(d.y)
  end
  s:move(d)
end

bt.y=s:size().height+100

function start()
  if bt:idle(pptouch())
  then
    local r=math.random(1,4)
    if r==1 then
      bt.y=s.height+100
    end
    if r==2 then
      bt.x=s.width+400
    end
    if r==3 then
      bt.y=-100
    end
    if r==4 then
      bt.x=-400
    end
  end
  bt:moveidle()
  bt:draw()
end