1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2024-12-12 10:04:40 +02:00
RedMew/locale/gen_shared/compass.lua

33 lines
634 B
Lua
Raw Normal View History

2017-07-20 23:22:09 +02:00
--Author Valansch
Compass = {}
Compass.__index = Compass
Compass.north={x=0,y=-1,next="west"}
Compass.west={x=-1,y=0,next="south"}
Compass.south={x=0,y=1,next="east"}
Compass.east={x=1,y=0,next="north"}
function Compass.new(start_direction)
local self = setmetatable({}, Compass)
self.direction = start_direction or "north"
return self
end
function Compass:turn_left()
self.direction= self:get_direction().next
end
function Compass:get_direction()
return self[self.direction]
end
function Compass:turn_right()
self:turn()
self:turn()
self:turn()
end
function Compass:turn_around()
self:turn()
self:turn()
end