From b9393dda5f427ac3da69e9a285b08665ecbaf6ad Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Fri, 25 Nov 2016 14:52:16 -0700 Subject: [PATCH] Added accel to all directions; moved accel to function --- love/tommy/main.lua | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/love/tommy/main.lua b/love/tommy/main.lua index 98d4b73..c030d3b 100644 --- a/love/tommy/main.lua +++ b/love/tommy/main.lua @@ -1,7 +1,13 @@ require "Tserial" -function move(direction) +function move(void) + -- with acceleration + + if player.current_speed < player.speed then + player.current_speed = player.current_speed + (player.speed*player.accel) + end + return player.current_speed end @@ -20,10 +26,12 @@ function love.load() player.y = 100 player.w = 25 player.h = 25 - player.speed = 100 + player.speed = 500 player.current_speed = 0 --Must be less than 1 - player.accel = 1/16 + --if I understand correctly, the second number should be how many frames + --it takes to get to top speed + player.accel = 1/120 end function love.keyreleased(key) @@ -49,27 +57,29 @@ function love.update(dt) --Move character left or right if love.keyboard.isDown("right") then - -- 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 + move() + player.x = player.x + player.current_speed*dt elseif love.keyboard.isDown("left") then - player.x = player.x - player.speed*dt + move() + player.x = player.x - player.current_speed*dt --Reset current speed if key is released - elseif not love.keyboard.isDown("right") then - player.current_speed = 0 end --Also able to move or up down at the same time as one of the above if love.keyboard.isDown("up") then - player.y = player.y - player.speed*dt + move() + player.y = player.y - player.current_speed*dt elseif love.keyboard.isDown ("down") then - player.y = player.y + player.speed*dt + move() + player.y = player.y + player.current_speed*dt end + if not love.keyboard.isDown("right", "left", "up", "down") then + player.current_speed = 0 + end + end function love.draw()