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]
[import]uid: 52491 topic_id: 18582 reply_id: 71371[/import]