67 lines
1.3 KiB
Lua

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 == QUIT_KEY then
love.event.quit()
-- save
elseif key == SAVE_KEY then
love.filesystem.write(saveFile, Tserial.pack(player, false, true))
-- Load
elseif key == LOAD_KEY then
save_exists = love.filesystem.exists(saveFile)
if save_exists then
player = Tserial.unpack( love.filesystem.read( saveFile ) )
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)
local newObject = {}
newObject.x = object.x
newObject.y = object.y
newObject.width = object.width
newObject.height = object.height
newObject.speed = object.speed
if love.keyboard.isDown(MOVE_RIGHT) then
newObject.x = newObject.x + half_speed(newObject.speed)
end
if love.keyboard.isDown(MOVE_LEFT) then
newObject.x = newObject.x - half_speed(newObject.speed)
end
-- if love.keyboard.isDown("up") then
-- newObject.y = newObject.y - newObject.speed
-- end
-- if love.keyboard.isDown("down") then
-- newObject.y = newObject.y + newObject.speed
-- end
if col_detect(newObject, screen) then
return newObject
else
return object
end
end