-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamemanager.asm
More file actions
671 lines (500 loc) · 10.1 KB
/
gamemanager.asm
File metadata and controls
671 lines (500 loc) · 10.1 KB
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
;
; Gamemanager.asm
; Routines for level setup, end of game handling etc.
;
gamemanager
xor a
ld (v_level), a
call prepare_game
call set_game_controls
gamemaanger_prep_level
call set_print_shadow_screen
call cls
call prepare_level
call display_level
call set_print_main_screen
xor a
ld (v_attr), a
call cls
call copy_shadow_screen_pixels
call fade_in_shadow_screen_attrs
call set_print_main_screen
; Initialises the in game music, which lives in RAM page 1.
ld hl, AY_GAME_TUNE
ld a, 1
call init_music
call restart_music
; Set the initial level status message
ld hl, str_level_begin
ld a, STATUS_LEVEL_START
call display_status_message
call clear_controls
call main_loop
call fade_out_attrs
call mute_music
; Was the game aborted
ld a, (v_game_end_reason)
cp GAME_ABORTED
jr z, gamemanager_end
;check_game_over
cp GAME_OVER
jr nz, check_level_complete
call gamemanager_game_over
jp gamemanager_end
check_level_complete
cp LEVEL_COMPLETE
jr nz, gamemanager_end
call gamemanager_level_complete
ld hl, (v_level)
inc (hl)
jp gamemaanger_prep_level
gamemanager_end
call mute_music
call fade_out_attrs
ret
;
; Handle Game Over scenario.
;
gamemanager_game_over
ld hl, AY_GAMEOVER_TUNE
ld a, 1
call init_music
call restart_music
xor a
ld (v_attr), a
call cls
call set_print_shadow_screen
call cls
call display_game_over_logo
ld bc, 0x100
game_over_wait_keypressed
halt
call scan_keys
jr z, gamemanager_end
dec bc
ld a, b
or c
jr nz, game_over_wait_keypressed
ret
display_game_over_logo
ld hl, img_game_over_logo
ld de, 0x800 + (SHADOW_SCREEN_BYTES * 0x100)
ld bc, 0x800
ldir
ld a, %01000010
ld hl, SHADOW_SCREEN_ATTR * 0x100
ld de, hl
inc de
ld bc, 0x300
ld (hl), a
ldir
call copy_shadow_screen_pixels
call fade_in_attrs
ret
;
; Handle level complete scenario
;
gamemanager_level_complete
ld hl, AY_LEVEL_COMPLETE_TUNE
ld a, 3
call init_music
call restart_music
xor a
ld (v_attr), a
call cls
call set_print_shadow_screen
call cls
call display_level_complete
call set_proportional_font
; Work out our time bonus
ld ix, v_time
ld hl, 0
gamemanager_lvc_calc_time
ld a, (ix)
cp '0'
jr z, gamemanager_lvc_calc_time_2
dec (ix)
ld de, 10
or a
add hl, de
jr gamemanager_lvc_calc_time
gamemanager_lvc_calc_time_2
ld a, (ix+1)
sub '0'
ld e, a
xor a
ld d, a
add hl, de
ld (v_lvc_time_bonus), hl
; Start printing stats
ld hl, str_time_bonus
call print
ld hl, (v_lvc_time_bonus)
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_time_bonus_2
call print
ld hl, str_level_complete_tab
call print
; Calculate time bonus and print it
ld hl, 0
ld bc, 100
ld de, (v_lvc_time_bonus)
gamemanager_lvc_calc_time_bonus
or a
add hl, bc
dec de
ld a, d
or e
jr nz, gamemanager_lvc_calc_time_bonus
ld (v_lvc_time_bonus), hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_wages_earned
call print
ld hl, 150
ld (v_lvc_wages), hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, str_level_complete_tab
call print
ld hl, str_pound
call print
ld hl, v_buffer
call print
call newline
; Did we hit any gnomes?
ld a, (v_gnomes_hit)
cp 0
jr z, gamemanager_lvc_check_flowers
ld hl, str_glue_to_stick_gnomes
call print
xor a
ld h, a
ld a, (v_gnomes_hit)
ld l, a
push hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_glue_to_stick_gnomes_2
ld a, (v_gnomes_hit)
cp 1
jr nz, gamemanager_lvc_check_gnomes_2
ld hl, str_glue_to_stick_gnome_2
gamemanager_lvc_check_gnomes_2
call print
; Calculate cost of hitting gnomes
; Multiply value in bc by 5
pop bc
ld hl, bc
or a
add hl, hl
add hl, hl
add hl, bc
call display_and_subtract_cost
gamemanager_lvc_check_flowers
ld a, (v_flowers_hit)
cp 0
jr z, gamemanager_lvc_check_rover
ld hl, str_flower_cost
call print
xor a
ld b, a
ld a, (v_flowers_hit)
ld c, a
; Calculate cost of hitting flowers
; Again, multiply value in bc by 5
ld hl, bc
or a
add hl, hl
add hl, hl
add hl, bc
call display_and_subtract_cost
; Check it we hit rover(s). This incurs a rather
; more severe financial penalty (as you probably
; don't have a conscience about mowing over a 8x8
; pixel sprite)
gamemanager_lvc_check_rover
ld a, (v_dogs_hit)
cp 0
jr z, gamemanager_lvc_check_lawnmower
ld hl, str_rover_vet_bill
call print
xor a
ld b, a
ld a, (v_dogs_hit)
ld c, a
; Calculate cost of vets bill. £25 per impact.
; First multiply to 32
push bc
ld hl, bc
or a
add hl, hl
add hl, hl
add hl, hl
add hl, hl
add hl, hl
; DE contains x 32 value
ld de, hl
pop hl
or a
add hl, hl
add hl, hl
add hl, hl
; HL now contains value x 8
sub hl, bc
; ... and now x 7.
ex de, hl
; 32 - 7 = 25 :)
or a
sub hl, de
call display_and_subtract_cost
gamemanager_lvc_check_lawnmower
ld a, (v_damage)
cp 0
jr z, gamemanager_lvc_do_totals
ld hl, str_mower_repair
call print
xor a
ld b, a
ld a, (v_damage)
ld c, a
; Mower damage is a far more reasonable
; £5 per damage point.
ld hl, bc
or a
add hl, hl
add hl, hl
add hl, bc
call display_and_subtract_cost
gamemanager_lvc_do_totals
; Work out cash in hand / cash bonus
call newline
ld hl, str_cash_in_hand
call print
ld hl, str_level_complete_tab
call print
ld hl, str_pound
call print
ld hl, (v_lvc_wages)
push hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_cash_bonus
call print
pop hl
push hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_cash_bonus_2
call print
ld hl, str_level_complete_tab
call print
pop hl
ld de, hl
; Cash bonus is 20 x cash in hand
or a
add hl, hl
add hl, hl
add hl, hl
add hl, hl
ex de, hl
add hl, hl
add hl, hl
add hl, de
ld (v_lvc_cash_bonus), hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
call newline
; Conclusion: add cash to time bonus and display it
ld hl, (v_lvc_cash_bonus)
ex de, hl
ld hl, (v_lvc_time_bonus)
or a
add hl, de
ld (v_lvc_total_bonus), hl
push hl
ld hl, str_total_bonus_score
call print
ld hl, str_level_complete_tab
call print
pop hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
ld hl, str_level_complete_any_key
call print
call copy_shadow_screen_pixels
call fade_in_attrs
call set_print_main_screen
call get_key
call fade_out_attrs
call add_bonus_to_score
; Increment current level
ld a, (v_level)
inc a
cp 8
jr nz, gamemanager_game_incomplete
;
; Game complete. Woohoo!
;
call set_print_shadow_screen
call cls
ld hl, img_game_complete
ld de, SHADOW_SCREEN_BYTES * 0x100
ld bc, 0x1000
ldir
ld de, SHADOW_SCREEN_ATTR * 0x100
ld bc, 0x200
ldir
ld hl, str_game_complete
call print
call copy_shadow_screen_pixels
call fade_in_attrs
call set_print_main_screen
call get_key
call fade_out_attrs
; Back to the start. Poor suckers.
xor a
gamemanager_game_incomplete
ld (v_level), a
call mute_music
ret
;
; Displays Level Complete logo on the shadow screen
; ready for fade in.
;
display_level_complete
ld hl, img_level_complete
ld de, SHADOW_SCREEN_BYTES * 0x100
ld bc, 0x800
ldir
ld a, %01000010
ld hl, SHADOW_SCREEN_ATTR * 0x100
ld de, hl
inc de
ld bc, 0x100
ld (hl), a
ldir
ret
;
; Displays and subtracts cost of damage
; (in HL) from wages earned.
;
display_and_subtract_cost
ld a, (v_cheat_mode)
bit 3, a
jr z, display_and_subtract_cost_2
ld hl, 0
display_and_subtract_cost_2
; Save value and print it
push hl
ld hl, str_level_complete_tab
call print
ld hl, str_pound
call print
pop hl
push hl
ld de, v_buffer
call Num2Dec_NoTrail
ld hl, v_buffer
call print
pop de
; Subtract it from wages Earned
ld hl, (v_lvc_wages)
or a
sub hl, de
ld (v_lvc_wages), hl
ret
;
; Adds accrued bonus in v_lvc_total_bonus to the
; score.
; Doing it this was as it's easier to allow the
; game to work and increment in pure ASCII to
; save speed.
;
add_bonus_to_score
ld hl, (v_lvc_total_bonus)
ld a, h
or l
ret z
dec hl
ld (v_lvc_total_bonus), hl
ld hl, v_score + 5
add_bonus_to_score_loop
inc (hl)
ld a, (hl)
cp '9' + 1
jr nz, add_bonus_to_score
ld a, '0'
ld (hl), a
dec hl
jr add_bonus_to_score_loop
prepare_game
xor a
ld (v_level), a
ld a, '0'
ld hl, v_score
ld b, 6
init_score
ld (hl), a
inc hl
djnz init_score
xor a
ld (hl), a
ld (v_pending_score), a
ret
define LVC_TAB 28
str_time_bonus
defb AT, 8, LVC_TAB, INK, 5, BRIGHT, 1, "Time bonus : ", 0
str_time_bonus_2
defb " x 100", 0
str_wages_earned
defb INK, 4, BRIGHT, 1, "\n", TAB, LVC_TAB, "Money earned :", 0
str_glue_to_stick_gnomes
defb "\n", TAB, LVC_TAB, "Glue to stick ", 0
str_glue_to_stick_gnomes_2
defb " gnomes :", 0
str_glue_to_stick_gnome_2
defb " gnome :", 0
str_flower_cost
defb INK, 4, BRIGHT, 1, "\n", TAB, LVC_TAB, "Flower bed repair :", 0
str_rover_vet_bill
defb "\n", TAB, LVC_TAB, "Rover's vet bill : ", 0
str_mower_repair
defb "\n", TAB, LVC_TAB, "Lawnmower repair bill : ", 0
str_cash_in_hand
defb INK, 5, BRIGHT, 1, "\n", TAB, LVC_TAB, "Cash in hand : ", 0
str_cash_bonus
defb INK, 6, BRIGHT, 1, "\n", TAB, LVC_TAB, "Cash bonus : ", 0
str_cash_bonus_2
defb " x 20", 0
str_total_bonus_score
defb INK, 2, BRIGHT, 1, "\n", TAB, LVC_TAB, "Total bonus score : ", 0
str_level_complete_any_key
defb AT, 22, 48, INK, 5, BRIGHT, 1, "Press any key to continue...", 0
str_level_complete_tab
defb TAB, 188, 0
str_pound
defb 0x60, 0
str_game_complete
defb AT, 17, 80, INK, 7, BRIGHT, 1, TEXTBOLD, "Congratulations!", TEXTNORM
defb AT, 19, 12, "You have mown all eight lawns and lived"
defb AT, 20, 12, "to tell the tale."
defb AT, 21, 12, "Unfortunately, time (and grass growth)"
defb AT, 22, 12, "stops for no one..."
str_press_any_key
defb AT, 23, 160, INK, 4, "(press any key)", 0