-
Notifications
You must be signed in to change notification settings - Fork 0
/
party.lua
103 lines (91 loc) · 2.01 KB
/
party.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- party.lua
-- class containing necessary things about party
local Party = {}
map = require "map"
-- keeps party direction 0 - north, 1 - east, 2 - south, 3 - west
local direction = 0
local x = 0
local y = 0
local map = 0
--- Constructor of the party table ("class")
-- @param newX map coordinates where the party should be spawn
-- @param newY map coordinates where the party should be spawn
-- @param newDirection direction of the new party
function Party:new(newX, newY, newDirection, newMap)
x = newX
y = newY
direction = newDirection
map = newMap
print("Info: Creating new party, x:" .. newX .. " y: " .. newY .. ", direction: " .. newDirection)
return self
end
function Party:changeDirection(change)
if change == 1 then direction = direction + 1
elseif change == -1 then direction = direction - 1
else print 'Wat! Invalid argument to party.changeDirection'
end
party.correctDirection()
print('Party direction: ' .. direction)
end
function Party:correctDirection()
if direction > 3 then direction = 0 end
if direction < 0 then direction = 3 end
end
function Party:setX(new_x)
x = new_x
end
function Party:getX()
return x
end
function Party:setY(new_y)
y = new_y
end
function Party:getY()
return y
end
function Party:getDirection()
return direction
end
function Party:moveForward()
if direction == 0 then
if map[y-1][x] == 0 then
y = y - 1
end
elseif direction == 1 then
if map[y][x+1] == 0 then
x = x + 1
end
elseif direction == 2 then
if map[y+1][x] == 0 then
y = y + 1
end
elseif direction == 3 then
if map[y][x-1] == 0 then
x = x - 1
end
else
print("Error in party orientation!")
end
end
function Party:moveBackward()
if direction == 0 then
if map[y+1][x] == 0 then
y = y + 1
end
elseif direction == 1 then
if map[y][x-1] == 0 then
x = x - 1
end
elseif direction == 2 then
if map[y-1][x] == 0 then
y = y - 1
end
elseif direction == 3 then
if map[y][x+1] == 0 then
x = x + 1
end
else
print("Error in party orientation!")
end
end
return Party