-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfood.asm
338 lines (263 loc) · 4.78 KB
/
food.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
init_food
SELECT_BANK sprite_bank_config
ld ix, food_items
ld b, (food_items_end - food_items) / 8
ld de, 8
food_init_loop
ld (ix + 2), 0
add ix, de
djnz food_init_loop
ld ix, tombstones
ld (ix + 1), 0xff
ld (ix + 9), 0xff
ld (ix + 17), 0xff
ret
replen_food
SELECT_BANK sprite_bank_config
ld ix, food_items
ld b, (food_items_end - food_items) / 8
ld de, 8
food_replen_loop
ld a, (ix + 2)
and a
jr z, no_replen
dec a
ld (ix + 2), a
no_replen
add ix, de
djnz food_replen_loop
ret
add_tombstone
ld ix, tombstones
ld a, (num_lives)
sla a
sla a
sla a
ld e, a
ld d, 0
add ix, de
ld a, (room_number)
ld (ix + 1), a
ld a, (player_x)
srl a
ld (ix + 3), a
ld a, (player_y)
ld b, a
ld a, (actual_player_height)
add b
ld (ix + 4), a
ld (draw_tombstone_with_index), ix
jp draw_food_item2
check_food_collision
ld c, a
SELECT_BANK sprite_bank_config
ld b, c
ld hl, this_rooms_food_list
ld iyh, 0
check_next_food_item_collision
ld a, (hl)
ld ixl, a
inc hl
ld a, (hl)
ld ixh, a
ld a, (ix + 2)
and a
call z, check_food
ld a, iyh ; exit early if collected food
and a
ret nz
inc hl
djnz check_next_food_item_collision
ret
check_food
push hl
push bc
ld a, (player_x)
srl a
add 2
ld e, a
ld a, (ix + 3)
add 1
sub e
bit 7, a
jr z, food_not_neg_x
neg
food_not_neg_x
cp 4
jr nc, cant_find_food
ld a, (player_y)
add average_player_height / 2
ld e, a
ld a, (ix + 4)
ld c, (ix + 7)
srl c
sub c
sub e
bit 7, a
jr z, food_not_neg_y
neg
food_not_neg_y
cp 12
jr nc, cant_find_food
ld a, (ix + 0)
cp type_tombstone
jr z, cant_find_food
cp type_mushroom
jr nz, remove_food
ld e, sound_clock
call play_sfx
hdecay
call health_decay
jr cant_find_food
remove_food
call draw_food_item2
SELECT_BANK sprite_bank_config
ld a, food_respawn
ld (ix + 2), a
ld (erase_food_with_index), ix
ld e, sound_c_food
call play_sfx
call health_up
ld iyh, 1
cant_find_food
pop bc
pop hl
ret
reset_food_collected
ld hl, 0
ld (erase_food_with_index), hl
ld (draw_tombstone_with_index), hl
ret
draw_food
xor a
ld (this_rooms_food_count), a
call create_food_list
SELECT_BANK room_bank_config
ld a, (this_rooms_food_count)
and a
ret z
ld hl, this_rooms_food_list
ld b, a
draw_food_loop
push hl
push bc
call draw_food_item
pop bc
pop hl
inc hl
inc hl
djnz draw_food_loop
ret
draw_food_item ; hl pointer in food_items
SELECT_BANK sprite_bank_config
ld a, (hl)
ld ixl, a
inc hl
ld a, (hl)
ld ixh, a
draw_food_item2
ld a, (ix + 4)
ld c, (ix + 7)
sub c
ld l, a
ld h, 0
add hl, hl
ld de, (scr_addr_table)
add hl, de
ld a, (hl)
inc hl
ld h, (hl)
ld l, a
ld c, (ix + 3)
ld b, 0
add hl, bc ; add x, now hl has screen address
ex de, hl
ld a, (ix + 0)
sub 0x50
add a
ld l, a
ld h, 0
ld bc, food_table
add hl, bc
ld a, (hl)
inc hl
ld h, (hl)
ld l, a ; hl has food gfx
ex de, hl
ld c, (ix + 7)
SELECT_BANK room_bank_config
ld b, c
draw_food_item_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 draw_food_item_loop
ret
create_food_list
SELECT_BANK sprite_bank_config
ld a, (room_number)
ld c, a
ld ix, food_items
ld b, (food_items_end - food_items) / 8
list_food_loop
push bc
ld a, (ix + 1)
cp c
jr nz, skip_food_item
ld a, (ix + 2)
and a
jr nz, skip_food_item
ld a, (this_rooms_food_count)
add a
ld l, a
ld h, 0
ld bc, this_rooms_food_list
add hl, bc
ld a, ixl
ld (hl), a
inc hl
ld a, ixh
ld (hl), a
ld hl, this_rooms_food_count
inc (hl)
ld a, (hl)
cp max_food
jr c, skip_food_item
pop bc
ret
skip_food_item
pop bc
ld de, 8
add ix, de
djnz list_food_loop
ret
food_table
defw item_can, item_candycane
defw item_ham, item_lolly
defw item_icecream, item_bowl
defw item_apple, item_milk
defw item_mushroom, item_tombstone
erase_food_with_index
defw 0x00
draw_tombstone_with_index
defw 0x00