Here’s another game starter for anyone to use. The object is to keep the balls from falling off the screen. Tap the screen to create a red ball for a ball to bounce off of. For each ball that hits the red ball, you get 1 point. For each ball that falls off the bottom, you lose points equal to the number of balls on the screen. Keep tapping around the screen to keep the balls from falling. A new ball is created every ten seconds or anytime a ball falls off the bottom. I show your current score and the high score. Once the current score goes back to 0, the game is over and your high score is shown. Double tap the screen to play again.
displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT_ANY)
function setup()
fontSize(40)
e1=physics.body(EDGE,vec2(0,0),vec2(0,HEIGHT))
e2=physics.body(EDGE,vec2(0,HEIGHT),vec2(WIDTH,HEIGHT))
e3=physics.body(EDGE,vec2(WIDTH,HEIGHT),vec2(WIDTH,0))
tab={}
ball()
tw()
total=0
maxTotal=0
gameOver=false
end
function tw()
t1=tween.delay(10,function() ball() tw() end)
end
function draw()
background(31, 66, 75, 255)
fill(255)
text("High score "..maxTotal,WIDTH/2,HEIGHT-100)
if gameOver then
text("GAME OVER",WIDTH/2,HEIGHT/2+100)
text("Double tap screen to play again.",WIDTH/2,HEIGHT/2)
return
end
text("Current "..total,WIDTH/2,HEIGHT-50)
for a,b in pairs(tab) do
ellipse(b.x,b.y,40)
if b.y<0 then
b:destroy()
table.remove(tab,a)
total=total-#tab
if total<=0 then
gameOver=true
return
end
ball()
end
end
if tb~=nil then
fill(255,0,0)
ellipse(tb.x,tb.y,30)
end
end
function collide(c)
if c.state==BEGAN and not gameOver then
if c.bodyA.info=="tball" and c.bodyB.info=="ball" or
c.bodyA.info=="ball" and c.bodyB.info=="tball" then
total=total+1
maxTotal=math.max(total,maxTotal)
end
end
end
function touched(t)
if t.state==BEGAN then
if gameOver and t.tapCount==2 then
restart()
return
end
if tb then
tb:destroy()
end
tb=physics.body(CIRCLE,15)
tb.x=t.x
tb.y=t.y
tb.restitution=1
tb.info="tball"
tb.type=STATIC
end
end
function ball()
b=physics.body(CIRCLE,20)
b.x=math.random(50,WIDTH-50)
b.y=math.random(HEIGHT-200,HEIGHT)
b.restitution=1
b.info="ball"
b.gravityScale=.5
table.insert(tab,b)
end