From 3953d079d6724701fdee429e845c54a562199583 Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sat, 22 Jul 2017 14:54:36 -0700 Subject: [PATCH] mike: Added half movement speed key; added variables for keys --- love/mike/lib/keys.lua | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/love/mike/lib/keys.lua b/love/mike/lib/keys.lua index 07d1de8..a172964 100644 --- a/love/mike/lib/keys.lua +++ b/love/mike/lib/keys.lua @@ -1,15 +1,22 @@ require "lib/Tserial" +QUIT_KEY = "q" +SAVE_KEY = "s" +LOAD_KEY = "l" +HALF_SPEED = "lshift" +MOVE_RIGHT = "right" +MOVE_LEFT = "left" + function love.keyreleased(key) - if key == "q" then + if key == QUIT_KEY then love.event.quit() -- save - elseif key == "s" then + elseif key == SAVE_KEY then love.filesystem.write(saveFile, Tserial.pack(player, false, true)) -- Load - elseif key == "l" then + elseif key == LOAD_KEY then save_exists = love.filesystem.exists(saveFile) @@ -19,6 +26,13 @@ function love.keyreleased(key) end end +function half_speed(object_speed) + if love.keyboard.isDown(HALF_SPEED) then + return object_speed/2 + else return object_speed + end +end + function check_keys(object) local newObject = {} newObject.x = object.x @@ -27,12 +41,12 @@ function check_keys(object) newObject.height = object.height newObject.speed = object.speed - if love.keyboard.isDown("right") then - newObject.x = newObject.x + newObject.speed + if love.keyboard.isDown(MOVE_RIGHT) then + newObject.x = newObject.x + half_speed(newObject.speed) end - if love.keyboard.isDown("left") then - newObject.x = newObject.x - newObject.speed + if love.keyboard.isDown(MOVE_LEFT) then + newObject.x = newObject.x - half_speed(newObject.speed) end -- if love.keyboard.isDown("up") then