-
Notifications
You must be signed in to change notification settings - Fork 1
/
game.asm
265 lines (198 loc) · 4.36 KB
/
game.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
game:
xor a
ld (level),a
ld (score),a
ld (score+1),a
ld (BONUSES._levelsWithoutADeath),a
ld a,4
ld (lives),a
call displayscoreline
call initsfx
call INPUT._setgame
newlevel:
call displaylevel
call createmap
call initentrances
call initdrone
xor a
ld (BONUSES._deathsPerLevel),a
ld (BONUSES._eexited),a
restart:
ld a,$99
ld (timerv),a
call inittimer
call initialiseenemies
call initenemytimer
call displaymen
ld hl,dfile+INITIAL_OFFS ; set initial position and direction
ld (playerpos),hl
ld a,DOWN ; player's 'last' move was down so correct pipe can be drawn
ld (playerdirn),a
ld hl,retractqueue ; initialise the pipeline retract lifo
ld (retractptr),hl
dec hl
ld a,DOWN
ld (hl),a
xor a
ld (playerhit),a
mainloop:
call framesync
ld a,(fire) ; if fire button has just been released then reset the retract tone
and 3
cp 2
call z,resettone
call updatecloud
call drone
call generateenemy
ld a,(timestop) ; decrement timestop to zero
and a
jr z,{+}
dec a
ld (timestop),a
+: ld a,(frames)
and 63
call z,dotimer ; returns with z set if timer has hit 0
jr z,_die
call updateenemies
ld a,(playerhit)
and a
jr z,_playon
_die:
ld hl,BONUSES._deathsPerLevel
inc (hl)
ld hl,BONUSES._levelsWithoutADeath
ld (hl),0
call loselife
jp nz,restart
ld b,75
call waitframes
ret
_playon:
ld a,(fire) ; retract happens quickly so check every frame
and 1
jr z,_noretract
ld hl,(retractptr) ; because the retract buffer sits on a 256 byte
xor a ; boundary we can use the lsb to tell when it's empty
cp l
jr z,mainloop ; even if we can't retract, jump back
call retract ; retract the head
ld a,(frames)
and 1
call z,retract ; do an extra retract every other frame
ld a,(winchframe) ; update winch animation
inc a
ld (winchframe),a
call showwinch ; so it's about a speed and a half
ld a,(frames)
and 3 ; prepare the z flag
ld a,18 ; set up sound number in case it's time
call z,generatetone
jp mainloop
_noretract:
ld a,(frames) ; only dig every nth frame
and 3 ; could be game speed controller?
cp 3
jp nz,mainloop
ld a,(headchar) ; animate the digging head
xor PIPE_HEAD1 ^ PIPE_HEAD2
ld (headchar),a
ld a,(retractptr) ; pipe length
inc a
jr z,_headupdate ; is 255 so can't move
call tryup ; the tryxxx functions return with z set
jr z,_headupdate ; if that direction was taken
call trydown
jr z,_headupdate
call tryleft
jr z,_headupdate
call tryright
_headupdate:
call showwinch ; animate the winch
ld hl,(playerpos) ; update the digging head
ld a,(headchar)
ld (hl),a
ld a,(scoretoadd) ; any score last frame?
and a
jp z,mainloop
ld c,a ; add score
xor a
ld (scoretoadd),a
ld b,a
call addscore
call checkhi
call lorryfill
call detectdot
jp z,mainloop
; next level
ld a,(BONUSES._deathsPerLevel) ; did player die at all this level?
and a
jr nz,{+}
ld hl,BONUSES._levelsWithoutADeath ; no, so track how many levels we did without dying
inc (hl)
+: ld a,12
call AFXPLAY
call tidyup
call displayBonuses
call levelup
call displaylvl
jp newlevel
;-------------------------------------------------------------------------------
inittimer:
ld a,(timerv)
jr _timerdd
dotimer:
ld a,(timerv)
and a
ret z
sub 1
daa
ld (timerv),a
_timerdd:
push af
and $f0
rrca
rrca
rrca
rrca
add a,ZEROZ+128
ld de,dfile+TIMER_OFFS
ld (de),a
pop af
and $0f
add a,ZEROZ+128
inc de
ld (de),a
ret
;-------------------------------------------------------------------------------
loselife:
ld a,(lives)
cp 1
jr nz,{+}
ld a,13
call AFXPLAY
+: call tidyup
ld a,(lives)
dec a
ld (lives),a
ret
;-------------------------------------------------------------------------------
tidyup:
ld b,4
-: push bc
call framesync
call invertscreen
pop bc
djnz {-}
call resetenemies
-: call framesync
call retract ; retract the head
call retract
call retract
ld a,(winchframe) ; update winch animation
inc a
ld (winchframe),a
call showwinch
ld a,(retractptr)
and a
jr nz,{-}
ret