Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sonic_HomingAttack:
  2.     tst.w   $3a(a0)                                     ; Check if target has been set (AKA target is not zero)
  3.     beq.s   Sonic_HomingAttack_NoTarget                 ; If target is not set, branch
  4.    
  5.     cmpi.w  #$FFFF,         $3a(a0)                     ; Is special target
  6.     beq.s   Sonic_HomingAttack_Dash                     ; If so, execute airdash
  7.     bra.s   Sonic_HomingAttack_Home                     ; Home into target otherwise
  8.    
  9. Sonic_HomingAttack_NoTarget:
  10.     andi.b  #btnA,          (v_jpadpress1).w   
  11.     beq.s   Sonic_HomingAttack_Ret
  12.    
  13.     move.w  #$FFFF,         $3a(a0)
  14.    
  15.     move.w  v_lvlobjspace,  a1
  16.    
  17.     btst.b  #$00,           $22(a0)                     ; Is facing left?
  18.     beq.s   .init_left                                  ; If so, branch
  19.    
  20.     move.w  #$8000,         d1                          ; Initialise
  21.     bra.s   Sonic_HomingAttack_Loop_Targets
  22.    
  23. .init_left:
  24.     move.w  #$7FFF,         d1                          ; Initialise
  25.    
  26. Sonic_HomingAttack_Loop_Targets:
  27.     cmpi.w  #$F000,         a1                          ; Is iteration at the end?
  28.     bge.w   Sonic_HomingAttack_Ret                      ; If so, branch
  29.    
  30.     btst.b  #$00,           $22(a0)                     ; Is facing left?
  31.     beq.s   Sonic_HomingAttack_Target_Left              ; If so, branch
  32.    
  33.     ;;; Case: Sonic is facing right!
  34.     move.w  obX(a1),        d2                          ; Save current object X position
  35.     cmp.w   d1,             d2                          ; Is current X smaller than previous
  36.    
  37.     bge.s   Sonic_HomingAttack_Loop_Targets             ; If not, branch
  38.    
  39.     move.w  a1,             $3a(a0)                     ; Safe the new target
  40.     move.w  d2,             d1
  41.     ;;; Case ends
  42.    
  43. Sonic_HomingAttack_Target_Loop_Increment:
  44.     addi.w  #$40,           a1                          ; Increment pointer
  45.     bra.s   Sonic_HomingAttack_Loop_Targets
  46.    
  47.    
  48. Sonic_HomingAttack_Target_Left:
  49.     move.w  obX(a1),        d2                          ; Save current object X position
  50.     cmp.w   d1,             d2                          ; Is current X smaller than the previous (Because of how sign works, is it bigger)
  51.     bcs.s   Sonic_HomingAttack_Loop_Targets             ; If not, branch
  52.    
  53.     move.w  a1,             $3a(a0)                     ; Safe the new target
  54.     move.w  d2,             d1
  55.    
  56.     bra.s   Sonic_HomingAttack_Target_Loop_Increment    ; Return Back to loop
  57.    
  58. Sonic_HomingAttack_Ret:
  59.     rts
  60.    
  61. Sonic_HomingAttack_Dash:                                ; Airdash
  62.     move.w  #$0000,         $3a(a0)                     ; Unset target
  63.    
  64.     move.w  #$FFF,          obVelX(a0)                  ; TODO - FIX ME
  65.  
  66.     bra.s   Sonic_HomingAttack_Ret                      ; Return
  67.    
  68. Sonic_HomingAttack_Home:                                ; Actual homing part
  69.     move.l  #$FFFF0000,     a1
  70.     move.w  $3a(a0),        a1                          ; Initialise a1
  71.  
  72.     move.w  obX(a1),        d1                          ; Do some arithmetic
  73.     move.w  obY(a1),        d2
  74.     sub.w   obX(a0),        d1
  75.     sub.w   obY(a0),        d2
  76.    
  77.     jsr     (CalcAngle).l
  78.     jsr     (CalcSine).l                                ; Some amazing maths going on :)
  79.  
  80.     muls.w  #-$700,         d1
  81.     asr.l   #8,             d1
  82.     move.w  d1,             obVelX(a0)                  ; Make Sonic home in
  83.     muls.w  #-$700,         d0
  84.     asr.l   #8,             d0
  85.     move.w  d0,             obVelY(a0)                  ; Make Sonic home in
  86.    
  87.     bra.s   Sonic_HomingAttack_Ret                      ; Return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement