-
Notifications
You must be signed in to change notification settings - Fork 0
/
enemies.asm
208 lines (166 loc) · 3.93 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
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
.module ENEMIES
;
BIT_INACT = 7 ; busy or dead
NME_STAL = $00
NME_MINE = $10
NME_STATMINE = $20
NME_DEPTH = $30
NME_SHOOT = $40
NME_LASER = $50
NME_BOSSKEY = $60
NME_BOSSDOOR = $70
enemyinitiator:
ld de,(scrollpos) ; find the first enemy on screen
ld hl,enemyidx
add hl,de
ex de,hl
ld b,32 ; and check up to 32 screen x positions from there
_search:
ld a,(de) ; get enemy table index, or ff if no enemy at this x pos
cp $ff
jr z,_nope
push bc
push de
ld h,enemydat / 256 ; make pointer into enemy data table
ld l,a
ld a,(hl) ; get enemy type
bit BIT_INACT,a
call z,_possibly
pop de
pop bc
_nope:
inc de
djnz _search
ret
_possibly:
and $f0 ; isolate type
rrca
rrca
push hl
ld hl,considertable ; index into consideration table
or l
ld l,a
push de
ld de,_considerator+1
ldi
ldi
ld de,_starterator+1
ldi
ldi
pop de
pop hl
_considerator:
call 0
ret nc
_yep:
set BIT_INACT,(hl) ; setting the inactive bit will change the enemy id
ld a,(hl)
and $0f ; isolate Y - also clears carry for SBC below
push af
ld hl,enemyidx ; calculate X
ex de,hl
sbc hl,de
push hl
_starterator:
ld bc,0
call objectafterthis ; returns with hl-> data area
ex de,hl
pop de ; retrieve X
ld (hl),e
inc hl
ld (hl),d
inc hl
pop af ; retrieve Y
ld (hl),a
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; consideration functions - return with carry set to go with
; this object.
;
considerifeffective:
push hl
ld hl,(subcharx)
and a
sbc hl,de ; ifsub x < enemy x, C will be set
pop hl
jr nc,considernever
push hl
push de
ld hl,(subcharx)
ld de,8
add hl,de
and a
sbc hl,de ; if enemy is further right than 8 chars, C will be set
pop de
pop hl
jr c,considernever
; fall in
consideralways:
scf
ret
considernever:
and a
ret
considermine:
ld a,(ocount)
cp 10
ret nc ; 10 or more objects active
push bc
call rng
pop bc
cp 1
ret ; return with C set to choose this enemy
considerstal:
push bc
call rng
pop bc
cp 1
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Return with carry set if x is off screen left
;
cIfOffscreenLeft:
ld l,(iy+OUSER+0)
ld h,(iy+OUSER+1)
ld de,(scrollpos)
and a
sbc hl,de
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Return with carry set if x is to the left of the sub by
; more than 8 characters
;
cIfIneffective:
ld hl,(subcharx)
ld de,8
and a
sbc hl,de
ld e,(iy+OUSER+0)
ld d,(iy+OUSER+1)
ex de,hl
and a
sbc hl,de
ret
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; Return with carry set if x is to the left of the sub
;
cIfIneffectiveHard:
ld hl,(subcharx)
ld e,(iy+OUSER+0)
ld d,(iy+OUSER+1)
ex de,hl
and a
sbc hl,de
ret
.include "e-stalactite.asm"
.include "e-mine.asm"
.include "e-shooter.asm"
.include "e-depth.asm"
.include "e-laser.asm"
.include "e-boss.asm"