Added acceleration
This commit is contained in:
parent
249581fd9c
commit
59a303d122
@ -1,5 +1,11 @@
|
|||||||
require "Tserial"
|
require "Tserial"
|
||||||
|
|
||||||
|
function move(direction)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
|
|
||||||
love.filesystem.setIdentity("tommy")
|
love.filesystem.setIdentity("tommy")
|
||||||
@ -15,6 +21,9 @@ function love.load()
|
|||||||
player.w = 25
|
player.w = 25
|
||||||
player.h = 25
|
player.h = 25
|
||||||
player.speed = 100
|
player.speed = 100
|
||||||
|
player.current_speed = 0
|
||||||
|
--Must be less than 1
|
||||||
|
player.accel = 1/16
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.keyreleased(key)
|
function love.keyreleased(key)
|
||||||
@ -40,9 +49,18 @@ function love.update(dt)
|
|||||||
|
|
||||||
--Move character left or right
|
--Move character left or right
|
||||||
if love.keyboard.isDown("right") then
|
if love.keyboard.isDown("right") then
|
||||||
player.x = player.x + player.speed*dt
|
-- with acceleration
|
||||||
|
if player.current_speed < player.speed then
|
||||||
|
player.current_speed = player.current_speed + (player.speed*player.accel)
|
||||||
|
end
|
||||||
|
player.x = player.x + player.current_speed*dt
|
||||||
|
|
||||||
elseif love.keyboard.isDown("left") then
|
elseif love.keyboard.isDown("left") then
|
||||||
player.x = player.x - player.speed*dt
|
player.x = player.x - player.speed*dt
|
||||||
|
|
||||||
|
--Reset current speed if key is released
|
||||||
|
elseif not love.keyboard.isDown("right") then
|
||||||
|
player.current_speed = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
--Also able to move or up down at the same time as one of the above
|
--Also able to move or up down at the same time as one of the above
|
||||||
@ -51,6 +69,7 @@ function love.update(dt)
|
|||||||
elseif love.keyboard.isDown ("down") then
|
elseif love.keyboard.isDown ("down") then
|
||||||
player.y = player.y + player.speed*dt
|
player.y = player.y + player.speed*dt
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user