So I have this routine that determines the player's 'recoil' direction in four direction based on the 'centerpoint' of the monster versus the 'centerpoint' of the player's hit box. It works fine for three directions, but I never seem to have a 'right' recoil. When it should recoil right, it always recoils down. And the actual recoil routines work fine (if I activate them another way for testing). I've let it go for a while as the thing is still playable, but it's now annoying me to no end.
Here's my routine...anyone spot anything glaring?
DetermineRecoilDirection:
;; monPointX, monPointY = centerpoint for monster
;; playerPointX, playerPointY = centerpoint for player
;; this part of routine is used to get an 'absolute' value of the
;; difference in x so it can be checked against the
;; absolute difference in y to determine if it should
;; recoil horizontally or vertically
LDA monPointX
SEC
SBC playerPointX
BPL absCheckDone
EOR #$FF
CLC
ADC #$01
absCheckDone:
STA temp1
; now the abs difference in x values should be held in temp1
LDA monPointY
SEC
SBC playerPointY
BPL absCheckDone2
EOR #$FF
CLC
ADC #$01
absCheckDone2:
;; now, the accumulator should be holding the abs y difference.
CMP temp1 ;; compare the y difference against the x difference...
BPL vCol ;; if the result is positive, it's a vertical collision...
;; the vertical distance to center is larger than
;; the horizontal distance to center.
LDA monPointX
CMP playerPointX
BMI recoilRight
;;set values to recoil left
RTS
recoilRight:
;; set values to recoil right
RTS
vCol:
LDA monPointY
CMP playerPointY
BMI recoilDown
;; set values to recoil up
RTS
recoilDown:
;; set values to recoil down
RTS
Thanks for taking a look!
Here's my routine...anyone spot anything glaring?
Code:
DetermineRecoilDirection:
;; monPointX, monPointY = centerpoint for monster
;; playerPointX, playerPointY = centerpoint for player
;; this part of routine is used to get an 'absolute' value of the
;; difference in x so it can be checked against the
;; absolute difference in y to determine if it should
;; recoil horizontally or vertically
LDA monPointX
SEC
SBC playerPointX
BPL absCheckDone
EOR #$FF
CLC
ADC #$01
absCheckDone:
STA temp1
; now the abs difference in x values should be held in temp1
LDA monPointY
SEC
SBC playerPointY
BPL absCheckDone2
EOR #$FF
CLC
ADC #$01
absCheckDone2:
;; now, the accumulator should be holding the abs y difference.
CMP temp1 ;; compare the y difference against the x difference...
BPL vCol ;; if the result is positive, it's a vertical collision...
;; the vertical distance to center is larger than
;; the horizontal distance to center.
LDA monPointX
CMP playerPointX
BMI recoilRight
;;set values to recoil left
RTS
recoilRight:
;; set values to recoil right
RTS
vCol:
LDA monPointY
CMP playerPointY
BMI recoilDown
;; set values to recoil up
RTS
recoilDown:
;; set values to recoil down
RTS
Thanks for taking a look!