-
Notifications
You must be signed in to change notification settings - Fork 1
/
display.asm
1760 lines (1496 loc) · 52.1 KB
/
display.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
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; *************************************************************************
; * Initialize the video RAM and machine registers
; *************************************************************************
INIT_DISPLAY
.as
; set the visible display size - 80 x 60
LDA #0
STA BORDER_X_SIZE
LDA #0
STA BORDER_Y_SIZE
; set the border to black
STA BORDER_COLOR_B
STA BORDER_COLOR_R
STA BORDER_COLOR_G
; RESET the keyboard handler
STZ KEYBOARD_SC_TMP
; disable the border
LDA #0
STA BORDER_CTRL_REG
; enable graphics, tiles and sprites display
LDA #Mstr_Ctrl_Graph_Mode_En + Mstr_Ctrl_Bitmap_en
STA MASTER_CTRL_REG_L
LDA #BM_LUT1 | BM_ENABLE
STA BM0_CONTROL_REG
LDA #(<`VSPLASH) - $B0
STA BM0_START_ADDY_H
setal
LDA #0
STA BM0_START_ADDY_L
setas
RTS
RESTART_GAME
.as
LDA #$20
STA BORDER_X_SIZE
; enable the border
LDA #Border_Ctrl_Enable
STA BORDER_CTRL_REG
; enable graphics, tiles and sprites display
LDA #Mstr_Ctrl_Graph_Mode_En + Mstr_Ctrl_TileMap_En + Mstr_Ctrl_Sprite_En ; + Mstr_Ctrl_Text_Mode_En + Mstr_Ctrl_Text_Overlay
STA MASTER_CTRL_REG_L
setal
LDA #0
STA RESET_BOARD
; enable tilemap 1
STA TL1_START_ADDY_H
; set the tilemap window position to 0
LDA #0
STA TL1_WINDOW_X_POS_L
STA TL1_WINDOW_Y_POS_L
; set the columns to 40
LDA #40
STA TL1_TOTAL_X_SIZE_L
; set the rows to 30
LDA #30
STA TL1_TOTAL_Y_SIZE_L
; set the video RAM to B0:2000
LDA #<>VTILE_MAP1
STA TL1_START_ADDY_L
; enable tilemap 0 - display the GAME OVER message
LDA #0
STA TL0_START_ADDY_H
; set the tilemap window position to 0
LDA #0
STA TL0_WINDOW_X_POS_L
STA TL0_WINDOW_Y_POS_L
; set the columns to 40
LDA #40
STA TL0_TOTAL_X_SIZE_L
; set the rows to 30
LDA #30
STA TL0_TOTAL_Y_SIZE_L
; set the video RAM to B0:2000
LDA #<>VTILE_MAP0
STA TL0_START_ADDY_L
LDA #$50
STA SP02_Y_POS_L
LDA #0
STA SCORE
setas
STA SCORE + 2
STA HOME_NEST
; enable tilemap 1
LDA #TILE_Enable + 0 ; the 0 is there to signify LUT0
STA @lTL1_CONTROL_REG
; disable tilemap 0
LDA #0
STA @lTL0_CONTROL_REG
STA DEAD
STA PL_MOVE_UP
STA NEST_UP
STA SP01_CONTROL_REG
; prepare the bee sprite
STA SP02_ADDY_PTR_L
STA SP02_CONTROL_REG
LDA #1
STA SP02_ADDY_PTR_H
LDA #BEE_SPRITE * 4
STA SP02_ADDY_PTR_M
LDA #DEFAULT_LIVES
STA LIVES
LDA #1
STA LEVEL
; enable the non-player sprites
JSR ENABLE_SPRITES_NPC
; initialize the player to the bottom row
JSR INIT_PLAYER
JSR INIT_NPC
JSR SHOW_SCORE_BOARD
JSR SHOW_LEVEL
; reset the timer bar
LDA #0
STA SOF_COUNTER
LDA #$DF ; - joystick in initial state
JSR UPDATE_DISPLAY
RTS
; *************************************************************
; * Setup the sprite registers for the non-player sprites
; *************************************************************
ENABLE_SPRITES_NPC
.as
; now enabled the sprites
; the address of the sprite is based on the game_array
LDX #0 ; X increments in steps of 8
LDY #0 ; Y counts the number of sprites total - 60
LDA #0
; reserve the first 4 sprites
STA @lSP00_CONTROL_REG
STA @lSP01_CONTROL_REG
STA @lSP03_CONTROL_REG
LSP_LOOP
LDA game_array, X ; if the speed is zero skip
BEQ LSP_SKIP_ROW
LDA #0
STA @lSP04_ADDY_PTR_L,X
LDA #(SPRITE_Enable | SPRITE_DEPTH0 | SPRITE_LUT0)
STA @lSP04_CONTROL_REG,X
LDA #1
STA @lSP04_ADDY_PTR_H,X
LDA game_array+6,X ; 0 to 23
ASL A
ASL A
STA @lSP04_ADDY_PTR_M,X
LSP_SKIP_ROW
setal
TXA
CLC
ADC #8
TAX
setas
INY
CPY #NPC_SPRITES
BNE LSP_LOOP
RTS
; *************************************************************
; * Initialize player position
; *************************************************************
INIT_PLAYER
; start at position (100,100)
setal
LDA #<>VFROGS_UP
STA @lSP00_ADDY_PTR_L
LDA #(SPRITE_Enable | SPRITE_DEPTH0 | SPRITE_LUT0)
STA @lSP00_CONTROL_REG
LDA #9 * 32 + 32 ; the middle of the screen
STA PLAYER_X
STA @lSP00_X_POS_L
LDA #15 * 32-16 ; the bottom row
;LDA #9 * 32-16 ; use this to debug the middle line
STA PLAYER_Y
STA @lSP00_Y_POS_L
setas
LDA #(`VFROGS_UP - $B0_0000)
STA @lSP00_ADDY_PTR_H
LDA #0
STA MOVING_CNT
STA MOVING
STA BEE_NEST
STA @l SP02_CONTROL_REG ; hide the bee
LDA #DEFAULT_BEE_TIME/2
STA BEE_TIMER
LDA #DEFAULT_TIMER
STA GTIMER
JSR UPDATE_TIMER_BAR
RTS
; *************************************************************
; * Initialize non-player components, from the game_array
; *************************************************************
INIT_NPC
.as
setal
LDX #0
LDY #0
INIT_NPC_LOOP
LDA game_array,X
BEQ INIT_NPC_SKIP
LDA game_array + 2,X ; X POSITION
STA @lSP04_X_POS_L,X
LDA game_array + 4,X ; Y POSITION
STA @lSP04_Y_POS_L,X
INIT_NPC_SKIP
TXA
CLC
ADC #8
TAX
INY
CPY #NPC_SPRITES
BNE INIT_NPC_LOOP
setas
RTS
; *************************************************************
; * Display the game over/title screen
; * Show the game over tilemap
; *************************************************************
GAME_OVER_DRAW
.as
LDA GAME_OVER
CMP #2
BGE G_O_LOAD_DONE
JSR DRAW_GAME_OVER_MAP
G_O_LOAD_DONE
; check if the fire button was pressed to restart the game
PLA
BIT #$10 ; fire
BNE GO_DONE
LDA #0
STA GAME_OVER
JSR RESTART_GAME
GO_DONE
PLB
RTS
; *************************************************************
; * The function gets called 60 times a second, by the SOF interrupt.
; * A contains the joystick byte - keyboard AWSD mimicks joystick.
; *************************************************************
UPDATE_DISPLAY
.as
PHB
PHA
LDA GAME_OVER ; GAME_OVER=1 signifies the player lost
BNE GAME_OVER_DRAW
; when the player is dead, wait 180 SOF cycles
LDA RESET_BOARD ; wait until RESET_BOARD is zero
BEQ CHECK_DEAD
DEC A
STA RESET_BOARD
BNE NO_UPDATE
CHECK_DEAD
; check if the player is dead
LDA DEAD
BEQ NOT_DEAD
; if the player died, decrease the remaining lives
LDA LIVES
DEC A
STA LIVES
BNE RESET_FROM_DEAD
; set the GAME_OVER
LDA #1
STA GAME_OVER
BRA NO_UPDATE
RESET_FROM_DEAD
LDA #0
STA DEAD
STA PL_MOVE_UP
JSR INIT_PLAYER
JSR SHOW_SCORE_BOARD
NO_UPDATE
PLA
PLB
RTS
NOT_DEAD
LDA NEST_UP
BEQ REG_FLOW
; when a player fills the nest, we wait 3 seconds and then reset the player
LDA #0
STA NEST_UP
JSR INIT_PLAYER
LDA HOME_NEST
CMP #$1F ; go to the next chapter.
BNE REG_FLOW
; the player has filled all the nest - go to the next level and reset the game board
LDA LEVEL
INC A
STA LEVEL
; add 1000 points to the player's score - since the score has 3 bytes, we only add 10 to the middle byte
setal
SED
LDA SCORE+1
CLC
ADC #$10
STA SCORE+1
CLD
setas
JSR SHOW_SCORE_BOARD
LDA #0
STA HOME_NEST
JSR SHOW_LEVEL
REG_FLOW
; count SOF and update the progress bar, if tick has occured
LDA SOF_COUNTER
INC A
CMP #60
BNE REG_FLOW_CONTINUE
; check the bee timer - if timer is zero, change the bee position randomly
JSR CHECK_BEE_TIMER
; update the progress bar
LDA #0
STA SOF_COUNTER
; check the timer
LDA GTIMER
DEC A
BNE GTIMER_UPDATE
; player has run out of time
STA GTIMER
JSR UPDATE_TIMER_BAR
LDA #SPLATT_SPRITE * 4
STA SP00_ADDY_PTR_M
LDA #1
STA SP00_ADDY_PTR_H
PLA
PLB
JMP SET_DEAD ; this JMP calls RTS
GTIMER_UPDATE
STA GTIMER
JSR UPDATE_TIMER_BAR
BRA REG_FLOW_CONTINUE_2
REG_FLOW_CONTINUE
STA SOF_COUNTER
REG_FLOW_CONTINUE_2
JSR UPDATE_LILLY
JSR UPDATE_TURTLE
; check if the frog's tongue is out
LDA TONGUE_POS
BEQ SKIP_TONGUE_UPDATE
JSR UPDATE_TONGUE
PLA ; if the tongue is sticking out, we don't let the player move
BRA JOY_DONE
SKIP_TONGUE_UPDATE
LDA MOVING
BEQ SKIP_TONGUE_BR
JMP ANIMATE_PLAYER
SKIP_TONGUE_BR
LDA #0
STA MOVING_CNT
PLA
BIT #$10 ; fire
BNE JOY_UP
JSR FLICK_TONGUE
BRA JOY_DONE
JOY_UP
BIT #1 ; up
BNE JOY_DOWN
JSR PLAYER_MOVE_UP
LDA #1
STA PL_MOVE_UP
BRA JOY_DONE
JOY_DOWN
BIT #2 ; down
BNE JOY_LEFT
JSR PLAYER_MOVE_DOWN
BRA JOY_DONE
JOY_LEFT
BIT #4 ; left
BNE JOY_RIGHT
JSR PLAYER_MOVE_LEFT
BRA JOY_DONE
JOY_RIGHT
BIT #8 ; right
BNE JOY_DONE
JSR PLAYER_MOVE_RIGHT
BRA JOY_DONE
JOY_DONE
JSR UPDATE_NPC_POSITIONS
LDA MOVING
BNE NO_COLLISION_WHILE_ANIMATING
JSR COLLISION_CHECK
NO_COLLISION_WHILE_ANIMATING
; if the player has moved up without collision, add 10 points.
LDA PL_MOVE_UP
BEQ UD_DONE
LDA DEAD ; if the player is dead, score doesn't increase...
BNE UD_DONE
setal
LDA PLAYER_Y
TAY
SED
LDA SCORE
; add 10 to the score in BCD
CLC
ADC #10
STA SCORE
setas
BCC NOCOL_FINISH
; Add 1 to the hi-byte of the score
CLC
LDA SCORE+2
ADC #1
STA SCORE+2
NOCOL_FINISH
CLD
; reset the score flag
LDA #0
STA PL_MOVE_UP
JSR SHOW_SCORE_BOARD
UD_DONE
PLB
RTS
; *************************************************************
; * The player can move left, right, up and down.
; * When the player is in-flight, moves are not allowed.
; * When the player is in-flight, no collision is computed.
; * Animation occurs ever 4 SOF interrupt move the player sprite
; *************************************************************
ANIMATE_PLAYER
.as
PLA ; we ignore the player's moves
LDA #0
XBA
LDA MOVING_CNT
INC A
BIT #1
BNE ANIM_DONE
STA MOVING_CNT
; READ THE OFFSET
LSR A
;LSR A
TAX
LDA SPRITE_OFFSET,X
PHA
CLC
ADC MOVING
DEC A
; MULTIPLY BY 4
ASL A
ASL A
STA @lSP00_ADDY_PTR_M
TXA
ASL A
TAX
LDA MOVING
CMP #PLAYER_UP + 1
BEQ ANIM_UP_COL
CMP #PLAYER_RIGHT + 1
BEQ ANIM_RIGHT_COL
CMP #PLAYER_LEFT + 1
BEQ ANIM_LEFT_COL
BRA ANIM_DOWN_COL
ANIM_COMPLETE
PLA ; check if the value was 0
BEQ ANIM_COMPLETE_BR
JMP JOY_DONE
ANIM_COMPLETE_BR
; stop the moving
LDA #0
STA MOVING
JMP JOY_DONE
ANIM_DONE
STA MOVING_CNT
JMP JOY_DONE
; *************************************************************
ANIM_UP_COL
setal
LDA PLAYER_Y
SEC
SBC SPRITE_MOVE,X
; check for collisions and out of screen
CMP #80
BCS PMU_DONE
LDA #80
PMU_DONE
STA PLAYER_Y
STA SP00_Y_POS_L
setas
BRA ANIM_COMPLETE
; *************************************************************
ANIM_LEFT_COL
setal
LDA PLAYER_X
SEC
SBC SPRITE_MOVE,X
; check for collisions and out of screen
CMP #64
BCS PML_DONE
LDA #64
PML_DONE
STA PLAYER_X
STA SP00_X_POS_L
setas
BRA ANIM_COMPLETE
; *************************************************************
ANIM_RIGHT_COL
setal
LDA PLAYER_X
CLC
ADC SPRITE_MOVE,X
; check for collisions and out of screen
CMP #640 - 32
BCC PMR_DONE
LDA #640 - 32 ; the lowest position on screen
PMR_DONE
STA PLAYER_X
STA SP00_X_POS_L
setas
BRA ANIM_COMPLETE
; *************************************************************
ANIM_DOWN_COL
setal
LDA PLAYER_Y
CLC
ADC SPRITE_MOVE,X
; check for collisions and out of screen
CMP #464
BCC PMD_DONE
LDA #464 ; the lowest position on screen
PMD_DONE
STA PLAYER_Y
STA SP00_Y_POS_L
setas
JMP ANIM_COMPLETE
; ****************************************************
; * Update non-players sprites
; ****************************************************
UPDATE_NPC_POSITIONS
.as
setal
LDX #0
LDY #0
UNPC_LOOP
LDA game_array,X
BEQ UNP_SKIP_ROW
LDA game_array + 2,X ; X POSITION
CLC
ADC game_array,X ; add the speed
BPL GRT_LFT_MRG
ADC #640-4
BRA LESS_RGT_MRG
GRT_LFT_MRG
CMP #640 - 4
BCC LESS_RGT_MRG
AND #7
LESS_RGT_MRG
STA @lSP04_X_POS_L,X
STA game_array + 2,X
UNP_SKIP_ROW
TXA
CLC
ADC #8
TAX
INY
CPY #NPC_SPRITES
BNE UNPC_LOOP
setas
RTS
; ********************************************
; * Player Movements
; ********************************************
PLAYER_MOVE_DOWN
.as
LDA #PLAYER_DOWN * 4
STA SP00_ADDY_PTR_M
LDA #PLAYER_DOWN + 1
STA MOVING
RTS
; ********************************************
PLAYER_MOVE_UP
.as
LDA #PLAYER_UP * 4
STA SP00_ADDY_PTR_M
LDA #PLAYER_UP + 1
STA MOVING
RTS
; ********************************************
PLAYER_MOVE_RIGHT
.as
LDA #PLAYER_RIGHT * 4
STA SP00_ADDY_PTR_M
LDA #PLAYER_RIGHT + 1
STA MOVING
RTS
; ********************************************
PLAYER_MOVE_LEFT
.as
LDA #PLAYER_LEFT * 4
STA SP00_ADDY_PTR_M
LDA #PLAYER_LEFT + 1
STA MOVING
RTS
; ********************************************
; * Flick the frog's tongue
; * This will used to pick flies remotely.
; ********************************************
INITIAL_DIST = 4
FLICK_TONGUE
.as
LDA #1
STA SP01_CONTROL_REG
STA SP01_ADDY_PTR_H
setal
; turn the frog to UP position
LDA #PLAYER_UP * 1024
STA SP00_ADDY_PTR_L
; enable the sprite
LDA #TONGUE_SPRITE * 1024
STA SP01_ADDY_PTR_L
; X position is the same as the player
LDA PLAYER_X
STA SP01_X_POS_L
; store the animation position
LDA #INITIAL_DIST
STA TONGUE_POS
; Y position is specified by the TONGUE_POS away from the player
LDA PLAYER_Y
SBC TONGUE_POS
STA SP01_Y_POS_L
setas
RTS
; ********************************************
UPDATE_TONGUE
.as
PHB
setdbr <`TONGUE_CTR
INC TONGUE_CTR
LDA TONGUE_CTR
BIT #7 ; only move the tongue every 16 SOF
BNE TONGUE_DONE
CMP #$20
BGE RETRACT_TONGUE
ASL TONGUE_POS
BRA MOVE_TONGUE
RETRACT_TONGUE
LSR TONGUE_POS
MOVE_TONGUE
setal
LDA PLAYER_Y
SBC TONGUE_POS
STA SP01_Y_POS_L
setas
LDA TONGUE_POS
CMP #2
BNE TONGUE_DONE
STZ TONGUE_POS
STZ TONGUE_CTR
; disable the sprite
LDA #0
STA SP01_CONTROL_REG
TONGUE_DONE
PLB
RTS
; *****************************************************************
; * Compare the location of each sprite with the player's position
; * Sprites are 32 x 32 so the math is pretty simple.
; * Collisions occur with cars and buses and with water.
; * Frog can hop on logs.
; *****************************************************************
COLLISION_CHECK
.as
PHB
setdbr <`TONGUE_CTR
setal
LDA PLAYER_Y
CMP #273 ; mid-screen
BLT WATER_COL_BR
JSR STREET_COLLISION
setas
PLB
RTS
WATER_COL_BR
.al
; here do the water collision routine
JSR WATER_COLLISION
setas
PLB
RTS
; *****************************************************************
; * Detect a collision when the player position is greather than 288
; *****************************************************************
STREET_COLLISION
.al
LDX #0
LDY #0
NEXT_STREET_ROW
LDA game_array,X ; if speed is 0, skip the row
BEQ CCS_CONTINUE
LDA game_array+4,X ; read the Y position
CMP PLAYER_Y
BNE CCS_CONTINUE
LDA PLAYER_X
CMP game_array+2,X ; read the X position
BEQ S_COLLISION
BLT CHECK_RIGHT_BOUND
CHECK_LEFT_BOUND
LDA game_array+2,X
ADC #PLAYER_WIDTH+PADDING
CMP PLAYER_X
BGE S_COLLISION ; BCS
BRA CCS_CONTINUE
CHECK_RIGHT_BOUND
ADC #PLAYER_WIDTH + PADDING
CMP game_array+2,X ; read the X position
BGE S_COLLISION
CCS_CONTINUE
TXA
CLC
ADC #8
TAX
INY
CPY #NPC_SPRITES / 2 ; half of the sprites are bottom of the screen
BNE NEXT_STREET_ROW
CC_DONE
setas
RTS
S_COLLISION
.al
PHB
setas
; show splash sprite at player's location
LDA #SPLATT_SPRITE * 4
STA SP00_ADDY_PTR_M
LDA #1
STA SP00_ADDY_PTR_H
PLB
JMP SET_DEAD
; *****************************************************************
; * Detect a collision when the player position is less than 288
; *****************************************************************
WATER_COLLISION
.al
CMP #262
BLT WC_CONTINUE
RTS
WC_CONTINUE
CMP #80
BNE WC_COMPARE_ROWS
JMP HOME_LINE
WC_COMPARE_ROWS
LDX #NPC_SPRITES / 2 * 8 ; we ignore the first 30 sprites in the game array
LDY #0
NEXT_WATER_ROW
; Skip row if speed is 0
LDA game_array,X
BEQ CCW_CONTINUE
;
LDA game_array+4,X ; read the sprite Y position
CMP PLAYER_Y
BNE CCW_CONTINUE
LDA PLAYER_X
CMP game_array+2,X ; read the X position
BEQ FLOAT
BCC CHECK_RIGHT_BOUND_W
CHECK_LEFT_BOUND_W
LDA game_array+2,X
ADC #PLAYER_WIDTH+PADDING
CMP PLAYER_X
BCS FLOAT
BRA CCW_CONTINUE
CHECK_RIGHT_BOUND_W
ADC #PLAYER_WIDTH+PADDING
CMP game_array+2,X ; read the X position
BCS FLOAT
CCW_CONTINUE
TXA
CLC
ADC #8
TAX
INY
CPY #30
BNE NEXT_WATER_ROW
; if none of the sprites match, then the player has fallen in water
JMP W_COLLISION
; the player jumps on logs, lilly pads and turtles
FLOAT
.al
; move the frog with the NPC
CLC
LDA PLAYER_X
ADC game_array,X
CMP #54-PADDING ; added a fuzzy buffer
BCC W_COLLISION
CMP #640-22+PADDING ; added a fuzzy buffer
BCS W_COLLISION
STA PLAYER_X
STA SP00_X_POS_L
RTS
H_COLLISION
.al
setas
; show splash sprite at player's location
LDA #SPLATT_SPRITE * 4
STA SP00_ADDY_PTR_M
LDA #1
STA SP00_ADDY_PTR_H
JMP SET_DEAD
W_COLLISION
.al
setas
; show splash sprite at player's location
LDA #SPLASH_SPRITE * 4
STA SP00_ADDY_PTR_M
LDA #1
STA SP00_ADDY_PTR_H
; set the player to DEAD
SET_DEAD
LDA #1
STA @lDEAD
LDA #THREE_SECS
STA @lRESET_BOARD
RTS
; *****************************************************************
; * At the home line, check if the player is aligned with a free nest.
; * If the nest is free, then the player gets a 200 point bonus.
; * If the nest is not free or the player is not aligned, then death occurs.
; *****************************************************************
HOME_LINE
.al
LDA PLAYER_X
LDX #1 ; nest state
LDY #6*2 ; the first draw tile
CMP #62+32
BLT H_COLLISION
CMP #97+32
BLT HOME_CHECK_VALID
LDX #2 ; nest state
LDY #13*2 ; the first draw tile
CMP #174+32
BLT H_COLLISION
CMP #210+32
BLT HOME_CHECK_VALID
LDX #4 ; nest state
LDY #20*2 ; the first draw tile
CMP #286+32
BLT H_COLLISION
CMP #322+32
BLT HOME_CHECK_VALID
LDX #8 ; nest state
LDY #27*2 ; the first draw tile
CMP #398+32
BLT H_COLLISION
CMP #434+32
BLT HOME_CHECK_VALID
LDX #$10 ; nest state
LDY #34*2 ; the first draw tile