So a week or so I came back to Löve2D and I started to play around with it and at the moment I've implemented a very simple movement code that moves a rectangle in 4 different directions:
Code: Select all
function love.load()
--Movement
-- movePlayer = true
moveX = 100
moveY = 100
cyan = love.graphics.setColor(0, 255, 255)
pink = love.graphics.setColor(255, 105, 180)
end
function love.update(dt)
-- Super simple movement
if love.keyboard.isDown("w") then
moveY = moveY - 100 * dt
elseif love.keyboard.isDown("a") then
moveX = moveX - 100 * dt
elseif love.keyboard.isDown("s") then
moveY = moveY + 100 * dt
elseif love.keyboard.isDown("d") then
moveX = moveX + 100 * dt
end
end
function love.draw()
-- A square
love.graphics.rectangle("line",moveX, moveY, 50, 50)
love.graphics.setColor{math.random(0,255),math.random(0, 255), math.random(0,255)}
-- love.graphics.setBackgroundColor{math.random(0,255),math.random(0, 255), math.random(0,255)}
-- love.graphics.setBackgroundColor{0, math.random(250, 255), math.random(0,255)}
-- love.graphics.setBackgroundColor{math.random(120, 255), 0, math.random(120,255)}
end
Do I need to use velocity? friction? or some combination?