Shoot logic (also detects the point of the gun
Code: Select all
if mouseDownTime >= rateOfFire then
XofGun = player.x + (14 * math.cos(player.direction)) - (5 * math.sin(player.direction))
YofGGun = player.y + (5 * math.cos(player.direction)) + (14 * math.sin(player.direction))
local x = love.mouse.getX()
local y = love.mouse.getY()
CreateNewBullet(x, y, XofGun, YofGGun)
mouseDownTime = 0
end
Code: Select all
function CreateNewBullet(x, y, startX, startY)
local bulletDx, bulletDy = CalculateDxDy(x, y, startX, startY)
bulletBoundingBox = {x = startX - (bulletSize/2), y = startY - (bulletSize/2), w = bulletSize, h = bulletSize}
table.insert(bullets, {x = startX, y = startY, dx = bulletDx, dy = bulletDy, bulletBoundingBox })
Code: Select all
function BulletUpdate(dt)
for i=#bullets, 1, -1 do
bullets[i].x = bullets[i].x + (bullets[i].dx * dt)
bullets[i].y = bullets[i].y + (bullets[i].dy * dt)
bullets[i].bulletBoundingBox = {x = bullets[i].x - (bulletSize/2), y = bullets[i].y - (bulletSize/2), w = bulletSize, h = bulletSize}
if CheckBulletPosition(bullets[i]) == true then
table.remove(bullets, i)
end
end
end