-
Notifications
You must be signed in to change notification settings - Fork 1
/
enemies.asm
264 lines (209 loc) · 4.03 KB
/
enemies.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
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module ENEMIES
initialiseenemies:
ld hl,enemydata
ld de,enemydata+1
ld bc,ENEMYSIZE*NENEMIES-1
ld (hl),0
ldir
xor a
ld (BONUSES._eeaten),a
ld iy,enemydata
ret
initenemytimer:
xor a ; reset count
ld (generatimer),a
ld a,(level) ; 0..7
and a
rlca
rlca
rlca ; 0..56
ld b,a
ld a,110
sub b
ld (leveltrig),a ; 110 .. 54
ret
generateenemy:
ld a,(leveltrig)
ld b,a
ld a,(generatimer)
inc a
cp b
jr nz,{+}
call startenemy
xor a
+: ld (generatimer),a
ret
startenemy:
ld a,3
call AFXPLAY
xor a
ld de,ENEMYSIZE
ld b,NENEMIES
ld iy,enemydata
jr {+}
-: add iy,de
+: cp (iy)
jr z,_ehstart
djnz {-}
ret
_ehstart:
inc (iy)
ld a,(entrancecount) ; shonky fixed point multiply
ld b,a ; get a random byte, treat it as a n/256 fraction
call xrnd8 ; add it to a total (entrancecount) times
ld c,a ; integer part is incremented when carry over
xor a
ld l,a
-: add a,c
jr nc,{+}
inc l
+: djnz {-}
ld a,l ; l is integer 0..entranceCount-1
and a ; clear carry
rlca
rlca
rlca
or entrances & 255
ld l,a
ld h,entrances / 256
ld a,(hl) ; address l
ld (iy+EO_ADL),a
inc hl
ld a,(hl) ; address h
ld (iy+EO_ADH),a
inc hl
ld a,(hl) ; direction
ld (iy+EO_MDL),a
inc hl
ld a,(hl) ; direction
ld (iy+EO_MDH),a
inc hl
ld a,(hl) ; animation number
and a ; clear carry
rlca
or enemyanims & 255
ld (iy+EO_ANL),a
ld (iy+EO_ANH),enemyanims / 256
ret
updateenemies:
ld b,NENEMIES
ld iy,enemydata
jr {+}
-: ld de,ENEMYSIZE ; de is corrupted in call so need to re-init
add iy,de
+: ld a,(iy)
cp 1
call z,_ehup
djnz {-}
ret
_ehup:
ld l,(iy+EO_ADL)
ld h,(iy+EO_ADH)
ex de,hl ; check if the player has eaten this enemy
ld hl,(playerpos)
and a
sbc hl,de
ex de,hl
jr z,_ediedwithscore
ld a,(frames) ; only update every few frames
and 15
cp 15
ret nz
inc (iy+EO_FNO) ; internal frame counter
set 2,h
ld a,(hl) ; undraw at old pos using char from map
res 2,h
ld (hl),a
ld a,(timestop) ; don't move when time stopped
and a
jr nz,{+}
ld e,(iy+EO_MDL) ; move
ld d,(iy+EO_MDH)
add hl,de
+: ex de,hl ; about to wander onto the player's head in the updated position?
ld hl,(playerpos)
and a
sbc hl,de
ex de,hl
jr z,_ediedwithscore
set 2,h
ld a,(hl) ; get character in target square in map
res 2,h
cp $76 ; about to wander off screen?
jr z,_edied
cp 128 ; wall?
jr nz,_testhit
ld a,(timestop) ; don't move when time stopped
and a
jr nz,_eupd
ld e,(iy+EO_MDL) ; move
ld d,(iy+EO_MDH)
xor a
sub e
ld e,a
sbc a,a
sub d
ld d,a
ld (iy+EO_MDL),e ; move
ld (iy+EO_MDH),d
add hl,de
add hl,de
jr _eupd
_testhit:
cp MAP_PIPE
jr nz,_eupd
ld a,(hl) ; the pipe character we collided with on-screen
set 2,h
ld (hl),a ; stuff it in off screen map for undrawing
res 2,h ; it will be erased anyway so why not
ld (playerhit),a ; signal life lost
ld a,7
call AFXPLAY
_eupd:
ld (iy+EO_ADL),l ; store updated position
ld (iy+EO_ADH),h
ld e,(iy+EO_ANL) ; animate
ld d,(iy+EO_ANH)
ld a,(iy+EO_FNO)
and 1
or e
ld e,a
ld a,(de)
ld (hl),a
ret
_ediedwithscore:
ld a,(scoretoadd)
add a,2
ld (scoretoadd),a
ld a,$b8 ; red on
call ledctl
ld a,14
call AFXPLAY
ld hl,BONUSES._eexited ; pre-correct the 'escapee' count
dec (hl) ;
ld hl,BONUSES._eeaten ; omnomnom
inc (hl)
_edied:
ld hl,BONUSES._eexited ; escapees (special bonus #01) count
inc (hl)
dec (iy)
ret
resetenemies:
ld iy,enemydata-ENEMYSIZE
ld b,NENEMIES
-: ld de,ENEMYSIZE
add iy,de
ld a,(iy)
cp 1
jr nz,{+}
dec (iy)
ld l,(iy+EO_ADL)
ld h,(iy+EO_ADH)
set 2,h
ld a,(hl)
res 2,h
ld (hl),a
+: djnz {-}
ret