Here’s another starter game. The object is to remove each ball by tapping them in order starting from 1. Try to remove as many as you can before 25 balls are created.
displayMode(FULLSCREEN)
function setup()
fontSize(30)
delay=120
gameOver=false
inst=true
count=0
nbr=0
remove=1
high=25
ball={}
for z=1,10 do
table.insert(ball,addBall())
end
physics.continuous=true
e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e2=physics.body(EDGE,vec2(0,50),vec2(WIDTH,50))
e3=physics.body(EDGE,vec2(WIDTH,0),vec2(WIDTH,HEIGHT))
e4=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
end
function draw()
background(40, 40, 50)
fill(255)
if inst then
text("Tap each ball in order to remove them",WIDTH/2,HEIGHT/2)
text("before ".. high.." balls are created.",WIDTH/2,HEIGHT/2-50)
text("Double tap screen to start.",WIDTH/2,HEIGHT/2-150)
elseif gameOver then
fill(244, 255, 0, 255)
text("Game Over\
\
Score = "..remove-1,WIDTH/2,HEIGHT/2)
text("Double tap to restart",WIDTH/2,HEIGHT/2-100)
else
for a,b in pairs(ball) do
fill(255)
ellipse(b.x,b.y,60)
fill(255,0,0)
text(b.info,b.x,b.y)
end
count=count+1
if count>delay then
table.insert(ball,addBall())
count=0
end
fill(0,255,0)
text("Remove "..remove,WIDTH/2,HEIGHT/2)
text("High ball "..nbr,WIDTH/2,HEIGHT/2-50)
if nbr>=high then
gameOver=true
end
end
end
function touched(t)
if t.state==BEGAN then
if t.tapCount==2 then
if inst then
inst=false
elseif gameOver then
restart()
end
return
end
for z=1,#ball do
if (t.x-ball[z].x)^2/30^2+(t.y-ball[z].y)^2/30^2 <= 1 then
if remove==ball[z].info then
ball[z]:destroy()
table.remove(ball,z)
remove=remove+1
delay=delay-3
return
end
end
end
end
end
function addBall()
nbr=nbr+1
local b=physics.body(CIRCLE,30)
b.x=math.random(50,WIDTH-50)
b.y=math.random(50,HEIGHT-50)
b.sleepingAllowed=false
b.restitution=1
b.gravityScale=0
b.info=nbr
b.linearVelocity=vec2(math.random(-300,300),math.random(-300,300))
return b
end