Position based attack

Discussion in 'Discussion and Q&A Archive' started by RandomAvatarFan, Jun 11, 2009.

Thread Status:
Not open for further replies.
  1. RandomAvatarFan

    RandomAvatarFan Well-Known Member Member

    Joined:
    Apr 10, 2009
    Messages:
    100
    Sorry if the title is a little confusing, I don't know what else to call it...


    Well here's my predicament:


    In my Sonic 1 hack, I created a new move called "Sonic Slide-n-punch" which uses a sprite that I believe the asm file for Sonic's animation calls "surf"


    Now I used it because it looks like he's punching in front of him. I got it set up, and the physics work fine, and it kills enemies fine. Yet it kills all the enemies regardless if they're coming from above, below, or behind him.


    My question: How can I make it so that the move will only kill enemies that are in front of Sonic, and any enemies that touch him from above, or below, or behind him, make Sonic get hurt?


    EDIT: Now thinking about, having Sonic get hurt from below, while it may look more realistic, might be a bit too much if he's sliding from a higher point down onto a lower platform filled with enemies....
     
    Last edited by a moderator: Jun 11, 2009
  2. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Depending on how you get sonic to kill enemies, you'd want a check for which way he's facing (Check sonic's walking routines, don't know how it is in S1). Your description is something I didn't really get, but if it's 'slide and punch' it would work something like spindash? Then instead of having the sprite shift have sonic actually move a certain speed and stop after going a certain speed. Again, look at spinning/spindash code for that.


    Sonic_NotLeft


    Sonic_NotRight


    or something similar is where you'd want to start.
     
  3. Thorn

    Thorn wroar Member

    Joined:
    Aug 11, 2007
    Messages:
    70
    So you're asking how to only have the enemy killed if they're in front of you, else Sonic gets hurt? I can't say that I've ever done something like this personally, but here's how I'm thinking through it in my head...


    1. Have a flag thrown in the routine for the attack that says "Sonic is punching now". Be sure it deactivates when it's not needed.


    2. Find the routine that checks for Sonic destroying an enemy (in the 2007 Sonic 2 disassembly it's Touch_Enemy and Touch_KillEnemy, but I don't know Sonic 1's labelling), and add code that only activates if the flag is on.


    3. In this new code...


    - Move the enemy's x position into d0 or another register.


    - Subtract Sonic's x position from d0.


    - If Sonic is facing to the left, negate d0 (i.e. swap the positive/negative sign for the other).


    - If d0 is negative (i.e. the enemy is behind Sonic), branch to the routine that hurts Sonic, else continue with the code for destroying the enemy.


    This is totally untested, but methinks that's the basic premise -- you'll just have to convert the pseudocode to actual code. You'll probably want to compare the enemy's y position to Sonic's position as well, or else things might look strange in-game with Sonic throwing a chest-level punch and hitting enemies at head-level or foot-level.
     
    Last edited by a moderator: Jun 11, 2009
  4. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada

    You could just have an animation # check, would be easier that way in my opinion.
     
  5. RandomAvatarFan

    RandomAvatarFan Well-Known Member Member

    Joined:
    Apr 10, 2009
    Messages:
    100
    I was thinking the same thing myself.

    Thanks guys!
     
Thread Status:
Not open for further replies.