-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcollectables.asm
422 lines (336 loc) · 6.46 KB
/
collectables.asm
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
init_collectables
SELECT_BANK item_bank_config
ld a, 0xff ; empty the pockets
ld (pocket1), a
ld (pocket2), a
ld (pocket3), a
ld ix, col_key_yellow ; move 'fixed' items back
init_coll1
ld a, (ix + 0)
cp 0xff
jr z, do_random_collectables
ld a, (ix + 5)
ld (ix + 0), a ; reset room number
ld a, (ix + 6)
ld (ix + 3), a ; reset x
ld a, (ix + 7)
ld (ix + 4), a ; reset y
ld de, 8
add ix, de
jr init_coll1
do_random_collectables
ld a, r
ld (random_seed), a
RANDOM_IN_A
and 0x07 ; random 0 to 7
ld l, a
ld h, 0
add hl, hl
ld de, random_place_table
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; hl has address of random data
ld ix, collectable_items
ld b, 6 ; 6 items are randomly placed (3 key parts, 3 keys)
ld de, 8
random_place_loop
ld a, (hl)
ld (ix + 0), a
inc hl
ld a, (hl)
ld (ix + 3), a
inc hl
ld a, (hl)
ld (ix + 4), a
inc hl
add ix, de
djnz random_place_loop
ld a, (col_key_red)
ld (mummy_room), a
ld a, room_dracula
ld (dracula_room), a
ret
draw_collectables
ld a, (room_number)
ld c, a
ld ix, collectable_items
collectable_loop
ld a, (ix + 0)
cp 0xff
ret z
cp c ; only draw if in this room
call z, draw_this_collectable
ld de, 8
add ix, de
jr collectable_loop
pickup_tapped
ld e, sound_c_food
call play_sfx
ld a, (room_number)
ld c, a
ld ix, collectable_items
ld b, 0
pickup_loop
ld a, (ix + 0)
cp 0xff
jr z, shuffle_pockets
ld d, 0
cp c ; can only pick things up that are in this room
call z, collect_this_collectable
ld a, d
and a ; stop now if colllected something
jr nz, shuffle_pockets
inc b ; b holds collectable item index
ld de, 8
add ix, de
jr pickup_loop
shuffle_pockets ; if nothing collected, a is 0xff, else b has collected item index
ld c, a
ld a, (pocket3)
ld e, a
ld a, (pocket2)
ld (pocket3), a
ld a, (pocket1)
ld (pocket2), a
ld a, 0xff
ld (pocket1), a
ld a, c
cp 0xff
jr z, pockets_done
ld a, b
ld (pocket1), a
ld (ix + 0), 0xfe ; take out of current room
cp the_red_key
jr nz, not_collected_red
ld a, (mummy_room)
ld c, a
ld a, (room_number)
cp c
jr nz, not_in_mummy_room
ld a, 1
ld (mummy_angry), a
not_in_mummy_room
ld a, b
not_collected_red
push de
SELECT_BANK room_bank_config
call draw_this_collectable ; and erase from both screens
ld hl, (save_collectable_screen_loc)
ld a, h
xor 0x40
ld h, a
call draw_this_collectable2
pop de
pockets_done
ld a, e ; drop an item?
cp 0xff
jr z, no_drop
; move item with this index into current room and draw it on both screens...
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl ; x 8
ld de, collectable_items
add hl, de
ex de, hl
ld ixh, d
ld ixl, e
ex de, hl
ld a, (room_number)
ld (ix + 0), a
ld a, (player_x)
srl a
ld (ix + 3), a
ld a, (player_y)
add 4
ld (ix + 4), a
SELECT_BANK room_bank_config
call draw_this_collectable
ld hl, (save_collectable_screen_loc)
ld a, h
xor 0x40
ld h, a
call draw_this_collectable2
no_drop
ld a, 2
ld (do_pockets), a
call update_collision_grid_for_items
ret
draw_pockets
ld de, (scr_addr_table)
ld hl, 0x0022 ; pocket item y
add hl, hl
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ld de, 0x0032 ; first pocket item x
add hl, de
SELECT_BANK room_bank_config
push hl
ld a, (pocket1)
call draw_this_pocket
pop hl
inc l
inc l
inc l
inc l
push hl
ld a, (pocket2)
call draw_this_pocket
pop hl
inc l
inc l
inc l
inc l
ld a, (pocket3)
draw_this_pocket ; hl = screen address, a = collectable item index
cp 0xff
jr z, draw_empty_pocket
draw_full_pocket
push hl
ld l, a
ld h, 0
add hl, hl
add hl, hl
add hl, hl ; x8
ld de, collectable_items
add hl, de
inc hl
ld e, (hl)
inc hl
ld d, (hl)
pop hl
ld b, 16
dfpl1
ld a, (de)
ld (hl), a
inc l
inc de
ld a, (de)
ld (hl), a
inc l
inc de
ld a, (de)
ld (hl), a
inc l
inc de
ld a, (de)
ld (hl), a
inc de
dec l
dec l
dec l
GET_NEXT_SCR_LINE
djnz dfpl1
ret
draw_empty_pocket
ld b, 16
ld e, 0x00
depl1
ld (hl), e
inc l
ld (hl), e
inc l
ld (hl), e
inc l
ld (hl), e
dec l
dec l
dec l
GET_NEXT_SCR_LINE
djnz depl1
ret
draw_this_collectable
ld de, (scr_addr_table)
ld l, (ix + 4)
ld h, 0
add hl, hl
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ld e, (ix + 3)
ld d, 0
add hl, de
ld (save_collectable_screen_loc), hl
draw_this_collectable2
ld e, (ix + 1)
ld d, (ix + 2)
push bc
draw_this_collectable_entry2
ld b, 16
collectable_draw_loop
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc l
inc de
ld a, (de)
xor (hl)
ld (hl), a
inc de
dec l
dec l
dec l
GET_NEXT_SCR_LINE
djnz collectable_draw_loop
pop bc
ret
collect_this_collectable ; compare centers and a tolerance
ld a, (player_x)
srl a
add 2
ld e, a
ld a, (ix + 3)
add 2
sub e
bit 7, a
jr z, not_neg_x
neg
not_neg_x
cp 4
ret nc
ld a, (player_y)
add average_player_height / 2
ld e, a
ld a, (ix + 4)
add 8
sub e
bit 7, a
jr z, not_neg_y
neg
not_neg_y
cp 8
ret nc
ld d, 1
ret
do_pockets
defb 0x00
pocket1
defb 0xff
pocket2
defb 0xff
pocket3
defb 0xff
mummy_room
defb 0x00
dracula_room
defb 0x00
save_collectable_screen_loc
defw 0