Newer
Older
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#!/usr/bin/env python3
from level.level_abc import AbstractLevel
from lib.loader.loader import load_level, run_level, test_level
from lib.level.objects import find_var_in_frame, get_top_map
from lib.utils import lvl
import graphic.constants as cst
import arcade
class Level(AbstractLevel):
"""avoid_monster"""
def reset_skeletons(self):
skeletons = [self.map.named_objects[f"skeleton_{i}"] for i in range(1,5)]
for skeleton in skeletons:
payload = {
"topic": "object_update",
"object_name": skeleton.name,
"action": "change_color",
"color": arcade.color.WHITE,
}
self.send_to_gui(payload)
skeleton.visible = False
skeleton.send_update()
def arcade_custom_restart(self):
wop = self.map.named_objects["wop"]
wop.place_at(6, 6)
wop.visible = True
wop.send_update()
self.reset_skeletons()
if self.door_open:
payload = {
"topic": "sprites",
"action": "hide",
"layer": "decorations",
"locations": [
(1, 5), (1, 4)
],
}
self.send_to_gui(payload)
self.door_open = False
def arcade_custom_first_start(self):
player = self.map.player
self.current_map = "main"
skeletons = [self.map.named_objects[f"skeleton_{i}"] for i in range(1,5)]
wop = self.map.named_objects["wop"]
self.door_open = False
self.wop_spawn = False
def change_map(map_name):
self.reset_skeletons()
self.current_map = map_name
payload = {
"topic": "map_change",
"map": map_name,
}
player.send_update(payload)
def detect_map_change():
if wop.visible:
wop.visible = False
wop.send_update()
map_name = "third_room"
if self.current_map == "main":
map_name = "second_room"
change_map(map_name)
def to_direction(direction):
if direction == "DIR_UP":
return cst.Direction.UP
elif direction == "DIR_DOWN":
return cst.Direction.DOWN
elif direction == "DIR_LEFT":
return cst.Direction.LEFT
elif direction == "DIR_RIGHT":
return cst.Direction.RIGHT
def post_update(player, memory):
if not self.wop_spawn:
wop.visible = True
wop.place_at(6, 6)
wop.direction = cst.Direction.LEFT
wop.send_update()
wop.place_at(5, 6)
wop.send_update()
wop.talk("intro")
wop.direction = cst.Direction.RIGHT
wop.place_at(6, 6)
wop.send_update()
wop.direction = cst.Direction.DOWN
wop.send_update()
self.wop_spawn = True
if not self.door_open:
payload = {
"topic": "sprites",
"action": "hide",
"layer": "decorations",
"locations": [
(1, 5), (1, 4)
],
}
self.send_to_gui(payload)
self.door_open = True
frames = memory["stack"]
for frame in frames:
if frame.name == "main":
monsters = find_var_in_frame(frame, "monsters_data")
try:
for m in monsters[0].info:
if m.id != -1:
skeletons[m.id].visible = True
skeletons[m.id].direction = to_direction(m.dir)
skeletons[m.id].place_at(m.x, m.y)
skeletons[m.id].send_update()
if m.player_seen:
payload = {
"topic": "object_update",
"object_name": f"skeleton_{m.id+1}",
"action": "change_color",
"color": arcade.color.RED,
}
self.send_to_gui(payload)
else:
skeletons[m.id].visible = False
skeletons[m.id].send_update()
except:
pass
player.post_update = post_update
self.register_breakpoint("change_map", detect_map_change)
def pre_validation(self):
self.checker.append_inputs(
[
"LEFT",
"LEFT",
"UP",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"UP",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"UP",
"UP",
"UP",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"DOWN",
"DOWN",
"DOWN",
"DOWN",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"RIGHT",
"DOWN",
"DOWN",
"WAIT",
"WAIT",
"WAIT",
"WAIT",
"DOWN",
"UP",
"DOWN",
"DOWN",
"DOWN",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
"LEFT",
]
)
def test(self):
pass
if __name__ == "__main__":
# run_level(Level, __file__, level_type="text")
# run_level(Level, __file__, level_type="arcade")
test_level(Level, __file__)