mike: Added half movement speed key; added variables for keys
This commit is contained in:
parent
4235950bcc
commit
3953d079d6
@ -1,15 +1,22 @@
|
|||||||
require "lib/Tserial"
|
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)
|
function love.keyreleased(key)
|
||||||
if key == "q" then
|
if key == QUIT_KEY then
|
||||||
love.event.quit()
|
love.event.quit()
|
||||||
|
|
||||||
-- save
|
-- save
|
||||||
elseif key == "s" then
|
elseif key == SAVE_KEY then
|
||||||
love.filesystem.write(saveFile, Tserial.pack(player, false, true))
|
love.filesystem.write(saveFile, Tserial.pack(player, false, true))
|
||||||
|
|
||||||
-- Load
|
-- Load
|
||||||
elseif key == "l" then
|
elseif key == LOAD_KEY then
|
||||||
|
|
||||||
save_exists = love.filesystem.exists(saveFile)
|
save_exists = love.filesystem.exists(saveFile)
|
||||||
|
|
||||||
@ -19,6 +26,13 @@ function love.keyreleased(key)
|
|||||||
end
|
end
|
||||||
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)
|
function check_keys(object)
|
||||||
local newObject = {}
|
local newObject = {}
|
||||||
newObject.x = object.x
|
newObject.x = object.x
|
||||||
@ -27,12 +41,12 @@ function check_keys(object)
|
|||||||
newObject.height = object.height
|
newObject.height = object.height
|
||||||
newObject.speed = object.speed
|
newObject.speed = object.speed
|
||||||
|
|
||||||
if love.keyboard.isDown("right") then
|
if love.keyboard.isDown(MOVE_RIGHT) then
|
||||||
newObject.x = newObject.x + newObject.speed
|
newObject.x = newObject.x + half_speed(newObject.speed)
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.keyboard.isDown("left") then
|
if love.keyboard.isDown(MOVE_LEFT) then
|
||||||
newObject.x = newObject.x - newObject.speed
|
newObject.x = newObject.x - half_speed(newObject.speed)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if love.keyboard.isDown("up") then
|
-- if love.keyboard.isDown("up") then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user