Move in Opposite Direction of Player

tbizzle

Well-known member
I need a move in opposite direction of player script for the Adventure Module. Any help appreciated!
 

tbizzle

Well-known member
@SHLIM I'll be damned! Yeah, I was trying to figure it out because I wanted a hurt reaction/recoil that didn't draw the monster into you as you attacked it. Totally not trying to steal your mechanics, lol.
 

SHLIM

Active member
@SHLIM I'll be damned! Yeah, I was trying to figure it out because I wanted a hurt reaction/recoil that didn't draw the monster into you as you attacked it. Totally not trying to steal your mechanics, lol.
did you add the recoil code yourself? cuz if its drawing the enemy in on attack then it sounds like youve setup the recoil in the opposite way...it should be, well, recoiling not drawing in lol :D
 

kevin81

Well-known member
"Move from player" essentially is "Move towards player" but with negated horizontal and vertical speeds.
I can't test this right now, but the following AI script should move an object away from the player. I tried to document it as much as possible, hope this helps!

Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;  AI SCRIPT: move away from player
;;
;;


    ;; Store the object's slot index (which is in the x-register) in
    ;; the tempx variable for later use.
    STX tempx

    ;; Store the current position of the object into held argument
    ;; variables for use with the doMoveTowardsPoint subroutine
    LDA Object_x_hi,x
    STA arg0_hold
    LDA Object_y_hi,x
    STA arg1_hold

    ;; Store the current position of the player into held argument
    ;; variables for use with the doMoveTowardsPoint subroutine.
    LDX player1_object
    LDA Object_x_hi,x
    STA arg2_hold
    LDA Object_y_hi,x
    STA arg3_hold
    STA tempD

    ;; Restore the object's slot index from the tempx variable and
    ;; into the x-register.
    LDX tempx


    ;; Get the "move towards point" values. This subroutine is found
    ;; in bank $18, so we need to bankswitch as well. Because both
    ;; doMoveTowardsPoint and the SwitchBank macro clobber the
    ;; y-register, we need to push that onto the stack, so we can
    ;; restore it after.
    TYA
    PHA
    SwitchBank #$18
    JSR doMoveTowardsPoint
    ReturnBank
    PLA
    TAY

    ;; doMoveTowardsPoint also clobbers the X-register, so we need to
    ;; restore the object's slot id from the tempx variable into
    ;; the x-register again.
    LDX tempx

    ;; Reverse the object's horizontal speed, so that the object
    ;; moves in the exact opposite direction.
    LDA tempA
    EOR #$FF
    CMP #$7F
    BEQ +
        CLC
        ADC #1
    +
    STA Object_h_speed_lo,x

    ;; Now do the same for the object's vertical speed.
    LDA tempB
    EOR #$FF
    CMP #$7F
    BEQ +
        CLC
        ADC #1
    +
    STA Object_v_speed_lo,x

    ;; Reset the high byte of the object's speed, beause aimed
    ;; physics by default only set the low byte.
    LDA #$00
    STA Object_h_speed_hi,x
    STA Object_v_speed_hi,x
    
    ;; ...I think this forces the object to use aimed physics for
    ;; the rest of the main game loop?
    LDA Object_direction,x
    AND #%00000111
    ORA #%00001000
    STA Object_direction,x
 
Top Bottom