2015-04-06 01:18:46 -07:00
|
|
|
local Player = {}
|
2014-07-12 18:47:39 -07:00
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
local Textbox = require "action.textbox"
|
2014-07-12 18:47:39 -07:00
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
local Input = require "util.input"
|
|
|
|
local Memory = require "util.memory"
|
2014-07-12 18:47:39 -07:00
|
|
|
|
|
|
|
local facingDirections = {Up=8, Right=1, Left=2, Down=4}
|
2015-05-03 16:55:47 -07:00
|
|
|
local alternate = false
|
2014-07-12 18:47:39 -07:00
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
function Player.isFacing(direction)
|
|
|
|
return Memory.value("player", "facing") == facingDirections[direction]
|
2014-07-12 18:47:39 -07:00
|
|
|
end
|
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
function Player.face(direction)
|
|
|
|
if Player.isFacing(direction) then
|
2014-07-12 18:47:39 -07:00
|
|
|
return true
|
|
|
|
end
|
2015-04-06 01:18:46 -07:00
|
|
|
if Textbox.handle() then
|
|
|
|
Input.press(direction, 0)
|
2014-07-12 18:47:39 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-13 00:47:34 -07:00
|
|
|
function Player.interact(direction, extended)
|
2015-04-06 01:18:46 -07:00
|
|
|
if Player.face(direction) then
|
2015-05-03 16:55:47 -07:00
|
|
|
local speed = 2
|
|
|
|
if extended then
|
|
|
|
speed = alternate and 4 or 0
|
|
|
|
alternate = not alternate
|
2015-04-11 14:03:44 -07:00
|
|
|
end
|
|
|
|
Input.press("A", speed)
|
2014-07-12 18:47:39 -07:00
|
|
|
return true
|
|
|
|
end
|
2015-05-03 16:55:47 -07:00
|
|
|
alternate = false
|
2014-07-12 18:47:39 -07:00
|
|
|
end
|
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
function Player.isMoving()
|
|
|
|
return Memory.value("player", "moving") ~= 0
|
2014-07-12 18:47:39 -07:00
|
|
|
end
|
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
function Player.position()
|
|
|
|
return Memory.value("player", "x"), Memory.value("player", "y")
|
2014-07-12 18:47:39 -07:00
|
|
|
end
|
|
|
|
|
2015-04-06 01:18:46 -07:00
|
|
|
return Player
|