-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldState.lua
180 lines (162 loc) · 4.05 KB
/
worldState.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
local Json = require 'json'
local WorldState = { data = {} }
local function defaultState()
return { gems = {red = false, blue = false, green = false, yellow = false} }
end
function WorldState.init(dir)
WorldState.dir = dir
WorldState.data.islands = {
saucer = {
pos = {x = 1, y = 1},
stuff = "grass",
feature = "shipCrash",
title = "Whoops...",
level = "saucer01",
transition = "saucerLand",
smoke = true,
canQuitToWorld = false,
--bgmName = 'Mighty Like Us'
},
map01 = {
pos = {x = 2, y = 1},
stuff = "grass",
feature = "grassBits",
title = "This seems nice?",
level = "map01",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
},
map03 = {
pos = {x = 3, y = 1},
stuff = "grass",
feature = "grassWater",
title = "A quick dip!",
level = "map03",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'Mighty Like Us'
},
map05 = {
pos = {x = 4, y = 1},
stuff = "grass",
feature = "greenSmilies",
title = "The only way is... wait what?",
level = "map05",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
},
map07 = {
pos = {x = 5, y = 1},
stuff = "ice",
--feature = "",
title = "Brrrrr",
level = "map07",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'Mighty Like Us'
},
map09 = {
pos = {x = 6, y = 1},
stuff = "grass",
feature = "factory",
title = "Pressin my buttons",
level = "map09",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
},
mapSecret01 = {
pos = {x = 2, y = 2},
stuff = "grass",
--feature = "grassWater",
title = "So what does this do?",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
},
--test levels, hidden
testfac = {
pos = {x = 4, y = 100},
stuff = "grass",
feature = "greenSmilies",
title = "Test level",
level = "testfac",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
},
testwat = {
pos = {x = 4, y = 101},
stuff = "grass",
feature = "greenSmilies",
title = "Test level",
level = "testwat",
transition = "saucerBeam",
canQuitToWorld = true,
bgmName = 'The Show Must Be Go'
}
}
for _, i in pairs(WorldState.data.islands) do
i.state = defaultState()
end
WorldState.data.barriers = {
map01green = {
color = "Green",
from = {x=2,y=1},
to = {x=3,y=1},
},
map01blue = {
color = "Blue",
from = {x=2,y=1},
to = {x=2,y=2},
},
map03blue = {
color = "Blue",
from = {x=3,y=1},
to = {x=4,y=1},
},
map05green = {
color = "Green",
from = {x=4,y=1},
to = {x=5,y=1},
},
}
WorldState.data.saucerLoc = {x=1, y=1}
WorldState.data.money = 0
end
function WorldState.incMoney(money)
WorldState.data.money = WorldState.data.money + money
end
function WorldState.destroyBarriers(barrierNames)
for barrierName, _ in pairs(barrierNames) do
WorldState.data.barriers[barrierName] = nil
end
end
function WorldState.changeLevels(changedLevels)
for islandName, islandData in pairs(changedLevels) do
for k, v in pairs(islandData) do
WorldState.data.islands[islandName][k] = v
end
end
end
function WorldState.gotGems(mapName, gems)
for gem, got in pairs(gems) do
if got then
WorldState.data.islands[mapName].state.gems[gem] = true
end
end
end
function WorldState.setSaucerLoc(sl)
WorldState.data.saucerLoc.x = sl.x
WorldState.data.saucerLoc.y = sl.y
end
function WorldState.fromJSON(str, dir)
WorldState.data = Json.decode(str)
WorldState.dir = dir
end
function WorldState.toJSON()
return Json.encode(WorldState.data)
end
return WorldState