PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
se=ppsemml[1]
rand=math.random

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

floor=math.floor
rand=math.random

env="@e1,0,127,10,50"
bang=env.."@7o1l8c"

o=ppoffscreen.new()
o:create(128,32)

o.defchar
=function(o,i,r,g,b)
local t
local dx=(i-1)*8
t="0123456789ABCDEF"
local function f(o,dx,s,k)
  local c
  for y=0,7 do
    local r,n
    for i=0,1 do
    n=y*2+1+i
    r=s:sub(n,n)
    r=t:find(r)-1
    for x=0,3 do
      local p,z
      p=(r%2)*255
      r=floor(r/2)
      z=3-x+i*4
      c=o:pixel(z+dx,y)
      c[k]=p
      c.a=255
      o:pixel(z+dx,y,c)
    end
    end
  end
end
f(o,dx,r,"r")
f(o,dx,g,"g")
f(o,dx,b,"b")
end

o:defchar(1,
"004033FF38F83140",
"000003071F070100",
"0000030707070100"
)

o:defchar(2,
"00F04CFF00FCF000",
"00F04CFFFFFEF000",
"00F0FCFFFFFEF000"
)

o:defchar(3,
"387E6AD0EC5E7030",
"0000000000000000",
"0000000000000000"
)

o:scale(4)
o:hflip()
o:bind()

m=ppsprite.new()
m:texture(o:texture())
m:tileSize(16,8)
m:tile(1)
m:scale(4)
m.x=16
m.y=(Bh-m.height)/2

b=ppmap.new()
b:addLayer("layer")
b:mapSize(11,18)
b:clip(0,0,11,18)
b:tileSize(8,8)
b:line(0,0,11,0,3)
b:line(0,17,11,17,3)
b:scale(4)
b:texture(o:texture())

b.by=4
b.bh=5
b.bc=0
b.bd=0

b.idle=function(s)
  s:move(-2,0)
  if s.x<-32 then
    s:scroll(-1,0)
    s.x=s.x+32
    s.bc=s.bc+1
    if s.bc>20 then
      s.bd=rand(0,2)-1
      s.bc=rand(15,18)
      s.bh=s.bh+rand(0,2)-1
      if s.bh<5 then
        s.bh=5
      end
      if s.bh>8 then
        s.bh=8
      end
    end
    s.by=s.by+s.bd
    if s.by<1 then
      s.by=1
    end
    if s.by>16-s.bh
    then
      s.by=16-s.bh
    end
    s:line(
      10,1,10,17,3)
    r=rand(3,7)
    s:line(
      10,s.by,
      10,s.by+s.bh,0)
    if (s.bc%2)==1 then
      r=math.random(1,17)
      s:tile(10,r,3)
    end
  end
end

b.check=function(b,p)
  p=(p-b:pos())/32
  if b:tile(p)>0 then
    return true
  end
  return false
end

over=false

function start()
  if not over then
  b:idle()
  m:drag(pptouch(),B)
  p=m:pos()
  p:move(16,16)
  if b:check(p) then
    over=true
  end
  p:move(32,0)
  if b:check(p) then
    over=true
  end
  if over then
    se:play(bang)
  end
  end
  b:draw()
  m:draw()
  if over then
    s="GAME OVER"
    w=ppfont:size(s)
    w=Bw-w.width
    g:pos(w/2,230)
    g:print(s,g.red)
  end
end