PicoPicoGameEngine

Quick Links

Source Code

g=ppgraph
rand=math.random
floor=math.floor

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

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

mv2={
{0,-3},
{-3,0},
{ 3,0},
{0, 3}
}

t={
{"DFDFDF00FDFDFD00",
"0000000000000000",
"0000000000000000"},
{"7E80808080808000",
"FEFEFEFEFEFEFE00",
"FEFFFFFFFFFFFF7E"},
{"FF00FF00000000FF",
"0000FFFFFF000000",
"0000FFFFFFFF0000"},
{"A1A1A1A1A1A1A1A1",
"3838383838383838",
"3C3C3C3C3C3C3C3C"}}

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

o.defchar
=function(o,i,d)
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,d[1],"r")
f(o,dx,d[2],"g")
f(o,dx,d[3],"b")
end

for i,d in ipairs(t)
do
  o:defchar(i,d)
end

o:hflip()
o:bind()
tex=o:texture()

mw=20*3+4
mh=10*3+4

D=pprect(
  -(mw*16-Bw),0,
  (mw*16-Bw)+16,16)

m=ppmap.new()
m:addLayer("layer")
m:mapSize(mw,mh)
m:clip(0,0,mw,mh)
m:tileSize(8,8)
m:texture(tex)
m:scale(2)

m.maze=function(m)
m:fill(0,0,mw,mh,1)
m:fill(1,1,mw-2,mh-2,2)
for x=3,mw-3,3 do
for y=1,mh-2,3 do
  m:tile(x,y,4)
  m:tile(x,y+1,4)
end
end
for y=3,mh-3,3 do
for x=1,mw-2,3 do
  m:tile(x,y,3)
  m:tile(x+1,y,3)
end
end
local 
function dig(m,x,y)
local loop
local t,o,u,q
loop=true
while loop do
  m:box(x,y,2,2,0)
  t={}
  for i=1,4 do
    q=pppoint(mv2[i])
    o=pppoint(mv[i])
    q:move(x,y)
    o:move(x,y)
    if m:tile(o)==1 then
    elseif m:tile(q)==0 then
    else
     t[#t+1]=i
    end
  end
  if #t<=0 then return end
  t=t[math.random(1,#t)]
  q=pppoint(mv2[t])
  o=pppoint(mv[t])
  u=pppoint(o)
  q:move(x,y)
  o:move(x,y)
  if u.x==0 then
  m:tile(o,1)
  o:move(1,0)
  m:tile(o,1)
  end
  if u.y==0 then
  m:tile(o,1)
  o:move(0,1)
  m:tile(o,1)
  end
  dig(m,q.x,q.y)
end
end
local x,y
x=math.random(0,mw-2)
x=math.floor(x/3)*3+1
y=math.random(0,mh-2)
y=math.floor(y/3)*3+1
dig(m,x,y)
for x=1,mw-1 do
for y=1,mh-1 do
 if m:tile(x,y)==0
 then
   m:tile(x,y,1)
 end
end
end
m:box(0,0,mw,mh,2)
end
m:maze()

bt=ppbutton("CREATE")
t=g:layout(bt,true,true,B)
t.y=Bh-t.height-64
bt:pos(t)

function start()
  if bt:idle(pptouch())
  then
    m:maze()
  end
  m:drag(pptouch(),D)
  m:draw()
  bt:draw()
end