ThomasSpeedrunner icon

Tails Flying Code v4

ThomasSpeedrunner | PRO | 05/03/13 07:31:28 PM UTC | 0 ⭐ | 478 👁️ | Never ⏰ | []
text |

4.95 KB

|

None

|

0 👍

/

0 👎

; Here we have the actual flight routine itself...
; ---------------------------------------------------------------------------
; Subroutine to check if Tails wants to begin flying mid-jump
; ---------------------------------------------------------------------------
Tails_CheckFlight:
	btst	#1,flight_property(a0)		; are we flying?
	bne.s	Tails_FlyingSwimming		; if yes, branch to the subroutine handling Tails' flight logic
	btst	#2,flight_property(a0)		; are we tired while flying?
	bne.s	Tails_FlyingSwimming		; if yes, branch to the subroutine handling Tails' flight logic
 	tst.b	(Two_player_mode).w		; are we in two player mode?
	bne.w	+				; if so, skip the following check
 	cmpa.w	#MainCharacter,a0		; is Tails the main character?
	bne.w	return_1C83D			; if not, return
+
	cmpi.b	#1,jumping(a0)			; are we jumping?
	bne.w	return_1C83D			; if not, return
 	move.b	(Ctrl_1_Press_Logical).w,d0
	andi.b	#button_B_mask|button_C_mask,d0	; is B or C pressed?
	beq.w	return_1C83D			; if not, return
; if all of these conditions are met, do the following:
	move.b	#AniIDTailsAni_Fly,anim(a0)	; begin flying
	move.b	#$4B,flight_time(a0)		; set the amount of time Tails can fly for (this is needed later, in Tails_FlyingSwimming)
	move.w	#$C,y_vel(a0)			; set Tails' y-velocity to something reasonable (again, needed later, in Tails_FlyingSwimming)
	bset	#1,flight_property(a0)		; tell the game that Tails is flying (part 1)
	bclr	#0,flight_property(a0)		; tell the game that Tails is flying (part 2)
 return_1C83D:
	rts
 ; ---------------------------------------------------------------------------
; Subroutine doing the extra logic for Tails' flight
; ---------------------------------------------------------------------------
Tails_FlyingSwimming:
	jsr	(ObjectMove).l
	cmpi.b	#death_egg_zone,(Current_Zone).w	; are we in Death Egg Zone?
	bne.s	+					; if not, skip the reverse gravity check
	moveq	#0,d0					; clear d0
	move.b	(Reverse_gravity_flag).w,d0		; move the value in Reverse_gravity_flag into d0
	cmpi.b	#1,d0					; is the reverse gravity gimmick on?
	bne.s	+					; No? Branch then
	subi.w	#4,y_vel(a0)				; If so, SUBTRACT from Tails' y_vel instead
	bra.s	++
+
	addi.w	#4,y_vel(a0)				; slowly increase Tails' gravity
+
	moveq	#0,d0
	move.b	($FFFFFE05).w,d0
	andi.b	#9,d0
	bne.s	+
	subq.b	#1,flight_time(a0)
	bne.s	+
	btst	#2,flight_property(a0)		; Did we already tell the game that Tails is tired?
        bne.s	+				; If so, don't keep telling it, since that's completely pointless and just wastes CPU cycles.
	bset	#2,flight_property(a0)		; If we haven't yet, tell the game that Tails is tired.
+
	rts
 ; ...and the modified Obj02_MdJump routine...
; ===========================================================================
; Start of subroutine Obj02_MdJump
; Called if Tails is in a ball and airborne (he could be jumping but not necessarily)
Obj02_MdJump:
	bsr.w   Tails_CheckFlight
	bsr.w	Tails_JumpHeight
	bsr.w	Tails_ChgJumpDir
	bsr.w	Tails_LevelBound
	btst	#1,flight_property(a0)	; is Tails flying?
	bne.s	+			; if so, skip ObjectMoveAndFall and related commands (the gravity for Tails' flying is handled in Tails_FlyingSwimming)
	btst	#2,flight_property(a0)	; is Tails in a tired state while flying?
	bne.s	+			; if so, skip ObjectMoveAndFall and related commands (the gravity for Tails' flying is handled in Tails_FlyingSwimming)
	jsr	(ObjectMoveAndFall).l
	btst	#6,status(a0)	; is Tails underwater?
	beq.s	+		; if not, branch
	subi.w	#$28,y_vel(a0)	; reduce gravity by $28 ($38-$28=$10)
+
	bsr.w	Tails_JumpAngle
	bsr.w	Tails_DoLevelCollision
	rts
; End of subroutine Obj02_MdJump
; ===========================================================================
; ...the modified Obj02_ResetOnFloor_Part3...
; loc_1CB80:
Tails_ResetOnFloor_Part3:
	bclr	#1,status(a0)
	bclr	#5,status(a0)
	bclr	#4,status(a0)
	move.b	#0,jumping(a0)
	move.w	#0,(Chain_Bonus_counter).w
	move.b	#0,flip_angle(a0)
	move.b	#0,flip_turned(a0)
	move.b	#0,flips_remaining(a0)
	btst	#0,flight_property(a0)			; Test the not-flying bit...
	bne.s	+					; ...and if we didn't fly since the last time we hit the floor, skip the flying section
	; Section for Tails' flight:
	move.b	#0,flight_time(a0)			; Reset our flight time...
	bclr	#1,flight_property(a0)			; ...clear the flying bit...
	bclr	#2,flight_property(a0)			; ...clear the tired-while-flying bit...
	bset	#0,flight_property(a0)			; ...and set the not-flying bit.
+	; Rest of original subroutine:
	move.w	#0,(Tails_Look_delay_counter).w
	cmpi.b	#AniIDTailsAni_Hang2,anim(a0)
	bne.s	return_1CBC4
	move.b	#AniIDTailsAni_Walk,anim(a0)
 return_1CBC4:
	rts
; ...and the modified section of Level_FromCheckpoint (this was done to fix a bug).
	move.b	#1,(Level_started_flag).w
	cmpi.w	#2,(Player_mode).w
	bne.s	+
	bset	#0,flight_property(a0)
	bclr	#1,flight_property(a0)
	bclr	#2,flight_property(a0)
; Level_StartGame: loc_435A:
+	bclr	#GameModeFlag_TitleCard,(Game_Mode).w ; clear $80 from the game mode

Comments