Need some help with a weapon
Posted: Thu Dec 02, 2010 10:52 pm
Hi there people, I have a little problem. I am writing this code and the way that it's written, when I press space to shoot, it spawns the bullet and it doesn't shoot until I release the button. Can someone me how to make it shoot automaticaly as long as I have the button pressed?
Code: Select all
function love.load()
love.graphics.setMode(500, 480, false, true, 2)
love.graphics.setBackgroundColor( 0, 0, 0)
love.graphics.setCaption("Proper")
bullet = {
image = love.graphics.newImage("BolaBola.png"),
x = 0,
y = 0,
}
back = love.graphics.newImage("background.png")
music = love.audio.newSource("Musicaaa.wav")
love.audio.play(music)
love.mouse.setVisible( false )
player = {
x = 230,
y = 400,
image = love.graphics.newImage("Blueshippp.png")
}
background1 = {
x = 0,
y = 0,
image = love.graphics.newImage("background.png")
}
background2 = {
x = 0,
y = -600,
image = love.graphics.newImage("background.png")
}
end
function love.draw()
love.graphics.draw(background2.image, background2.x, background2.y)
love.graphics.draw(background1.image, background1.x, background1.y)
love.graphics.draw(player.image, player.x, player.y)
if shoot == true then
love.graphics.draw(bullet.image, bullet.x, bullet.y)
end
end
function love.update()
background1.y = background1.y + 2
background2.y = background2.y + 2
if background1.y == 600 then
background1.y = -600
end
if background2.y == 600 then
background2.y = -600
end
if love.keyboard.isDown("left") then
player.x = player.x - 5
end
if player.x > 300 then
player.x = player.x - 0
end
if love.keyboard.isDown("right") then
player.x = player.x + 5
end
if love.keyboard.isDown(" ") then
shoot = true
bullet.x = player.x + 10
bullet.y = player.y
end
bullet.y = bullet.y - 20
end