Bullet system does not work [SOLVED!!!]
Posted: Tue Nov 01, 2022 3:53 pm
hi, i am making a game about a circle that goes around your screen and you can control it with your mouse, so i made a bullet system but it does not work also the bullet disappears if i don't press the button, can someone help me?
(with "a" the bullet should go left, "s" down, "w" up and with "d" right but everytime it goes where he wants like i can't control it)
Code: Select all
Bullet = {}
function Bullet:load()
self.x = love.graphics.getWidth() / 2
self.y = love.graphics.getHeight() / 2
self.width = 20
self.height = 20
self.speed = 300
self.xVel = 0
self.yVel = 0
self.visible = 0
end
function Bullet:update(dt)
local x, y = love.mouse.getPosition() -- get the position of the mouse
local y, x = love.mouse.getPosition() -- get the position of the mouse
self.x = y
self.y = x
----------------------------------------------- start of bullet system
if love.keyboard.isDown("a") then
self.visible = 1
self.bulletleft = 1
self.xVel = self.xVel + self.speed
self.x = self.x - self.xVel * dt
elseif love.keyboard.isDown("w") then
self.visible = 1
self.bulletup = 2
self.yVel = self.yVel + self.speed
self.y = self.y + self.yVel * dt
elseif love.keyboard.isDown("d") then
self.visible = 1
self.bulletright = 3
self.xVel = self.xVel - self.speed
self.x = self.x + self.xVel * dt
elseif love.keyboard.isDown("s") then
self.visible = 1
self.bulletdown = 4
self.yVel = self.yVel - self.speed
self.y = self.y - self.yVel * dt
else
self.x = y
self.y = x
self.visible = 0
end
----------------------------------------------- end of bullet system
end
function Bullet:draw()
if self.visible == 1 then
love.graphics.rectangle("fill", self.x, self.y, 10, 50)
end
end