PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph
z=64
w=4

se=ppsemml[1]

function bt(x,y,i)
local r
local v
v=(320-64*w)/2
r=pprect(x*z+v,y*z+v,z,z)
r.i=i
r.p=x+y*w
r.draw=function(s)
g:box(s)
g:pos(s)
if s.i>0 then
local z
z=""..s.i
z=g:layout(ppfont:size(z),
    true,true,s)
g:pos(z)
g:print(s.i)
end
end
return r
end

b={}
n=1
for y=0,w-1 do
for x=0,w-1 do
t=bt(x,y,n)
n=n+1
b[#b+1]=t
end
end

function shuffle()
for i=1,w*w do
b[i].i=i
end
b[#b].i=0
for i=1,100 do
local x,y
x=math.random(1,w*w)
y=math.random(1,w*w)
local j=b[x].i
b[x].i=b[y].i
b[y].i=j
end
end
shuffle()

q={-w,-1,1,w}

sh=ppbutton("SHUFFLE")
sh:pos(
 g:layout(sh,true,true,B))
sh.y=4*64+64

function start()
tc=pptouch()
for i,r in ipairs(b) do
r:draw()
if r:hitCheck(tc) then
for j,u in ipairs(q) do
 u=u+r.p+1
 if u>0 and u<=w*w then
  if b[u].i==0 then
   b[u].i=r.i
   r.i=0
   se:play("o7c")
   break
  end
 end
end
end
end
if sh:idle(tc) then
shuffle()
end
sh:draw()
end