PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph

yelbox=ppoffscreen.new()
yelbox:create(64,192)
yelbox:clear(g.yellow)
yelbox:bind()

redbox=ppoffscreen.new()
redbox:create(96,64)
redbox:clear(g.red)
redbox:bind()

z=ppscreen:size()
ha=pprect()
ha.width=z.width
ha.height=z.height/2
hd=pprect()
hd.y=z.height/2
hd.width=z.width
hd.height=z.height/2

rand=math.random
far=100
ct=ppscreen:size()/2
ct=pppoint(ct.width,ct.height)

col={
  {0,0,0,0},  --0
  g.yellow,   --1
  g.red,      --2
  g.blue,     --3
  g.cyan,     --4
  g.white     --5
}

zero=("0"):byte(1)
o=ppoffscreen.new()
o:create(16,16)
px={
  "0000000000000000",
  "0000011100000000",
  "0000011110000000",
  "0000011110000000",
  "0000022222000000",
  "0000222122200000",
  "0000221113330000",
  "0000022123230000",
  "0000004443330000",
  "0000044344000000",
  "0000443034000000",
  "0004430034440000",
  "0005530003550000",
  "0022500000522000",
  "0022000000022000",
  "0000000000000000",
}
for y=0,15 do
  for x=0,15 do
    local pc
    pc=px[y+1]:byte(x+1)
    pc=pc-zero
    o:pixel(x,y,col[pc+1])
  end
end

hero=o
hero:scale(10,10)
hero:pos(
  g:layout(
    hero:size(),true,true))
hero.c=hero:pos()

function sp(n)
  local r=ppsprite.new()
  r:texture(n:texture())
  r:tileSize(n:size())
  r.p=pppoint(0,0)
  r.p.z=far
  r.sz=pppoint(0.5,0.5)
  r:pivot(r.width/2,
          r.height)
  r.disp=function(s)
    local p
    local sw,sh
    local z=s.p.z/far
    sw=s.sz.x/z
    sh=s.sz.y/z
    p=s.p/z
    p=p+ct-s:pivot()
    s:pos(p)
    s:scale(sw*2,sh*2)
    s:draw()
  end
  return r
end

t={}
tex={
  yelbox,
  redbox
}
for i=1,40 do
  local s
  local n=rand(1,2)
  s=sp(tex[n])
  s.p.x=rand(-1000,1000)
  s.p.y=100
  s.p.z=rand(1,1000)
  table.insert(t,s)
end

function start()
  g:fill(ha,g.cyan)
  g:fill(hd,g.green)
  local xx=hero:pos()-hero.c
  xx=xx.x/20
  local o={}
  for i=1,1000 do
    o[i]={}
  end
  for i,v in ipairs(t) do
    v.p.x=v.p.x-xx
    v.p.z=v.p.z-8
    if v.p.z<0 then
      dx=rand(-500,500)
      dx=dx+xx*200
      v.p.x=dx
      v.p.z=1000
    end
    local z
    z=math.floor(v.p.z)
    if z<=0 then
      z=1
    end
    table.insert(o[z],v)
  end
  for i=1000,1,-1 do
  for j,v in ipairs(o[i]) do
    v:disp()
  end
  end
  hero:drag(pptouch(),z)
  hero:draw()
end