Here's the code and where the error is:
Code: Select all
player = {}
function player.load()
player.x = 5
player.y = 5
player.xvel = 0
player.yvel = 0
player.friction = 7
player.speed = 2250
player.width = 50
player.height = 50
end
function player.draw()
love.graphics.setColor(255,0,0)
love.graphics.rectangle("fill", player.x, player.y, player.width, player.height)
end
--Here is where it says that there's an error:
function player.physics(dt)
player.x = player.x + player.xvel * dt
player.y = player.y + player.yvel * dt
player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
end
function player.move(dt)
if love.keyboard.isDown("right") and
player.xvel < player.speed then
player.xvel = player.xvel + player.speed * dt
end
if love.keyboard.isDown("left") and
player.xvel < -player.speed then
player.xvel = player.xvel - player.speed * dt
end
end
--More functions including other functions.
function UPDATE_PLAYER(dt)
player.physics(dt)
player.move(dt)
end
function DRAW_PLAYER()
player.draw()
end