simple right/left movement doesnt work
Posted: Fri Apr 04, 2014 4:12 pm
i am just learning how to do coding in love2d and lua, but when i try to make this super simple up/down/left/right movement it goes diagonally, for some reason... here's the problem code(in player.lua):
to clarify myself, i did put playerMove() and playerDraw() in the love.update() and love.draw() functions in main.lua.
Code: Select all
player = {}
player.x = 300
player.y = 300
player.speed = 10
player.health = 20
player.damage = 2
player.pic = love.graphics.newImage("anka.png")
function playerDraw()
love.graphics.setColor(255, 255, 255)
love.graphics.draw(player.pic, player.x, player.x)
end
function playerMove()
if love.keyboard.isDown("up") then
player.y = player.y - player.speed
end
if love.keyboard.isDown("down") then
player.y = player.y + player.speed
end
if love.keyboard.isDown("left") then
player.x = player.x - player.speed
end
if love.keyboard.isDown("right") then
player.x = player.x + player.speed
end
end