NOTE: Where I have written print is where the issues occur, as these for loops never run.
Code: Select all
bullet = {}
player = player or require("scripts.player");
Options = Options or require("scripts.options");
Game = Game or require("scripts.game");
bulletSpeed = 100;
image = love.graphics.newImage("images/bullet.jpg");
bullet.x = -10;
bullet.y = -10;
bullet.velX = 0;
bullet.velY = 0;
fire = love.audio.newSource("sounds/fire.mp3");
function bullet.load()
bulletTable = {}
end
function bullet.create(x, y, velX, velY)
bullet.x = x;
bullet.y = y;
bullet.velX = velX;
bullet.velY = velY;
end
b = 0;
function bullet.update(dt)
for i, v in ipairs(bulletTable) do
if v.remove then
table.remove(bulletTable, i);
print ("4");
i = i - 1;
else
v:update(dt);
print("5")
end
end
end
function bullet.spawn(dt)
if (love.mouse.isDown(1)) then
if (player.canShoot == true) then
if (GameState.getGameState() == "GAME" and (Game.game_time ~= 90 and Game.game_time ~= 180 and Game.game_timer ~= 300)) then
if (player.canShoot) then
if (Options.getSound() == "ON") then
fire:play();
end
velX = 0;
velY = 0;
table.insert(bulletTable, (Bullet.create(player.getX() + 23, player.getY() + 5, velX, velY)));
player.canShoot = false;
player.shootTime = 2;
end
end
end
end
end
function bullet.draw()
for i, v in ipairs(bulletTable) do
print("2");
v:render();
end
end
function bullet.render()
love.graphics.draw(image, v.x, v.y, 0, 1);
end
return bullet;