/[projet1]/users/twilighte/Stormlord/HeroCode.s
Defence Force logotype

Contents of /users/twilighte/Stormlord/HeroCode.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (show annotations)
Thu Oct 7 20:50:23 2010 UTC (8 years, 5 months ago) by dbug
File size: 22637 byte(s)
Added Stormlord
1 ;HeroCode.s
2 ;X 128 Resign Level
3 ;F 64 Shoot
4 ;L 32 Left
5 ;R 16 Right
6 ;U 8 Jump
7 ;D 4
8
9 HeroNPCCollisionDetected
10 lsr
11 lsr
12 lsr
13 lsr
14 tax
15
16 ;Is Bonus level Fairy Collision?
17 lda MapX
18 cmp #237
19 beq HeroControlContinue
20
21 dex
22
23 ;Is NPC EggWasp?
24 lda NPC_Activity,x
25 cmp #NPCA_EGGWASP
26 .(
27 bne skip1
28
29 ;Is NPC still in Egg or Hatch phase?
30 ;It seems these NPC's are just too difficult to get passed
31 lda NPC_Progress,x
32 bpl HeroControlContinue
33 jmp DeathSequence
34
35 skip1 ;Is NPC raindrop?
36 cmp #NPCA_RAINDROP
37 bne skip2
38
39 ;Is Hero holding the Umbrella?
40 lda HeroHolding
41 cmp #OBJECT_UMBRELLA
42 beq HeroControlContinue
43
44 skip2 jmp DeathSequence
45 .)
46
47 HeroControl
48 ;Check Hero collision with NPC's here
49 ;The hero is 4x24 so to give player the benefit of the doubt we'll only detect NPC's
50 ;in centre two bytes. For height we'll also only read on centre 2 bytes.
51 lda HeroY
52 clc
53 adc #6
54 tay
55 lda HeroX
56 adc #1
57 adc CollisionMapYLOCL-30,y
58 sta cmap
59 lda CollisionMapYLOCH-30,y
60 adc #00
61 sta cmap+1
62 ldx #3
63 .(
64 loop1 ldy HeroOffsetsInCollisionMap,x
65 lda (cmap),y
66 and #$F0
67 beq skip1
68 cmp #$D0
69 bcc HeroNPCCollisionDetected
70 skip1 dex
71 bpl loop1
72 .)
73 HeroControlContinue
74 lda JumpPhase
75 bne DealWithJumpMoves
76 ;Ground check
77 jsr CheckBelowInCollisionMap
78 .(
79 bcs skip1
80
81 ;Falling..
82 jsr DeleteHero
83 ;When falling Synchronise y position to 1 6th then fall every 6 pixels
84 lda #4
85 sta InternalFallCount
86 loop1 dec InternalFallCount
87 beq skip2
88 lda HeroY
89 clc
90 adc #2
91 ora #1 ;Allign to blue head, red arms
92 sta HeroY
93 cmp #$70
94 bcc skip4
95 jmp DeathSequence
96 skip4 jsr CheckBelowInCollisionMap
97 bcc loop1
98 skip2
99 jsr PlotHero
100 ;If Falling then avoid jumping again
101 jmp skip3
102
103 skip1 lda KeyRegister
104 and #CTRL_UP
105 beq skip3
106 ;Don't allow jump whilst jumping
107 lda JumpPhase
108 bne skip3
109 jsr JumpUp
110
111 skip3 lda KeyRegister
112 .)
113 and #CTRL_LEFT
114 .(
115 beq skip1
116 jsr MoveLeft
117 skip1 lda KeyRegister
118 .)
119 and #CTRL_RIGHT
120 .(
121 beq skip1
122 jsr MoveRight
123 skip1 lda KeyRegister
124 .)
125 and #CTRL_FIRE
126 .(
127 beq skip1
128 jmp HeroFire
129 skip1 lda FirePressedPeriod
130 beq skip2
131 cmp #16
132 bcs skip4
133 ;Don't spawn Orb if on fairy screen
134 lda MapX
135 cmp #237
136 beq skip4
137 jsr SpawnOrb
138 skip4 lda #00
139 sta FirePressedPeriod
140 skip2 rts
141 .)
142
143 DealWithJumpMoves
144 ;First control Heroes Y pos
145 jsr DeleteHero
146 lda HeroY
147 clc
148 adc JumpStep
149 ora #1
150 .(
151 sta vector1+1
152 tay
153 ldx HeroX
154 jsr CheckHorizontalsInCollisionMap
155 bcs StopJump
156 vector1 lda #00
157
158 ;Prevent jumping beyond top of screen
159 cmp #30
160 bcc StopJump
161 sta HeroY
162 inc JumpStep
163 bmi Rising
164
165 ;Falling
166 jsr CheckBelowInCollisionMap
167 bcc skip3
168
169 ;Synchronise hero to platform just landed on
170 loop9 dec HeroY
171 jsr CheckBelowInCollisionMap
172 bcs loop9
173
174 StopJump lda #00
175 sta JumpPhase
176 ; jmp skip1
177 skip3
178 Rising
179 ;Whilst airbourne permit fire, left and right
180 lda KeyRegister
181 and #CTRL_LEFT
182 beq skip2
183 jsr MoveLeft
184 skip2 lda KeyRegister
185 and #CTRL_RIGHT
186 beq skip1
187 jsr MoveRight
188 ; jmp PlotHero
189 skip1
190 .)
191 lda KeyRegister
192 and #CTRL_FIRE
193 .(
194 beq skip1
195 jsr HeroFire
196 skip1 lda FirePressedPeriod
197 beq skip2
198 cmp #16
199 bcs skip4
200 ;Don't spawn Orb if on fairy screen
201 lda MapX
202 cmp #237
203 beq skip4
204 jsr SpawnOrb
205 skip4 lda #00
206 sta FirePressedPeriod
207 skip2 rts
208 .)
209
210
211 JumpStep .byt 0
212 JumpPhase .byt 0
213
214 MoveLeft
215 lda HeroX
216 cmp #2
217 .(
218 bcc skip3
219
220 jsr CheckLeftInCollisionMap
221 bcs skip1
222
223 lda ObjectSwapped
224 beq skip5
225 ;If the object was swapped and the hero was facing right(8) then reset ObjectSwapped
226 lda SwappedDirection
227 beq skip5
228 lda #00
229 sta ObjectSwapped
230 skip5 lda HeroFrame
231 and #7
232 clc
233 adc #1
234 cmp #6
235 bcc skip2
236 lda #00
237 skip2 ora #8
238 sta HeroFrame
239 php
240 tax
241 lda HeroGraphicStep,x
242 beq NoByteMovement
243 jsr DeleteHero
244 NoByteMovement
245 ldx HeroFrame
246 plp
247 lda HeroX
248 adc HeroGraphicStep,x
249 sta HeroX
250 ;Trigger Footstep SFX
251 jsr CheckFootDown
252 jsr PlotHero
253 skip1 rts
254 skip3 jmp ExitLeft
255 .)
256
257 MoveRight
258 lda HeroX
259 cmp #35
260 .(
261 bcs skip4
262
263 jsr CheckRightInCollisionMap
264 bcs skip1
265
266 lda ObjectSwapped
267 beq skip5
268 ;If the object was swapped and the hero was facing left(0) then reset ObjectSwapped
269 lda SwappedDirection
270 bne skip5
271 lda #00
272 sta ObjectSwapped
273 skip5 lda HeroFrame
274 clc
275 adc #1
276 cmp #6
277 bcc skip2
278 lda #00
279 skip2 sta HeroFrame
280 tax
281 lda HeroX
282 adc HeroGraphicStep,x
283 cmp HeroX
284 beq skip3
285 pha
286 jsr DeleteHero
287 pla
288 skip3 sta HeroX
289 ;Trigger Footstep SFX
290 jsr CheckFootDown
291 jsr PlotHero
292 skip1 rts
293 skip4 jmp ExitRight
294 .)
295
296 CheckFootDown
297 jsr CheckBelowInCollisionMap
298 .(
299 bcc skip1
300
301 lda JumpPhase
302 bne skip1
303 lda HeroFrame
304 and #7
305 beq FootDown
306 cmp #3
307 bne skip1
308 FootDown lda #SFX_FOOTSTEP
309 jsr KickSFX
310 skip1 rts
311 .)
312
313 ;We use a 2's compliment number to perform the jump height curve
314 ;Setting it to 240 then incrementing in steps of 2
315 JumpUp
316 ;Initialise jump with range which depends if hero posesses the boots
317 ;04 Object 1 Key
318 ;05 Object 2 Honey
319 ;06 Object 3 Umbrella
320 ;07 Object 4 Boots
321 ldy #247 ;Default jump height
322 lda HeroHolding
323 cmp #7
324 .(
325 bne skip1
326 ldy #244
327 skip1 sty JumpStep
328 .)
329 lda #1
330 sta JumpPhase
331 rts
332
333 HeroFire ;Hero Fire is based on the length of time FIRE is held down
334 ;Short Press - Fire orb
335 ;Long Press - Fire Sword
336 lda FirePressedPeriod
337 cmp #FIREPERIOD4SWORD
338 .(
339 bcs skip2
340 inc FirePressedPeriod
341 skip1 rts
342 skip2 ;Is Hero on bonus Fairy bit?
343 lda MapX
344 cmp #237
345 bne skip3
346 jsr SpawnHeart
347 jmp skip4
348 skip3 jsr SpawnSword
349 skip4 lda #00
350 sta FirePressedPeriod
351 rts
352 .)
353
354
355 CheckBelowInCollisionMap
356 lda #128
357 sta LastSafeX
358 ldx HeroX
359 lda HeroY
360 clc
361 adc #24
362 tay
363 jsr CheckHorizontalsInCollisionMap
364 lda LastSafeX
365 .(
366 bmi skip1
367 sta ReEntryPointX
368 lda MapX
369 sta ReEntryPointMapX
370 lda HeroY
371 sta ReEntryPointY
372 skip1 rts
373 .)
374 LastSafeX .byt 128
375 ReEntryPointX .byt 20
376 ReEntryPointMapX .byt 0
377 ReEntryPointY .byt 0
378
379 ;CheckAboveInCollisionMap
380 ; ldx HeroX
381 ; lda HeroY
382 ; sec
383 ; sbc #6
384 ; tay
385
386 CheckHorizontalsInCollisionMap
387 cpy #30
388 .(
389 bcc skip3
390 txa
391 clc
392 adc CollisionMapYLOCL-30,y
393 sta cmap
394 lda CollisionMapYLOCH-30,y
395 adc #00
396 sta cmap+1
397 sec
398 ldy #02
399 loop1 lda (cmap),y
400 and #15
401 bne skip1
402 dey
403 bne loop1
404 skip1 cmp #1
405 bcc skip2
406 jsr ProcessCollision
407 ;Also check if on temporary ledge or Triffid
408
409 skip3 sec
410 skip2 rts
411 .)
412
413
414 CheckRightInCollisionMap
415 lda HeroX
416 clc
417 adc #3
418 jmp CheckVerticalsInCollisionMap
419 CheckLeftInCollisionMap
420 lda HeroX
421 clc
422 CheckVerticalsInCollisionMap
423 ldy HeroY
424 adc CollisionMapYLOCL-30,y
425 sta cmap
426 lda CollisionMapYLOCH-30,y
427 adc #00
428 sta cmap+1
429 sec
430 ldy #00
431 lda (cmap),y
432 .(
433 and #15
434 bne skip1
435
436 ldy #40
437 lda (cmap),y
438 and #15
439 bne skip1
440
441 ldy #80
442 lda (cmap),y
443 and #15
444 bne skip1
445
446 ldy #120
447 lda (cmap),y
448 and #15
449 skip1 cmp #1
450 bcc skip2
451 jsr ProcessCollision
452 sec
453 skip2 rts
454 .)
455
456 ;B0-3 Static Collisions
457 ; 00 Background
458 ; 01 Wall/Surface/Solid
459 ; 02 Death(Flames)
460 ; 03 Temporary Ledge(Blue)
461 ; 04 Object 1 Key
462 ; 05 Object 2 Honey
463 ; 06 Object 3 Umbrella
464 ; 07 Object 4 Boots
465 ; 08 Fairy
466 ; 09 Door
467 ; 10 Trampolene
468 ; 11-15 -
469 ;B4-7 Sprite Collisions
470 ; 00 Background
471 ; 01-0C NPC Index
472 ; 0D Hero Orb
473 ; 0E Hero Sword
474 ; 0F -
475 ProcessCollision ;Collision in A
476 ;Is Hero at left border?
477 ldx HeroX
478 cpx #2
479 .(
480 bcs skip1
481 jmp ExitLeft
482
483 skip1 ;Is Hero at Right Border
484 cpx #35
485 bcc skip2
486 jmp ExitRight
487
488 skip2 ;Are we on Bonus level?
489 ldy MapX
490 cpy #237
491 bne skip11
492 ;Was collision with Tear?
493 cmp #BCKC_TEARS
494 bcs skip10
495
496 skip11 ;Was collision with Death?
497 cmp #BCKC_DEATH
498 bne skip3
499
500 jmp DeathSequence
501
502 skip3 ;Was collision with Temporary Ledge?
503 cmp #BCKC_ICELEDGE
504 bne skip8
505 jmp ActivateLedgeDestruction
506
507 skip8 ;Was collision with solid?
508 bcs skip9
509 ;If solid then mark this position as re-entry point after death
510 lda HeroX
511 sta LastSafeX
512 jmp skip4
513 skip9 ;Was collision with Object?
514 cmp #BCKC_FAIRY
515 bcs skip5
516 jmp SwapObject
517
518 skip5 ;Was collision with Fairy?
519 bne skip6
520 jmp FreeFairy
521
522 skip6 ;Was collision with Door?
523 cmp #BCKC_DOOR
524 bne skip7
525 jmp CheckDoor
526
527 skip7 ;Was collision with trampolene?
528 cmp #BCKC_TRAMPOLENE
529 bne skip4
530 jmp HitTrampolene
531
532 skip4 rts
533
534 skip10 ;Found tear
535 .)
536 ;Calculate NPC Index
537 sec
538 sbc #4
539 tax
540
541 RemoveTear
542 ;Delete Old Frame
543 ldy NPC_ScreenY,x
544 lda NPC_ScreenX,x
545 jsr RecalcScreen
546 lda #NPCF_RAINDROP ;3x8
547 sta SpriteFrame
548 jsr RestoreSpriteBG
549
550 ;Remove from collision map
551 ldy NPC_ScreenX,x
552 lda #0
553 sta CollisionMap+40*14,y
554
555 ;Destroy NPC
556 jsr DestroyNPC
557
558 ;Award Life, score and sfx
559 lda HeroLives
560 cmp #9
561 .(
562 bcs skip1
563 inc HeroLives
564 jsr DisplayLives
565 skip1
566 .)
567 ; lda #
568 ; jsr KickSFX
569
570 lda #$75
571 jsr AddScore
572 jmp DisplayScore
573
574
575 ExitLeft
576 lda MapX
577 .(
578 beq skip1
579 sec
580 sbc #14
581 sta MapX
582
583 ; bne skip998
584 ;skip999 nop
585 ; jmp skip999
586 ;skip998
587
588 ; jsr ClearCollisionMap
589 ; sec
590 jsr DrawMap
591 ; jsr CheckRepositionBees
592 ; jsr GenerateCollisionMap
593 ;Reposition Hero to opposite side of screen
594 lda #29
595 sta HeroX
596 lda #00
597 sta JumpPhase
598 lda #255
599 sta UltimateProjectile
600 jmp PlotHero
601 skip1 rts
602 .)
603
604
605 ExitRight
606 lda MapX
607 cmp #238
608 .(
609 bcs skip1
610 adc #14
611 sta MapX
612 ; jsr ClearCollisionMap
613 ; sec
614 jsr DrawMap
615 ; jsr CheckRepositionBees
616 ; jsr GenerateCollisionMap
617 ;Reposition Hero to opposite side of screen
618 lda #7
619 sta HeroX
620 lda #00
621 sta JumpPhase
622 lda #255
623 sta UltimateProjectile
624 jmp PlotHero
625 skip1 rts
626 .)
627
628 CheckRepositionBees
629 ;Was the honeypot found?
630 lda HoneypotPresent
631 .(
632 beq skip1
633 ;Are their bees on this screen?
634 lda MapX
635 cmp #70
636 beq skip2
637 cmp #168
638 bne skip1
639 skip2 ;Transfer Object_X and Object_Y to beeorigins
640 ldx HoneypotSOS
641 lda Object_X,x
642 asl
643 sta vector1+1
644 asl
645 vector1 adc #00
646 sta BeeOriginX
647 lda Object_Y,x
648 clc
649 adc #24
650 sta BeeOriginY
651 skip1 rts
652 .)
653
654 ActivateLedgeDestruction
655 rts
656
657
658
659 SwapObject
660 ;Match object with Recorded one for this screen
661 ldx ObjectIndex
662 .(
663 loop1 cmp Object_CollisionValue,x
664 beq skip1
665 dex
666 bpl loop1
667 ;Report Error
668 ; lda #17
669 ; sta $BF68
670 rts
671 skip1
672 .)
673 ;Fetch map location for this object
674 lda Object_MapLo,x
675 sta map
676 lda Object_MapHi,x
677 sta map+1
678 stx ReservedSOBIndex
679
680 ;Record object on screen (4-7)
681 lda Object_CollisionValue,x
682 sta ThisOneIsToHold
683
684 ;Does Hero already hold an object?
685 ldy HeroHolding
686 .(
687 bmi skip2
688
689 ;We need to make sure this swapping only occurs once!!
690 lda ObjectSwapped
691 beq skip5
692 rts
693
694 skip5 ;Object not swapped before, so mark as swapped and store Current hero dir
695 inc ObjectSwapped
696 lda HeroFrame
697 and #8
698 sta SwappedDirection
699
700 ;Place held item in map
701 lda ObjectsMapCode-4,y
702 ; tax
703 ldy #00
704 sta (map),y
705 iny
706 clc
707 adc #1
708 sta (map),y
709
710 ldy HeroHolding
711 lda ObjectSFX-4,y
712 jsr KickSFX
713
714 ;Is object placed on map the honeypot?
715 lda HeroHolding
716 cmp #BCKC_OBJECTHONEY
717 bne skip4
718 ;Does this screen contain bees?
719 lda BeesPresentHere
720 beq skip4
721 ;Now move the bees to this honeypot
722 jsr InitiateBeesJourney
723
724 skip4 ;Swap object
725 ldx HeroHolding
726 ;This is a collision value so we need to change back to a blockid
727 ldy ObjectsMapCode-4,x
728 sty Object2Plot
729 iny
730 sty Object2Plot+1
731
732 ;Object must also be swapped in Object_ tables
733 lda ObjectsMapCode-4,x
734 ldy ReservedSOBIndex
735 sta Object_BlockID,y
736 txa
737 sta Object_CollisionValue,y
738
739 jmp skip3
740
741 skip2 ;Hero was not holding an object
742 lda #00
743 sta Object2Plot
744 sta Object2Plot+1
745
746 ;remove object from map
747 lda #00
748 tay
749 sta (map),y
750 iny
751 sta (map),y
752
753 jsr skip3
754
755 ;Object tables must be updated and shrunk
756 ldx ReservedSOBIndex
757 jmp RemoveObjectFromList
758
759 skip3
760 ldx ThisOneIsToHold
761 lda ObjectSFX-4,x
762 jsr KickSFX
763
764 ;Remove or swap Object from screen 2x1
765 ldx #01
766
767 loop1 stx TempX
768 ldy ReservedSOBIndex
769 lda Object_Y,y
770 clc
771 adc ObjectDeletionYOffset,x
772 sta dm_CursorY
773 lda Object_X,y
774 clc
775 adc ObjectDeletionXOffset,x
776 sta dm_CursorX
777 lda Object2Plot,x
778 sta MomentaryBlock
779 jsr PlotBlock2Screen
780 jsr PlotBlock2BGBuff
781 jsr PlotBlock2CMAP
782 ldx TempX
783 dex
784 bpl loop1
785
786 skip1 ;Place Map item in pocket
787 .)
788 lda ThisOneIsToHold
789 sta HeroHolding
790
791 ;Update score
792 lda #$05
793 jsr AddScore
794 jsr DisplayScore
795
796 ;Update Held Object Display in Score panel
797 jmp DisplayHeldObject
798
799 InitiateBeesJourney
800 ;Calculate bees destination x/y
801 lda Object_X,x
802 jsr Mult6
803 sta BeesDestinationX
804 lda Object_Y,x
805 jsr Mult6
806 clc
807 adc #24
808 sta BeesDestinationY
809 lda #1
810 sta BeeTravellingFlag
811 rts
812
813 CheckDoor ;Does Hero have a key?
814 lda HeroHolding
815 cmp #4
816 .(
817 bne skip2
818
819 ;Locate Door
820 lda #9
821 ldx ObjectIndex
822 loop1 cmp Object_CollisionValue,x
823 beq skip1
824 dex
825 bpl loop1
826 ;Report Error
827 ; lda #18
828 ; sta $BF68
829 rts
830
831 skip1 lda #SFX_OPENDOOR
832 jsr KickSFX
833 ;Remove door from map(2x2)
834 stx Purging_ObjectIndex
835 lda Object_MapLo,x
836 sta map
837 lda Object_MapHi,x
838 sta map+1
839 lda #00
840 tay
841 sta (map),y
842 iny
843 sta (map),y
844 inc map+1
845 sta (map),y
846 dey
847 sta (map),y
848
849 ;Remove Held key
850 lda #255
851 sta HeroHolding
852
853 ;Wipe key from score panel
854 jsr EraseDisplayedObject
855 ; lda #<$A000+24+154*40
856 ; sta screen
857 ; lda #>$A000+24+154*40
858 ; sta screen+1
859 ; jsr EraseBlock
860 ; lda #<$A000+26+154*40
861 ; sta screen
862 ; lda #>$A000+26+154*40
863 ; sta screen+1
864 ; jsr EraseBlock
865
866 ;Refresh screen, bgbuff and collision map
867 jsr Remove2x2Blocks
868
869 ;Add score
870 lda #$50
871 jsr AddScore
872 jsr DisplayScore
873
874 ;Refresh Hero
875 jsr PlotHero
876 skip2 rts
877 .)
878
879 FreeFairy
880 ;Locate Fairy
881 lda #8
882 ldx ObjectIndex
883 .(
884 loop1 cmp Object_CollisionValue,x
885 beq skip1
886 dex
887 bpl loop1
888 ;Report Error
889 ; lda #19
890 ; sta $BF68
891 rts
892
893 skip1 ;Remove Fairy from map(2x2)
894 .)
895 lda #SFX_COLLECTFAIRY
896 jsr KickSFX
897
898 stx Purging_ObjectIndex
899 lda Object_MapLo,x
900 sta map
901 lda Object_MapHi,x
902 sta map+1
903 lda #00
904 tay
905 sta (map),y
906 iny
907 sta (map),y
908 inc map+1
909 sta (map),y
910 dey
911 sta (map),y
912
913 ;Add Fairy to acquired
914 inc HeroCapturedFairies
915
916 ;Display in score panel
917 jsr DisplayCapturedFairies
918
919 ;We should branch here if all the fairies have been freed
920 lda HeroCapturedFairies
921 cmp HeroRequiredFairies
922 .(
923 bcc skip1
924
925 ;For bonus level, act like trampolene with MapX destination 237 in Trampolene tables
926 jsr EraseDisplayedObject
927 jmp HitTrampolene
928
929 skip1 ;Refresh screen, bgbuff and collision map
930 .)
931 jsr Remove2x2Blocks
932
933 ;Add score
934 lda #$75
935 jsr AddScore
936 jsr DisplayScore
937
938 ;Refresh Hero
939 jmp PlotHero
940
941 Remove2x2Blocks
942 ;Remove Fairy from screen 2x2
943 ldx #03
944 .(
945 loop1 stx TempX
946 ldy Purging_ObjectIndex
947 lda Object_Y,y
948 clc
949 adc ObjectDeletionYOffset,x
950 sta dm_CursorY
951 lda Object_X,y
952 clc
953 adc ObjectDeletionXOffset,x
954 sta dm_CursorX
955 lda #00
956 sta MomentaryBlock
957 jsr PlotBlock2Screen
958 jsr PlotBlock2BGBuff
959 jsr PlotBlock2CMAP
960 ldx TempX
961 dex
962 bpl loop1
963 .)
964 ;Remove Fairy from Object List
965 ldx Purging_ObjectIndex
966 jmp RemoveObjectFromList
967
968
969
970 ;Remove object x from Object_ tables and shrink
971 RemoveObjectFromList
972 ;Is x same as Count-1?
973 cpx ObjectIndex
974
975 ;If it is then just shrink
976 .(
977 beq skip1
978
979 ;Transfer Object_ tables from x
980 ldy ObjectIndex
981 lda Object_X,y
982 sta Object_X,x
983 lda Object_Y,y
984 sta Object_Y,x
985 lda Object_MapLo,y
986 sta Object_MapLo,x
987 lda Object_MapHi,y
988 sta Object_MapHi,x
989 lda Object_BlockID,y
990 sta Object_BlockID,x
991 lda Object_CollisionValue,y
992 sta Object_CollisionValue,x
993
994 skip1 ;Shrink List
995 .)
996 dec ObjectIndex
997 rts
998
999
1000
1001 ObjectDeletionXOffset
1002 .byt 0,2,0,2
1003 ObjectDeletionYOffset
1004 .byt 0,0,2,2
1005 TempX .byt 0
1006 Purging_ObjectIndex .byt 0
1007
1008 HitTrampolene
1009 lda #SFX_USETRAMPOLENE
1010 jsr KickSFX
1011 ;If the trampolene is being called because the hero has all the fairies
1012 ;we'll need to do things a bit different
1013 lda HeroCapturedFairies
1014 cmp HeroRequiredFairies
1015 .(
1016 bne skip6
1017 ;In this scenario the destination is always 237
1018 ;Set trampolene id to 19 and write to tables
1019 ldx #19
1020 lda #237
1021 sta TrampolenesEndMapX,x
1022 lda #20
1023 sta TrampolenesEndHeroX,x
1024 jmp skip5
1025 skip6 ;Find out destination of trampolene (5 on level 0)
1026 ldx #0
1027 loop1 lda TrampolenesLevelID,x
1028 bmi skip4
1029 cmp LevelID
1030 bne skip1
1031 lda TrampolenesStartMapX,x
1032 cmp MapX
1033 beq skip2
1034 skip1 inx
1035 jmp loop1
1036 skip4 rts
1037 skip2 ;If the Fairy was collected from the place this trampolene took the hero we should
1038 ;disable the trampolene here, though we don't currently
1039
1040 lda HeroFrame
1041 ldy TrampolenesEndMapX,x
1042
1043 skip5 ;Decide on direction the hero should face
1044 cpy MapX
1045 and #7
1046 bcs skip3
1047 ora #8
1048 skip3 sta HeroFrame
1049 .)
1050 stx ThisTrampolenesID
1051
1052 ;Raise hero to top of screen
1053 .(
1054 loop1 jsr DeleteHero
1055
1056 lda HeroY
1057 sec
1058 sbc #6
1059 ora #1
1060 sta HeroY
1061
1062 cmp #36
1063 bcc HeroAtTop
1064
1065 jsr PlotHero
1066
1067 ;Delay
1068 jsr SpeedDampener
1069
1070 jmp loop1
1071 .)
1072
1073 HeroAtTop ;Clear screen
1074 jsr ClearScreen
1075
1076 ;Set hero to bottom of screen
1077 lda #103
1078 sta HeroY
1079
1080 ;Now entering parralax starfield phase - Calculate difference in mapX's
1081 ldx ThisTrampolenesID
1082 lda TrampolenesEndMapX,x
1083 cmp MapX
1084 .(
1085 bcc skip2
1086 sbc MapX
1087 ldy #STARFIELD_EAST
1088 jmp skip1
1089 skip2 ldy #STARFIELD_WEST
1090 lda MapX
1091 sbc TrampolenesEndMapX,x
1092 skip1 asl
1093 sta StarfieldDistance
1094 .)
1095 sty StarfieldDirection
1096
1097 ;Move Hero to centre stage
1098 lda #20
1099 sta HeroX
1100
1101 ;Setup Parralax scrolling
1102 ldx #99
1103 .(
1104 loop1 ;Randomise X
1105 jsr GetRandomNumber
1106
1107 ;Ensure X is no wider than 232
1108 cmp #232
1109 bcc skip1
1110 sbc #232
1111
1112 skip1 ;Add 8 to avoid ink column
1113 clc
1114 adc #8
1115 sta StarfieldX,x
1116
1117 ;Randomise Y
1118 jsr GetRandomNumber
1119
1120 ;Ensure Y is no taller than 108
1121 and #127
1122 cmp #108
1123 bcc skip2
1124 sbc #108
1125
1126 skip2 ;Add 30 to bring into screen bounds
1127 clc
1128 adc #30
1129 sta StarfieldY,x
1130
1131 ;Randomise step(Defines number of layers)
1132 ;Step is 2's compliment to allow same parralax routine for both left and right scrolls
1133 ;So for moving right steps should be from 1 to 8 and for Left from 248-255
1134 jsr GetRandomNumber
1135 and #7
1136 clc
1137 adc StarfieldDirection ;Add either 1(Right) or 248(Left)
1138 sta StarfieldStep,x
1139
1140 dex
1141 bpl loop1
1142 .)
1143 ;Kick starfield sfx
1144 lda #SFX_STARFIELD
1145 jsr KickSFX
1146
1147 ;Process starfield
1148 .(
1149 loop2 ldx #99
1150
1151 loop1 ;Delete pixel
1152 ldy StarfieldX,x
1153 lda BitMap,y
1154 eor #63+64
1155 sta sfTemp01
1156 lda XLOC,y
1157 ldy StarfieldY,x
1158 jsr RecalcScreen
1159 ldy #00
1160 lda (screen),y
1161 and sfTemp01
1162 sta (screen),y
1163
1164 ;Move star
1165 lda StarfieldStep,x
1166 bmi MovingStarfieldLeft
1167 MovingStarfieldRight
1168 adc StarfieldX,x
1169 cmp #240
1170 bcc skip1
1171 lda #8
1172 jmp skip1
1173 MovingStarfieldLeft
1174 adc StarfieldX,x
1175 cmp #8
1176 bcs skip1
1177 lda #239
1178 skip1 sta StarfieldX,x
1179
1180 ;Plot star
1181 tay ;ldy StarfieldX,x
1182 lda BitMap,y
1183 sta sfTemp01
1184 lda XLOC,y
1185 ldy StarfieldY,x
1186 jsr RecalcScreen
1187 ldy #00
1188 lda (screen),y
1189 ora sfTemp01
1190 sta (screen),y
1191
1192 dex
1193 bpl loop1
1194
1195
1196 ;Delete hero only if descending
1197 lda StarfieldDistance
1198 cmp #10
1199 bcs skip4
1200 jsr DeleteHero
1201
1202 lda HeroY
1203 cmp #103
1204 bcs skip2
1205 adc #6
1206 sta HeroY
1207 jmp skip2
1208 skip4 lda HeroY
1209 cmp #36
1210 bcc skip2
1211 jsr DeleteHero
1212
1213 lda HeroY
1214 sbc #6
1215 sta HeroY
1216
1217 skip2 jsr PlotHero
1218
1219
1220 ;Count down
1221 dec StarfieldDistance
1222 beq skip3
1223 jmp loop2
1224 skip3
1225 .)
1226 ;Clear Screen
1227 jsr ClearScreen
1228
1229 ;Move to destination of Trampolene
1230 ldx ThisTrampolenesID
1231 lda TrampolenesEndMapX,x
1232 sta MapX
1233
1234 ;Position Hero correctly
1235 lda TrampolenesEndHeroX,x
1236 sta HeroX
1237 lda #34
1238 sta HeroY
1239
1240 ;If new MapX is 237 then bonus level, so set speed of sunmoon to high and reset sunmoon ypos
1241 lda MapX
1242 cmp #237
1243 .(
1244 bne skip1
1245 jsr SetTimeLimit
1246 ; lda #00
1247 ; sta usm_SunMoonYPos
1248 ; ldx Option_Difficulty
1249 ; lda BonusSpeed,x
1250 ; sta CounterReference
1251 lda #$67
1252 sta HeroY
1253
1254 skip1 ;Refresh screen, bgbuff and collision map
1255 .)
1256 jsr DrawMap
1257
1258 ;Refresh Hero
1259 jmp PlotHero
1260
1261 DeathSequence
1262 ;Descend hero to ground
1263 jsr CheckBelowInCollisionMap
1264 .(
1265 bcs skip1
1266
1267 ;Falling..
1268 jsr DeleteHero
1269 ;When falling Synchronise y position to 1 6th then fall every 6 pixels
1270 lda #4
1271 sta InternalFallCount
1272 loop1 dec InternalFallCount
1273 beq skip2
1274 lda HeroY
1275 clc
1276 adc #2
1277 ora #1 ;Allign to blue head, red arms
1278 sta HeroY
1279 cmp #$70
1280 bcs skip1
1281 skip4 jsr CheckBelowInCollisionMap
1282 bcc loop1
1283 skip2
1284 jsr PlotHero
1285
1286 jsr SpeedDampener
1287 jmp DeathSequence
1288
1289 skip1 ;Animate with frame 06 then 07
1290 .)
1291 lda #6
1292 sta HeroFrame
1293 jsr PlotHero
1294 lda #10
1295 sta ProgrammableCountdown
1296 jsr SpeedDampener
1297 lda #7
1298 sta HeroFrame
1299 jsr PlotHero
1300
1301 ;Wait a while longer
1302 lda #10
1303 sta ProgrammableCountdown
1304 jsr SpeedDampener
1305
1306 ;Delete Hero
1307 jsr DeleteHero
1308
1309 ;Clear screen
1310 jsr ClearScreen
1311
1312 ;decrement lives
1313 dec HeroLives
1314 beq GameOver
1315
1316 ;Display lives
1317 jsr DisplayLives
1318
1319 ;Return to last trampolene or level start x/y
1320 jsr RestoreHero2SafeZone
1321 lda #00
1322 sta HeroFrame
1323 sta JumpPhase
1324
1325 ;Refresh screen, bgbuff and collision map
1326 jsr DrawMap
1327
1328 ;Also clear single line just below play area since this often contains crap
1329 ldx #39
1330 lda #64
1331 .(
1332 loop1 sta $A000+40*138,x
1333 dex
1334 bpl loop1
1335 .)
1336 ;Refresh Hero
1337 jmp PlotHero
1338
1339 GameOver
1340 ;Display Game Over mid screen
1341 ldx #OVERLAY_GAMEOVER
1342 jsr DisplayOverlay
1343 lda #GAME_NOMORELIVES
1344 sta GameAction
1345 rts
1346
1347 PlotHero
1348 lda HeroX
1349 ldy HeroY
1350 jsr RecalcScreen
1351
1352 lda HeroX
1353 ldy HeroY
1354 sec
1355 sbc #1
1356 jsr RecalcBGBuff
1357
1358 ldx HeroFrame
1359 lda HeroBMPGraphicAddressLo,x
1360 sta graphic
1361 lda HeroBMPGraphicAddressHi,x
1362 sta graphic+1
1363
1364 lda HeroMSKGraphicAddressLo,x
1365 sta mask
1366 lda HeroMSKGraphicAddressHi,x
1367 sta mask+1
1368
1369 ldx #24
1370 .(
1371 loop2 ldy #3
1372 loop1 lda (bgbuff),y
1373 bpl skip1
1374 eor #63
1375 and (mask),y
1376 ora (graphic),y
1377 eor #63+128
1378 jmp skip2
1379 skip1 and (mask),y
1380 ora (graphic),y
1381 skip2 sta (screen),y
1382 dey
1383 bpl loop1
1384
1385 lda graphic
1386 clc
1387 adc #4
1388 sta graphic
1389 lda graphic+1
1390 adc #00
1391 sta graphic+1
1392
1393 jsr nlScreen
1394
1395 lda mask
1396 adc #4
1397 sta mask
1398 lda mask+1
1399 adc #00
1400 sta mask+1
1401
1402 lda bgbuff
1403 adc #40
1404 sta bgbuff
1405 lda bgbuff+1
1406 adc #00
1407 sta bgbuff+1
1408
1409 dex
1410 bne loop2
1411 .)
1412 rts
1413
1414 ;Remove hero from screen by restoring his current loc with the bgbuff
1415 DeleteHero
1416 lda HeroX
1417 ldy HeroY
1418 jsr RecalcScreen
1419
1420 ;Reduce Y to play area range
1421 lda HeroX
1422 ldy HeroY
1423 sec
1424 sbc #1
1425 jsr RecalcBGBuff
1426
1427 ldx #24
1428 .(
1429 loop2 ldy #3
1430 loop1 lda (bgbuff),y
1431 sta (screen),y
1432 dey
1433 bpl loop1
1434 jsr nlBgbuff
1435 jsr nlScreen
1436 dex
1437 bne loop2
1438 .)
1439 rts
1440
1441 CheatCode2
1442 .byt "MAYBE THE CHEAT IS HERE SOMEWHERE.."

  ViewVC Help
Powered by ViewVC 1.1.26