My Balloon Game - 3 Questions

So I am making this game where balloons fly up through the screen and you need to pop them. Once you pop them it removes them and plays a pop sound.

Question #1: Why does it only play the pop sound on the first balloon?

Also after you get your score to 20 I wanted it to show a nuke balloon which would remove all the balloons on the screen but in a “fancy” style.

Question #2: How could I make it remove all the balloons when you touch the nuke balloon but since I wanted it “fancy” i wanted the screen to fade to white than fade back and have all the currently shown balloons gone.

Also when it comes to the nuke balloon, why it doesnt spawn correctly. I know why for one of the reasons but the others idk why. Currently I have the nuke balloon inside my function that spawns a bunch of ballons so when

[lua]if score == 20 then
local nukeB = display.newImage(“Graphics/nukeBALLOON.png”)
nukeB.x = display.contentWidth/2
nukeB.y = display.contentHeight + 150
physics.addBody(nukeB)
end[/lua]

Than if they only pop 20 balloons it spawns them untill they have 21. Which i understand it makes sense. but what i dont get is that it doesnt work when i take it out of that function.

Question #3: How do i fix above?

Here is my code because i think you might need it

[lua]system.activate(“multitouch”)

local physics = require(“physics”)
physics.start()
physics.setGravity(0, -9.8)

local pop = media.newEventSound( “balloonpop.wav” )

local background = display.newImage(“Graphics/sky.png”)

local wave = 0
local waveletter = "You Are On Wave "…wave;

local waveTEXT = display.newText(waveletter, display.contentWidth - 250, 20, nil, 26)
waveTEXT:setTextColor(0,0,0)

local balloons = 100

local balloonsLEFT = display.newText(“You Have “… balloons …” Balloons Left”, 20, 45, nil, 26)
balloonsLEFT:setTextColor(255,0,0)

local score = 0

local scoreTEXT = display.newText(“You Popped " … score … " Balloons”, 20, 20, nil, 26)
scoreTEXT:setTextColor(0,0,255)

local leftWALL = display.newRect(0, 0, 1, display.contentHeight + 500 )
local rightWALL = display.newRect(display.contentWidth, 0, 1, display.contentHeight + 500 )
local ceiling = display.newRect(0, 0, display.contentWidth, 1 )

physics.addBody(leftWALL, “static”)
physics.addBody(rightWALL, “static”)

local function spawnBalloon()
local balloon = display.newImage(“Graphics/balloon1.png”)
balloon.x = display.contentWidth/2
balloon.y = display.contentHeight + 150
physics.addBody(balloon)

if score == 20 then
local nukeB = display.newImage(“Graphics/nukeBALLOON.png”)
nukeB.x = display.contentWidth/2
nukeB.y = display.contentHeight + 150
physics.addBody(nukeB)
end

local function nukeBall()

end

function killBalloon(event)

if event.phase == “ended” then

media.playEventSound( pop )

score = score + 1
print("SCORE IS: "… score)
balloons = balloons - 1
print("BALLOONS: "… balloons)

scoreTEXT.text = “You Popped " … score … " Balloons”
balloonsLEFT.text = “You Have “… balloons …” Balloons Left”

local text = display.newText(“You Popped Another Balloon!”, 50, 100, nil, 26)
text:setTextColor(0,0,0)

transition.to(text, {time = 2000, alpha = 0, x = 300, y = 400})

balloon:removeSelf( )

end

end

balloon:addEventListener(“touch”, killBalloon)
nukeB:addEventListener(“touch”, nukeBall)
end

timer.performWithDelay( 250, spawnBalloon, 100)

display.setStatusBar( display.HiddenStatusBar )[/lua]

Thanks in Advanced.
Brennan [import]uid: 81383 topic_id: 18582 reply_id: 318582[/import]

Hey there,

For testing code it really needs to be plug and play or a project download, because no one can run this as they don’t have the images, sounds, etc.

With your balloons, you are spawning 100 but you are not doing it correctly, you should be keeping them in a table.

Right now you have 100 objects once the timer is done all called balloon.

Does that make sense? If you’re unfamiliar with tables let me know and if I have time I can try to write you up a little example.

Peach :slight_smile: [import]uid: 52491 topic_id: 18582 reply_id: 71371[/import]

yeah i dont really understand tables all to much [import]uid: 81383 topic_id: 18582 reply_id: 71372[/import]

I think this will give you a instant white background then fade to black 5 seconds. i dont know how to fade in the white

[lua]
nukeBall()
background:setFillColor(0,0,0)
timer1 = timer.performWithDelay(background{time = 5000, array = 0})
end
[import]uid: 75779 topic_id: 18582 reply_id: 71394[/import]

Here is a really basic example of spawning some balloons without naming them all “balloon” - let me know if it helps.

[lua]math.randomseed(os.time())

local balloon = {}

local function pop(event)
event.target:removeSelf()
return true
end

local function spawn()
balloon[#balloon] = display.newCircle( math.random(20,300), math.random(20,400), 30 )
balloon[#balloon]:addEventListener(“tap”, pop)
end
timer.performWithDelay(500, spawn, 20)[/lua]

I believe if you add your sound to the pop function it should play fine each time and not just once.

Peach :slight_smile: [import]uid: 52491 topic_id: 18582 reply_id: 71500[/import]