[HELP] Shoot in one direction at a time
Posted: Mon May 25, 2015 10:55 pm
Hi, I'm making a basic game in Love where the player can shoot bullets at enemies.
I'm trying to restrict the player to shooting in one direction at a time so the player can't spam bullets in all directions. Here's the part of the code I need modified:
Any help would be very much appreciated!
I'm trying to restrict the player to shooting in one direction at a time so the player can't spam bullets in all directions. Here's the part of the code I need modified:
Code: Select all
function player.shoot(key)
if gameState == "playing" then
if key == 'up' then
bullet.spawn(player.x - bullet.width/2, player.y - player.height - bullet.height, 'up')
TEsound.play("/res/shoot.mp3")
end
if key == 'down' then
bullet.spawn(player.x - bullet.width/2, player.y + player.height + bullet.height, 'down')
TEsound.play("/res/shoot.mp3")
end
if key == 'right' then
bullet.spawn(player.x + player.width + bullet.width, player.y - bullet.width/2, 'right')
TEsound.play("/res/shoot.mp3")
end
if key == 'left' then
bullet.spawn(player.x - player.width - bullet.width, player.y - bullet.width/2, 'left')
TEsound.play("/res/shoot.mp3")
end
end
end