PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
B=ppscreen:size()

dotouchdown=function(s)
  g:move(0,-16)
  if s.touch then
    if s.touchdown==nil
    then
      g:print("DOWN")
      shot("DOWN",
        s.color)
    end
    s.touchdown=true
  else
    s.touchdown=nil
  end
end

touch=function(s)
  g:pos(s:pos())
  g:move(0,-16)
  local t
  t=pptouch()
  if s:hitCheck(t)
  then
    g:print("UP")
    shot("UP",s.color)
  end
  dotouchdown(s)
end

bt={}

t=ppbutton("TOUCH")
t:pos(g:layout(t:size(),true,true,B))
t:move(-80,-100)
t.dotouch=function(s)
  g:pos(s:pos())
  g:move(0,-16)
  local t
  t=pptouch()
  if s:idle(t) then
    g:print("UP")
    shot("UP",s.color)
  end
  dotouchdown(s)
end
bt[1]=t

t=ppbutton("TOUCH")
t:pos(g:layout(t:size(),true,true,B))
t:move(80,-100)
t.color=g.yellow
t.dotouch=touch
bt[2]=t

t=ppoffscreen.new()
t:create(80,100)
t:pos(g:layout(t:size(),true,true,B))
t:move(-80,100)
t:fill(t:size(),g.green)
t.color=g.green
t.dotouch=touch
bt[3]=t

t=pprect(0,0,80,100)
t:pos(g:layout(t:size(),true,true,B))
t:move(80,100)
t.dotouch=touch
t.color=g.cyan
t.draw=function(s)
  g:box(s,s.color)
end
bt[4]=t

p={}
function shot(str,col)
  local r=nil
  for i,h in ipairs(p)
  do
    if h.y<=-16 then
      r=h
      break
    end
  end
  if r==nil then
    r=pprect()
    table.insert(p,r)
  end
  r.str=str
  r.col=col
  local z
  z=ppfont:size(str)
  r:size(z)
  r:pos(0,B.height)
  r.x=(B.width
        -r.width)/2
end

function start()
  for i,b in ipairs(bt)
  do
    b:dotouch()
    b:draw()
  end
  for i,v in ipairs(p)
  do
    g:pos(v)
    g:print(v.str,v.col)
    if v.y>-16 then
      v:move(0,-4)
    end
  end
end