PicoPicoGameEngine

Quick Links

Source Code

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

se1=ppsemml[1]
se1:play("t255l2")
se2=ppsemml[2]
se2:play("t255l2")
se3=ppsemml[3]
se3:play("t255l2")

w=64
n=5
sp=4

function cannon(x,y)
local r
r=pprect(x,y,w,w)
r.hitrect=pprect(0,0,w-1,w-1)
r.hitmask=1
r.draw=function(s)
 g:box(s)
end
return r
end

c={}
for i=0,n-1 do
c[i+1]=cannon(i*w,Bh-w)
end


function obj(d,c)
local r
r=pprect(0,0,w,w)
r.e=false
r.d=d
r.c=c
r.hitrect=pprect(0,0,w-1,w-1)
r.hitmask=0
r.draw=function(s)
  if s.e then
  s:move(0,s.d)
  g:box(s,s.c)
  if B:intersect(s) then
  else
    s.e=false
  end
  end
end
return r
end

t={}
for i=1,10 do
t[i]=obj(-sp,g.orange)
end

function shot(s,t)
for i=1,10 do
if not t[i].e then
t[i].e=true
t[i]:pos(s)
t[i].hitmask=1
return t[i]
end
end
end

e={}
for i=1,10 do
e[i]=obj(sp,g.cyan)
end

tim=0

function eshot()
tim=tim+1
if tim>80 then
 tim=0
 local o
 o=math.random(0,n-1)
 se1:play(note[o+1])
 o=pppoint(o*w,-w)
 o=shot(o,e)
end
end

function hittama(t,e)
t.e=false
t.hitmask=0
e.e=false
e.hitmask=0
se2:play(note3[t.i])
end

function hitenemy(c,e)
end

note={
"o5c",
"o5c",
"o5d",
"o5e",
"o5e"
}

note2={
"o5e",
"o5f",
"o5f",
"o5g",
"o5g"
}

note3={
"o5g",
"o5a",
"o5a",
"o5b",
"o6c"
}

function start()
for i,v in ipairs(c) do
 if v:hitCheck(pptouch())
 then
   local o=shot(v,t)
   o.i=i
   se3:play(note2[i])
 end
 v:draw()
end
for i,v in ipairs(t) do
 v:draw()
end
for i,v in ipairs(e) do
 v:draw()
end
eshot()
pphitcheck(t,e,hittama)
pphitcheck(c,e,hitenemy)
end