PicoPicoGameEngine

Quick Links

ピコピココード

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

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

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

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:box(0,0,mw,mh,2)
local t,u,o
for y=3,mh-3,3 do
for x=3,mw-3,3 do
  m:tile(x,y,2)
  for i=1,10 do
    if y==3 then
      t=rand(1,4)
    else
      t=rand(2,4)
    end
    o=pppoint(mv[t])
    t=pppoint(o)
    t:move(x,y)
    u=m:tile(t)
    if u==1 then
      if o.x==0 then
      m:tile(t,4)
      t:move(0,1)
      m:tile(t,4)
      end
      if o.y==0 then
      m:tile(t,3)
      t:move(1,0)
      m:tile(t,3)
      end
      break
    end
  end
end
end
end
m:maze()

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

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