Game Development Reference
In-Depth Information
And here's the Gideros Studio version:
function setupSound()
sounds = {
explosion = Sound.new("_001.wav"), -- explosion
shoot = Sound.new("_002.wav"), -- shoot bullet
collectSurvivor = Sound.new("_003.wav"), -- collect survivor
collectFuel = Sound.new("_004.wav"), -- collected fuel
crash = Sound.new("_005.wav"), -- crash
}
end
Since we wrap all of our sounds in the setupSound function, we need to call this once at the start, like so:
setupSound()
Shooting Bullets
To enable the helicopter to shoot bullets, we set an event listener to capture the taps or touches to
trigger a shot.
In Corona SDK, we use this:
Runtime:addEventListener("tap",shoot)
And in Gideros Studio, we use this:
stage:addEventListener(Event.TOUCHES_END, shoot)
In the shoot function, we check if the number of bullets on the screen is less than the MAX_BULLETS
value, and only then spawn a new bullet. When we shoot, we shall also play a shooting sound; this is
achieved via our playSound function.
function shoot()
if gameOver == true or wTime > 0 then return end
if #bullets < MAX_BULLETS then
local hx, hy = getPosition(heli)
local spr = loadImage("_bullet.png", hx+heli.width, hy + (heli.height/2))
blt = {
sprite = spr,
x = hx + heli.width,
y = hy + (heli.height/2),
wd = spr.width,
ht = spr.height,
}
table.insert(bullets, blt)
playSound(sounds.shoot) -- play the shooting sound
end
end
2
 
Search WWH ::




Custom Search