PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
B=ppscreen:size()
C=pppoint(B.width,B.height)
S=pppoint(200,200)
D=pprect(B)
D:inset(64,B.height/3)

function zpos(p)
local t=pppoint(p)
local z=1+p.z+v.z-1
if z<0.001 then
 z=0.001
end
t=t*S+(v:pos()-v.c)*4
return t/z+C/2
end

zn=20
zx=2
d={}
l={}
p={}
n=1
for z=0,zn do
for x=1,zx do
t=pppoint(x-(zx+1)/2,-2)
t.x=t.x*4
t.z=z
p[#p+1]=t
t=pppoint(x-(zx+1)/2,2)
t.x=t.x*4
t.z=z
p[#p+1]=t
l[#l+1]={n,n+1}
if z<zn then
l[#l+1]={n,n+zx*2}
l[#l+1]={n+1,n+zx*2+1}
d[#d+1]={
  p={n,n+zx*2,
     n+zx*2+1,n+1},
  z=z}
if x<zx then
d[#d+1]={
  p={n+zx*2+1,n+zx*2+3,
     n+3,n+1},
  z=z}
end
end
if x<zx then
l[#l+1]={n,n+2}
l[#l+1]={n+1,n+3}
end
n=n+2
end
end

v=ppsprite.new()
v.y=100
v.z=0
v:tileSize(1,1)
v:pos(
  g:layout(
    v:size(),
    true,true,B))
v.c=v:pos()

zc=0

table.sort(d,
function(a,b)
return (a.z>b.z)
end)

function start()
v.z=v.z-0.05
if v.z<-1 then
 zc=1-zc
 v.z=0
end
v:drag(pptouch(),D)
for i,p in ipairs(p) do
p.t=zpos(p)
end
for i,l in ipairs(d) do
local t={}
for j,q in ipairs(l.p) do
t[#t+1]=p[q].t
end
if ((l.z+zc)%2)==0 then
g:triangleFan(t,g.blue)
else
g:triangleFan(t,g.cyan)
end
end
for i,l in ipairs(l) do
g:line(p[l[1]].t,p[l[2]].t)
end
end