ASM to Sega Genesis Platform

All about assembly programming in the Sega Genesis console.


    Homing Attack - Variant 2 - Quadratic Method

    Share

    OuricoDoido
    Admin

    Mensagens : 46
    Data de inscrição : 2011-01-09
    Current Project : Sonic Open Source Project

    Homing Attack - Variant 2 - Quadratic Method

    Post  OuricoDoido on Thu Feb 03, 2011 7:00 pm

    In this method, the Sonic goes in enemy direction by the edges of a imaginary rectangle between they.



    When the Sonic enter in blue range, the horizontal alignment is activated and the vertical alignment is disabled.

    To download the Rom and the Source Code, click here: http://goo.gl/2SH7T
    To apply this you need first apply the Homing Attack in Sonic 1 guide.


    Now in HA_Move change this:
    Code:
    ; Recalculating the distance between the Sonic and the object (d1 = x distance / d2 = y distance)
          move.w  8(a1),d1   ; move the object x-position to d1
          move.w  $C(a1),d2   ; move the object y-position to d2
          sub.w  8(a0),d1   ; sub sonic x-position of object x-position
          sub.w  $C(a0),d2   ; sub sonic y-position of object y-position

          jsr      (CalcAngle).l   ; calculates the angle
          jsr      (CalcSine).l   ; calculates the sine and the cosine
          muls.w  #$C,d1         ; multiply cosine by $C
          move.w  d1,$10(a0)      ; move d1 to X-velocity
          muls.w  #$C,d0         ; multiply sine by $C
          move.w  d0,$12(a0)      ; move d0 to Y-velocity

    Sonic_HA_rts:
          rts                  ; return
    To this:
    Code:
       ; vertical alignment
          move.w  $C(a1),d2   ; move the object y-position to d2
          sub.w  $C(a0),d2   ; sub sonic y-position of object y-position
          move.w   d2,d3      ; copy y-distance to d3
          muls.w   d3,d3      ; vertical distance squared
          cmp.w   #400,d3      ; is y-distance of Sonic, less than or equal 20 pixels of the object? (20^2=400 // $14^2=$190)
          ble.s   Ha_GO      ; if yes, attack him
          clr.w  $10(a0)      ; if not, stop Sonic's X-velocity
          muls.w   #5,d2         ; multiply y-distance by 5
          add.w  d2,$12(a0)      ; add y-distance*5 to Y-velocity
          rts


    Ha_GO:   ; horizontal alignment
          move.w  8(a1),d1   ; move the object x-position to d1
          sub.w  8(a0),d1   ; sub sonic x-position of object x-position
          clr.w  $12(a0)      ; stop Sonic's Y-velocity
          muls.w   #5,d1         ; multiply x-distance by 5
          add.w  d1,$10(a0)      ; add x-distance*5 to X-velocity

    Sonic_HA_rts:
          rts                  ; return


    Last edited by OuricoDoido on Fri Feb 04, 2011 12:34 pm; edited 1 time in total

    TailsX-Doll

    Mensagens : 1
    Data de inscrição : 2011-02-02

    Re: Homing Attack - Variant 2 - Quadratic Method

    Post  TailsX-Doll on Fri Feb 04, 2011 12:56 am

    Cool!!!
    avatar
    hacker___

    Mensagens : 1967
    Data de inscrição : 2013-05-06
    Localização : Antarctica
    Current Project : Sonic Random Hax

    [flash(9999,9999)]http://www.youtube.com/v/qVCFV7jT9ho[/flash]

    Post  hacker___ on Sun May 19, 2013 11:45 am


    Sponsored content

    Re: Homing Attack - Variant 2 - Quadratic Method

    Post  Sponsored content


      Current date/time is Sun Jun 25, 2017 4:33 am