2017-07-25 21:25:45 -07:00
|
|
|
require "lib/GameState"
|
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-30 20:33:43 -07:00
|
|
|
SAVE_FILE = "testing.lua"
|
2017-07-22 14:54:36 -07:00
|
|
|
|
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-25 21:25:45 -07:00
|
|
|
--love.filesystem.write(saveFile, Tserial.pack(player, false, true))
|
2017-07-30 20:33:43 -07:00
|
|
|
love.filesystem.write(SAVE_FILE, GameState.save(actors, "actors"))
|
2017-07-05 07:11:51 -07:00
|
|
|
|
|
|
|
-- Load
|
2017-07-22 14:54:36 -07:00
|
|
|
elseif key == LOAD_KEY then
|
2017-07-05 07:11:51 -07:00
|
|
|
|
2017-07-30 20:33:43 -07:00
|
|
|
save_exists = love.filesystem.exists(SAVE_FILE)
|
2017-07-05 07:11:51 -07:00
|
|
|
|
|
|
|
if save_exists then
|
2017-07-25 21:25:45 -07:00
|
|
|
--player = Tserial.unpack( love.filesystem.read( saveFile ) )
|
2017-07-30 20:33:43 -07:00
|
|
|
GameState.load(SAVE_FILE)
|
2017-07-05 07:11:51 -07:00
|
|
|
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-25 18:41:25 -07:00
|
|
|
function check_keys(object, screen, dt)
|
2017-07-05 07:11:51 -07:00
|
|
|
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
|
2017-07-25 18:41:25 -07:00
|
|
|
newObject.x = newObject.x + half_speed(newObject.speed * dt)
|
2017-07-05 07:11:51 -07:00
|
|
|
end
|
|
|
|
|
2017-07-22 14:54:36 -07:00
|
|
|
if love.keyboard.isDown(MOVE_LEFT) then
|
2017-07-25 18:41:25 -07:00
|
|
|
newObject.x = newObject.x - half_speed(newObject.speed * dt)
|
2017-07-05 07:11:51 -07:00
|
|
|
end
|
|
|
|
|
2017-07-22 16:43:07 -07:00
|
|
|
if screen_col_detect(newObject, screen) then
|
2017-07-05 07:11:51 -07:00
|
|
|
return newObject
|
|
|
|
else
|
|
|
|
return object
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-25 18:31:15 -07:00
|
|
|
--Inspired by https://love2d.org/wiki/BoundingBox.lua
|
|
|
|
--Returns true if boxes overlap
|