fall_damage

by hwailaluta

Game: Super Mario World

Description: xhsdf made this on SMWC.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Fall damage
;          by xhsdf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


!falldistance = $0019	; Lethal fall height

!kill = 0				; 0 = hurt, 1 = kill

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


!ypos = $96						; RAM address of current y position
!peakPosRam = $13E6|!addr		; RAM address to save peak y position (2 bytes)


main:
        LDA !carl_initialized
        BNE +
	JSL save_current_pos
	RTL

        +
	LDA $75					; \ Check if in water
	BNE not_falling			; /

	LDA $77					; \
	AND #$04				; | Check if on the ground
	BNE on_ground			; /


in_air:
	LDA $7D					; \ Check direction:
	BEQ not_falling			; | If speed is 0 Mario is not moving
	BMI not_falling			; / If speed is negative (>= $80) Mario is moving up

	CMP $00D7B9				; \ Check if falling with cape speed
	BCC not_falling			; | or slower
	BEQ not_falling			; /

	RTL


on_ground:
	REP #$30				; Enter 16-bit mode
	LDA !ypos

	CMP !peakPosRam			; \ Check if old position is lower.
	BCC not_falling			; / Happens when Mario is clipped upwards

	SEC						; \
	SBC !peakPosRam			; | Check if difference between start and
	CMP #!falldistance		; | end position is bigger than !falldistance
	SEP #$30				; | and exit 16-bit mode
	BCC save_current_pos	; /


hurt:
	if !kill == 1			; \
		JSL $00F606|!bank	; |
	else					; | Kill or hurt player
		JSL $00F5B7|!bank	; |
	endif					; /


not_falling:
save_current_pos:
	REP #$30				; \
	LDA !ypos				; | Enter 16-bit mode, save current y
	STA !peakPosRam			; | position and exit 16-bit mode
	SEP #$30				; /

	RTL
back to listings