-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.asm
executable file
·385 lines (355 loc) · 7.14 KB
/
index.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
device zxspectrum48
org 32768
include "routines/definitions.asm"
begin:
jp main
include "routines/sprite.asm"
include "routines/helpers.asm"
include "routines/sound.asm"
include "routines/timer.asm"
main:
; we want a black screen, green default icons.
ld a,%0000100
ld (var_permanent_current_colours),a
xor a
call rom_set_permanent_colors
call rom_clear_screen
call display_instructions
call wait_for_s_key_pressed
game_begin:
call reset_game_variables
call reset_timer
call rom_clear_screen
call display_score_bar
call display_timer_if_necessary
call draw_grass
main_loop:
halt
call timer_event
call display_timer_if_necessary
call has_timer_expired
jr z, time_expired
call delete_player_sprite
call delete_fighter_sprite
call move_player_by_keyboard
call draw_player_sprite
call move_fighter
call draw_fighter_sprite
call detect_soot_key_pressed
call delete_prevous_bullet
call shoot
call detect_player_fighter_collision
jr c, game_over_due_to_crash
call detect_bullet_hit
jr main_loop
game_over_due_to_crash:
call wait_for_s_key_pressed
jp game_begin
time_expired:
ld hl,start_over_message
call show_message
call wait_for_s_key_pressed
jp game_begin
move_fighter:
ld a, (fighter_xcoordinate)
dec a
jr nz, continue_to_move_fighter
call reset_fighter_to_randomized_position
ret
continue_to_move_fighter:
ld (fighter_xcoordinate), a
ret
reset_fighter_to_randomized_position:
call get_random_number
cp 167
jr nc, reset_fighter_to_randomized_position
cp 16
jr c, reset_fighter_to_randomized_position
ld (fighter_ycoordinate), a
ld a, 232
ld (fighter_xcoordinate), a
ret
move_player_by_keyboard
ld a,(player_ycoordinate)
inc a
cp 170
jr nc, already_at_bottom_position
ld (player_ycoordinate),a
already_at_bottom_position:
ld bc,#7ffe
in a,(c)
bit 3, a
jr z, is_n_key_pressed
bit 2, a
jr z, is_m_key_pressed
move_vertically:
ld bc,#fdfe
in a,(c)
bit 0, a
jr z, is_a_key_pressed
ld bc,#fefe
in a,(c)
bit 1, a
jr z, is_z_key_pressed
ret
is_n_key_pressed:
ld a,(player_xcoordinate)
dec a
ret z
ld (player_xcoordinate),a
jp move_vertically
is_m_key_pressed:
ld a,(player_xcoordinate)
inc a
cp 232
ret nc
ld (player_xcoordinate),a
jp move_vertically
is_a_key_pressed:
ld a,(player_ycoordinate)
dec a
dec a
dec a
cp 16
ret c
ld (player_ycoordinate),a
ret
is_z_key_pressed:
ld a,(player_ycoordinate)
inc a
cp 167
ret nc
ld (player_ycoordinate),a
ret
detect_soot_key_pressed:
ld bc,#7ffe
in a,(c)
bit 0, a
jr z, space_key_pressed
ret
space_key_pressed:
ld a, (is_shooting)
cp a, 1
ret z
call output_zap_sound
ld a, (player_xcoordinate)
add a,16
ld (bullet_xcoordinate), a
ld a, (player_ycoordinate)
add a,8
ld (bullet_ycoordinate), a
ld a, 1
ld (is_shooting), a
ret
delete_prevous_bullet:
ld a, (is_shooting)
cp a, 1
ret nz
ld a,(del_bullet_xcoordinate)
ld c,a
ld a, (del_bullet_ycoordinate)
ld b,a
call yx2pix
ld a, 0
ld (de), a
ret
shoot:
ld a, (is_shooting)
cp a, 1
ret nz
ld a,(bullet_xcoordinate)
ld (del_bullet_xcoordinate), a
cp 232
jr c, bullet_stillflying
ld a, 0
ld (is_shooting), a
ret
bullet_stillflying:
ld c,a
ld a,(bullet_ycoordinate)
ld (del_bullet_ycoordinate), a
ld b,a
call yx2pix
ld a, %10101010
ld (de), a
ld a,(bullet_xcoordinate)
add a, 8
ld (bullet_xcoordinate),a
ret
detect_player_fighter_collision:
ld a, (player_ycoordinate)
ld b, a
ld a, (fighter_ycoordinate)
sub b
cp 16
ret nc
ld a, (player_xcoordinate)
ld b, a
ld a, (fighter_xcoordinate)
sub b
cp 20
ret nc
call output_game_over_sound
ld hl,game_over_message
call show_message
ld a, 1
rrc a
ret
detect_bullet_hit:
ld a, (is_shooting)
cp a, 1
ret nz
ld a, (fighter_ycoordinate)
ld b, a
ld a, (del_bullet_ycoordinate)
sub b
cp 16
ret nc
ld a, (fighter_xcoordinate)
ld b, a
ld a, (del_bullet_xcoordinate)
sub b
cp 20
ret nc
; if the player is closer to the end of the screen, gets more score
ld hl, (score)
inc hl
ld a, (player_xcoordinate)
ld e,a
ld d, 0
add hl, de
ld (score), hl
call output_hit_sound
call display_score_bar
call delete_fighter_sprite
call reset_fighter_to_randomized_position
ret
delete_player_sprite:
ld a,(player_xcoordinate)
ld c,a
ld a,(player_ycoordinate)
ld b,a
call delete_sprite
ret
delete_fighter_sprite:
ld a,(fighter_xcoordinate)
ld c,a
ld a,(fighter_ycoordinate)
ld b,a
call delete_sprite
ret;
draw_player_sprite:
ld a,(player_xcoordinate)
ld c,a
ld a,(player_ycoordinate)
ld b,a
ld hl,player_sprite_data0
call draw_sprite
ret
draw_fighter_sprite:
ld a,(fighter_xcoordinate)
ld c,a
ld a,(fighter_ycoordinate)
ld b,a
ld hl,fighter_sprite_data0
call draw_sprite
ret
display_instructions:
ld hl,instructions_message
call show_message
ret
wait_for_s_key_pressed:
ld bc,#fbfe
in a,(c)
bit 0, a
; hidden function Q to quit
jr nz, no_quit
pop bc
ret
no_quit:
ld bc,#fdfe
in a,(c)
bit 1, a
jr nz, wait_for_s_key_pressed
ret
reset_game_variables:
ld a, 0
ld (player_xcoordinate), a
ld (bullet_xcoordinate), a
ld (bullet_ycoordinate), a
ld (del_bullet_xcoordinate), a
ld (del_bullet_ycoordinate), a
ld (is_shooting), a
ld hl, 0
ld (score), hl
ld a, 232
ld (fighter_xcoordinate), a
ld a, 32
ld (fighter_ycoordinate), a
ld a, 166
ld (player_ycoordinate), a
ret
display_timer_if_necessary:
ld hl, (timer)
ld a,l
cp 0
ret nz
call show_timer_bar
ld de, (timer)
ld h,0
ld l,d
call display_num
ret
display_score_bar:
call show_score_bar
ld hl, (score)
call display_num
ret
draw_grass:
ld c,232
ld b, 191 - 8
draw_grass_loop:
ld hl,grass_sprite
push bc
call draw_static_sprite
pop bc
ld a, c
sub 16
ld c,a
jr nc, draw_grass_loop
ld c,0
ld b, 191 - 8
ld hl,grass_sprite
call draw_static_sprite
ret
include "data.asm"
include "sprites.asm"
include "messages.asm"
lenght equ $-begin
code = #af
usr = #c0
load = #ef
clear = #fd
randomize = #f9
org #5c00
baszac db 0,1 ;; line number
dw linlen ;; line length
linzac
db clear,'32768',#0e,0,0
dw 32768
db 0,':'
db load,'"'
codnam ds 10,32
org codnam
db "code"
org codnam+10
db '"',code,':'
db randomize,usr,'32768',#0e,0,0
dw 32768
db 0,13
linlen = $-linzac
baslen = $-baszac
emptytap "game.tap"
savetap "game.tap",basic,"test-game",baszac,baslen,1
savetap "game.tap",code,"code",begin, lenght
SAVESNA "game.sna", begin