I dont know why it didnt work for me! This is the whole game till now if you want to check it out not that difficult but okay to pass your time. I’m still building it up but here’s where I’ve reached till
function setup()
physics.pause()
physics.gravity(0,0)
score = {}
bullets = {}
number = {}
ball = {}
for i = 1,5 do
ball[i] = Ballons()
end
sound(DATA, "ZgBAKgBLQFRAQEBAAAAAAK5T+j46fh4/UwBAf0BAQEBAZEBA")
parameter.watch("#number")
parameter.watch("#score")
t = 300
end
function draw()
t = t - 1
if t>=0 then
background(255, 255, 255, 255)
pushStyle()
font("MarkerFelt-Thin")
fontSize(25)
fill(0, 199, 255, 255)
text("no more than 5 lives", WIDTH - 380, HEIGHT - 50)
text("waste an arrow or miss a balloon and lose a life", WIDTH - 250, HEIGHT - 75)
popStyle()
pushStyle()
fontSize(100)
font("SnellRoundhand-Black")
fill(192, 26, 18, 117)
text("BALLONS", WIDTH/2, HEIGHT/2)
popStyle()
pushStyle()
font("AmericanTypewriter-Bold")
fontSize(20)
text("(inspired by the old windows game)", WIDTH/2, HEIGHT/2 - 75)
text("game begins in 5 seconds", WIDTH/2,HEIGHT/2 - 95)
popStyle()
pushStyle()
font("MarkerFelt-Thin")
fontSize(25)
fill(0, 199, 255, 255)
text("Touch behined this line to shoot arrows", 350, HEIGHT - 250)
strokeWidth(3)
stroke(0, 200, 255, 255)
lineCapMode(ROUND)
line(160,HEIGHT-250,75,HEIGHT-250)
line(75,HEIGHT-250,85,HEIGHT-245)
line(75,HEIGHT-250,85,HEIGHT-255)
popStyle()
pushStyle()
strokeWidth(2)
stroke(81, 31, 31, 255)
line(50,0,50,HEIGHT)
popStyle()
end
if t<= 0 then
background(255, 255, 255, 255)
strokeWidth(2)
stroke(81, 31, 31, 255)
line(50,0,50,HEIGHT)
physics.resume()
end
if collision~=nil then ------------------- see note 3. above
ball[collision[1]].ballon:destroy() --- see note 2 above
table.remove(ball,collision[1])
bullets[collision[2]]:destroy()
table.remove(bullets,collision[2])
collision=nil
table.insert(score,1)
end
pushStyle()
fill(0, 0, 0, 255) -- drawing the bullets
for i,b in pairs(bullets) do
sprite("Documents:arrow",b.x - 37,b.y,74)
if b.x<1 or b.x>WIDTH or b.y<1 or b.y>HEIGHT then
table.remove(bullets,1,b)
table.insert(number,1)
end
end
for i,b in pairs(ball) do
if b.ballon.y>HEIGHT + b.radius then
b:count()
end
end
popStyle()
for i,b in pairs(ball) do -- drawing the ballons
pushStyle()
fill(b.colr)
ellipse(b.ballon.x, b.ballon.y, b.radius*2)
end
popStyle()
if #number >= 5 then
pushStyle()
fill(255, 0, 0, 255)
font("HoeflerText-BlackItalic")
fontSize(50)
text("Game Over", WIDTH/2, HEIGHT/2)
physics.pause()
popStyle()
end
if #ball == 0 then
for i = 1,5 do
ball[i] = Ballons()
end
end
end
function createBullet()
local bullet = physics.body(CIRCLE,5)
bullet.x = x
bullet.y = y
bullet.linearVelocity = vec2(750,0)
bullet.restitution = 0
bullet.type = DYNAMIC
bullet.info = "bullet"
table.insert(bullets,bullet)
end
function touched(touch)
x = touch.x
y = touch.y
if touch.x<=50 then
if touch.state == BEGAN then
a = true
createBullet()
end
end
end
function collide(contact)
if contact.bodyA.info~=nil and contact.bodyB.info~=nil then
for i,v in pairs(ball) do
if v.ballon==contact.bodyA or v.ballon==contact.bodyB then
for j,bb in pairs(bullets) do
if bb==contact.bodyA or bb==contact.bodyB then
sound(DATA, "ZgNAXS4wQEBAQEBA/9iePiN3mD64nKs+cgBAf0BAQEBAb0BA ")
collision={i,j} -- see note 3 above
end
end
end
end
end
end
Ballons = class()
function Ballons:init(x,y,r,c,lv)
self.radius = r or math.random(25,50)
self.ballon = physics.body(CIRCLE,self.radius)
self.ballon.x = x or math.random(150,WIDTH - self.radius)
self.ballon.y = y or math.random(-HEIGHT/2,-self.radius)
self.ballon.linearVelocity = lv or vec2(0,math.random(100,200))
self.ballon.info="ball"
self.colr = c or color(math.random(255),math.random(255),math.random(255),math.random(100,150))
end
function Ballons:count()
for i = 1,#ball do
if self.ballon.y > HEIGHT + self.radius then
table.insert(number,1)
table.remove(ball,i,ball[i])
end
end
end
Can’t make a start button so I’ve added a five second delay.
How can I make a start button?
And how should I write the score as text not print in the end?