2017-07-05 07:22:58 -07:00
|
|
|
require "lib/Tserial"
|
2017-07-05 07:11:51 -07:00
|
|
|
|
2017-07-22 14:54:36 -07:00
|
|
|
QUIT_KEY = "q"
|
|
|
|
SAVE_KEY = "s"
|
|
|
|
LOAD_KEY = "l"
|
|
|
|
HALF_SPEED = "lshift"
|
|
|
|
MOVE_RIGHT = "right"
|
|
|
|
MOVE_LEFT = "left"
|
|
|
|
|
2017-07-05 07:11:51 -07:00
|
|
|
function love.keyreleased(key)
|
2017-07-22 14:54:36 -07:00
|
|
|
if key == QUIT_KEY then
|
2017-07-05 07:11:51 -07:00
|
|
|
love.event.quit()
|
|
|
|
|
|
|
|
-- save
|
2017-07-22 14:54:36 -07:00
|
|
|
elseif key == SAVE_KEY then
|
2017-07-05 07:11:51 -07:00
|
|
|
love.filesystem.write(saveFile, Tserial.pack(player, false, true))
|
|
|
|
|
|
|
|
-- Load
|
2017-07-22 14:54:36 -07:00
|
|
|
elseif key == LOAD_KEY then
|
2017-07-05 07:11:51 -07:00
|
|
|
|
|
|
|
save_exists = love.filesystem.exists(saveFile)
|
|
|
|
|
|
|
|
if save_exists then
|
|
|
|
player = Tserial.unpack( love.filesystem.read( saveFile ) )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-22 14:54:36 -07:00
|
|
|
function half_speed(object_speed)
|
|
|
|
if love.keyboard.isDown(HALF_SPEED) then
|
|
|
|
return object_speed/2
|
|
|
|
else return object_speed
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-05 07:11:51 -07:00
|
|
|
function check_keys(object)
|
|
|
|
local newObject = {}
|
|
|
|
newObject.x = object.x
|
|
|
|
newObject.y = object.y
|
|
|
|
newObject.width = object.width
|
|
|
|
newObject.height = object.height
|
|
|
|
newObject.speed = object.speed
|
|
|
|
|
2017-07-22 14:54:36 -07:00
|
|
|
if love.keyboard.isDown(MOVE_RIGHT) then
|
|
|
|
newObject.x = newObject.x + half_speed(newObject.speed)
|
2017-07-05 07:11:51 -07:00
|
|
|
end
|
|
|
|
|
2017-07-22 14:54:36 -07:00
|
|
|
if love.keyboard.isDown(MOVE_LEFT) then
|
|
|
|
newObject.x = newObject.x - half_speed(newObject.speed)
|
2017-07-05 07:11:51 -07:00
|
|
|
end
|
|
|
|
|
2017-07-05 07:18:32 -07:00
|
|
|
-- if love.keyboard.isDown("up") then
|
|
|
|
-- newObject.y = newObject.y - newObject.speed
|
|
|
|
-- end
|
2017-07-05 07:11:51 -07:00
|
|
|
|
2017-07-05 07:18:32 -07:00
|
|
|
-- if love.keyboard.isDown("down") then
|
|
|
|
-- newObject.y = newObject.y + newObject.speed
|
|
|
|
-- end
|
2017-07-05 07:11:51 -07:00
|
|
|
|
|
|
|
if col_detect(newObject, screen) then
|
|
|
|
return newObject
|
|
|
|
else
|
|
|
|
return object
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|