PicoPicoGameEngine

Quick Links

ピコピココード

g=ppgraph
rand=math.random
ceil=math.ceil
z=80
w=3

max=20

se=ppsemml[1]

function bt(x,y,i)
local r
local v
v=(320-z*w)/2
r=pprect(
   x*z+v,y*z+v+48,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

vala=0
valb=0

function ans()
local a,b
a=rand(2,max)
b=rand(1,a-1)
return a-b,b
end

function shuffle()
vala,valb=ans()
local t={}
for i=1,max do
if i~=vala+valb then
t[#t+1]=i
end
end
for i=1,max do
local x,y
x=rand(1,max-1)
y=rand(1,max-1)
local j=t[x]
t[x]=t[y]
t[y]=j
end
for i=1,w*w do
b[i].i=t[i]
end
b[#b].i=vala+valb
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("START")
sh:pos(
  g:layout(sh,true,true,B))
sh.y=4*64+64+32

tim=0
sc=0

function prt(s,y,c)
local z=ppfont:size(s)
z=g:layout(z,true,true,B)
g:pos(z.x,y)
g:print(s,c)
end

function start()
local s=""..vala.."+"..valb.."="
prt(s,48,g.cyan)
if tim>0 then
tim=tim-1
if tim<=0 then
 se:play("o6cgcgcg")
 tim=0
end
end
local s
s="TIME "..ceil(tim/60)
prt(s,0,g.yellow)
s="SCORE "..sc
prt(s,16,g.green)
tc=pptouch()
for i,r in ipairs(b) do
r:draw()
if r:hitCheck(tc) then
if tim>0 then
if r.i==vala+valb then
se:play("o7c")
sc=sc+1
shuffle()
else
se:play("o4cg")
end
end
end
end
if tim==0 then
if sh:idle(tc) then
se:play("o7c")
sc=0
tim=60*60
shuffle()
end
sh:draw()
end
if tim==0 then
s="TIME OUT!"
prt(s,184,g.red)
end
end