oh ok sorry, I am following a tutorial but Im getting syntax errors can this be because this tutorial is from a older version of love2d?
If you want to see it this is my code:
The syntax error said that it had something to do with the line player.fire_sound = love.audio.newSource("shoot.wav")
love.graphics.setDefaultFilter("nearest", "nearest")
enemy = {}
enemies_controller = {}
enemies_controller.enemies = {}
enemies_controller.image = love.graphics.newImage("enemy.png")
function love.load()
player = {}
player.x = 0
player.y = 110
player.bullets = {}
player.cooldown = 20
player.speed = 2
player.image = love.graphics.newImage("player.png")
player.fire_sound = love.audio.newSource("shoot.wav")
player.fire = function()
if player.cooldown <= 0 then
love.audio.play(player.fire_sound)
player.cooldown = 20
bullet = {}
bullet.x = player.x + 4
bullet.y = player.y - 1
table.insert(player.bullets, bullet)
end
end
enemies_controller:spawnEnemy(0, 0)
enemies_controller:spawnEnemy(20, 0)
end
function enemies_controller:spawnEnemy(x, y)
enemy = {}
enemy.x = x
enemy.y = y
enemy.bullets = {}
enemy.cooldown = 20
enemy.speed = 2
table.insert(self.enemies, enemy)
end
function enemy:fire()
if self.cooldown <= 0 then
self.cooldown = 20
bullet = {}
bullet.x = self.x + 35
bullet.y = self.y
table.insert(self.bullets, bullet)
end
end
function love.update(dt)
player.cooldown = player.cooldown -1
if love.keyboard.isDown("right") then
player.x = player.x + player.speed
elseif love.keyboard.isDown("left") then
player.x = player.x - player.speed
end
if love.keyboard.isDown("space") then
player.fire()
end
for _,e in pairs(enemies_controller.enemies) do
e.y = e.y + 1
end
for i,b in ipairs(player.bullets) do
if b.y < -5 then
table.remove(player.bullets, i)
end
b.y = b.y - 2
end
end
function love.draw()
love.graphics.scale(5)
--draw player
love.graphics.setColor(255, 255, 255)
love.graphics.draw(player.image, player.x, player.y)
--draw enemy
for _,e in pairs(enemies_controller.enemies) do
love.graphics.draw(enemies_controller.image, e.x, e.y, 0, 1)
end
--draw bullets
love.graphics.setColor(225, 225, 225)
for _,b in pairs(player.bullets) do
love.graphics.rectangle("fill", b.x, b.y, 2, 2)
end
end
Thanks for helping!