PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
rand=math.random
B=ppscreen:size()

w=39
h=39

o=ppoffscreen.new()
o:create(4,1)
o:pixel(0,0,g.blue)
o:pixel(1,0,g.green)
o:pixel(2,0,g.yellow)
o:scale(10,10)
o:bind()

m=ppmap.new()
m:addLayer("layer1",w,h)
m:texture(o:texture())
m:clip(0,0,w,h)
m:tileSize(1,1)
m:box(m:size(),1)
m:scale(8,8)
m:move(4,32)

mv={
  {0,-1},
  {-1,0},
  {0,1},
  {1,0}
}

local r=3

for y=2,h,2 do
for x=2,w,2 do
  m:tile(x,y,1)
  local a=rand(1,4)
  local p=pppoint(x,y)
  p:move(mv[a])
  m:locate(p)
  m:tile(1)
end
end

m:tile(w-2,h-2,3)

function button(t,x,y)
  local r
  r=pprect(x,y,80,80)
  r.t=t
  r.c=0
  r.pretouch=false
  r.draw=function(s)
    g:box(s)
    local t
    t=ppfont:size(s.t)
    t=g:layout(
      t,true,true,s)
    g:pos(t)
    g:print(s.t)
    t=pptouch()
    s:hitCheck(t)
    local ret=false
    if s.touch then
      s.c=s.c+1
      if s.c>20 then
        s.c=16
        s.pretouch=false
      end
      if not s.pretouch
      then
        ret=true
      end
    else
      s.c=0
    end
    s.pretouch=s.touch
    return ret
  end
  return r
end

cx=(B.width-80)/2
cy=B.height-160
up=button("UP",
  cx,cy-80)
down=button("DOWN",
  cx,cy+80)
left=button("LEFT",
  cx-80,cy)
right=button("RIGHT",
  cx+80,cy)

q=pppoint(1,1)

function start()
  m:draw()
  m:tile(q,0)
  local oq=pppoint(q)
  if up:draw() then
    q:move(0,-1)
  end
  if down:draw() then
    q:move(0,1)
  end
  if left:draw() then
    q:move(-1,0)
  end
  if right:draw() then
    q:move(1,0)
  end
  if m:tile(q)==3 then
    while true do
      m:draw()
      local t
      t="GAME CLEAR!"
      local sz
      sz=ppfont:size(t)
      sz=sz.width
      sz=(B.width-sz)/2
      g:pos(sz+8,200)
      g:print(t)
      g:update()
    end
  elseif m:tile(q)~=0
  then
    q=oq
  end
  m:tile(q,2)
end