Implementing an unused death animation into Sonic 1

Discussion in 'Tutorials Archive' started by jubbalub, Aug 30, 2016.

  1. jubbalub

    jubbalub Mania fanboy Member

    Joined:
    Dec 25, 2014
    Messages:
    286
    This guide is geared toward beginners (like me :p) and designed for the Hivebrain disassembly. It should be easy enough to adapt to the GitHub disassembly.

    There are many unused sprites in Sonic 1, but one of them in particular piqued my interest:

    sprite0.png

    It's what seems to be a death animation. It may have been used when Sonic is killed by a fire hazard, as Sonic appears to be burned/charred. There's also an animation that sets Sonic's sprite to this, but it's unused.

    Our goal: make Sonic use this sprite after being killed by a fire hazard.

    Let's begin. Open up sonic1.asm in your text editor of choice (I recommend Notepad++) and perform a search for "KillSonic:" (line 35264). This is the routine that handles Sonic when he's killed.
    Code:
    KillSonic:
            tst.w    ($FFFFFE08).w    ; is debug mode    active?
            bne.s    Kill_NoDeath    ; if yes, branch
            move.b    #0,($FFFFFE2D).w ; remove invincibility
            move.b    #6,$24(a0)
            bsr.w    Sonic_ResetOnFloor
            bset    #1,$22(a0)
            move.w    #-$700,$12(a0)
            move.w    #0,$10(a0)
            move.w    #0,$14(a0)
            move.w    $C(a0),$38(a0)
            move.b    #$18,$1C(a0)
            bset    #7,2(a0)
            move.w    #$A3,d0        ; play normal death sound
            cmpi.b    #$36,(a2)    ; check    if you were killed by spikes
            bne.s    Kill_Sound
            move.w    #$A6,d0        ; play spikes death sound
    
    Kill_Sound:
            jsr    (PlaySound_Special).l
    
    Kill_NoDeath:
            moveq    #-1,d0
            rts
    
    Take a look at this line:
    Code:
    move.b    #$18,$1C(a0)
    This line determines what to set Sonic's animation to - in this case it's 18, the death animation. Our unused animation is number 16. We COULD simply change the 18 to 16, but then Sonic will use this animation every time he dies, and we don't want that.

    What we need to do, is before the code that changes Sonic's animation, we need to add a check to see if Sonic was killed by a specific object - in this case, a fire hazard - and if so, set Sonic's animation to 16.

    Just above the aforementioned line, add this code:
    Code:
    cmpi.b    #$14,(a2)    ; check if you were killed by fireball
    beq.s    Kill_Lava       ; if yes, branch
    cmpi.b    #$35,(a2)    ; check if you were killed by sinking floor fireball
    beq.s    Kill_Lava       ; if yes, branch
    cmpi.b    #$54,(a2)    ; check if you were killed by lava
    beq.s    Kill_Lava       ; if yes, branch
    cmpi.b    #$6D,(a2)    ; check if you were killed by flamethrower
    beq.s    Kill_Lava        ; if yes, branch
    
    The commands above are Compare and BranchIfEqual. In this case, the game is checking if you were killed by a fireball, and if yes, branch to another routine (in this case, KillLava). If you were not killed by a fireball, the game does the same check, but for the invisible lava tag, the sinking platform fire, and flamethrowers.

    Now we need to create the routine that changes Sonic's animation. Underneath the routine KillSonic, create a new routine called Kill_Lava, and put the following code under it:
    Code:
    move.b    #$16,$1C(a0)
    This code will only run if one of the above checks succeeded. It sets Sonic's animation to 16, which contains the unused burned sprite. Now we can build the ROM and test it out...

    upload_2016-8-30_14-27-23.png

    Success! However, there's a bug: the death sound doesn't play. To fix this, add the following lines to the end of the Kill_Lava routine:
    Code:
            move.w    #$A3,d0        ; play death sound
            jsr    (PlaySound_Special).l
    Now, the death sound will play. Congratulations, you now have a new death sprite in your hack!

    Optionally, you can make the sound more fitting by making it play sound B3, which is the flamethrower sound.
     
    Last edited: Aug 30, 2016
  2. TheStoneBanana

    TheStoneBanana banana Member

    Joined:
    Nov 27, 2013
    Messages:
    602
    Location:
    The Milky Way Galaxy
    You know what... I never even thought about the sprite that way. I mean, it makes sense, yet I always thought he was turned to stone or something.

    For a first guide, I'll say that it was well done, and you gave pretty clear explanations as to what was going on. Nice work!
     
  3. Royameadow

    Royameadow Welcome to the modern existence. Member

    Joined:
    Feb 21, 2012
    Messages:
    249
    Location:
    Lynn MA, North America
    This now makes me wonder about the other animation that has been used in a few ROM hacks in the Late 200X and Early 201X decade, Sonic getting sucked away from the screen seemed more like a Warping Out animation, if anything, which I presume was intended to be used for the Secret Zones/Special Stages if the player were to have Sonic touch a Goal Circle.
    I think that there's a tutorial somewhere on here or Retro that discusses it, but if that's not the case, then wishfully, that could be done at a later point in time; I always have wanted the unused sprites and functions of the original game to be used or expanded upon, and ROM hacks such as Beta Remake and tutorials such as this one definitely do deliver many potential things to come from the unused material, prototype and unused material always makes me smile when it gets attention and this one is no exception, I like what I am seeing. :)
     
  4. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    Nice post! Never considered it to be a fiery death animation, myself. By the way, don't forget about the flamethrowers in SBZ (Obj6D).
     
    Pacca likes this.
  5. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,902
    Location:
    italy
    I really like what you did there, I never thought of that sprite in that way, but it looks like you put it to good use, nice work indeed!

    If you play my hack, you'll see that I used the shrinking animation for the exact purpose you mention here (touching a Goal in a Special Stage) ;)
     
  6. Psycho RFG

    Psycho RFG Well-Known Member Member

    Joined:
    Feb 22, 2011
    Messages:
    234
    Sirously? No one never considered this?
    Back to 2011... at 3min. 25sec.

    (Note: Very old stuff)

    It's the first "video proof" I have, but the unused animations what's one of the first things I added to my project...
     
  7. Arsen

    Arsen Active Member In Limbo

    Joined:
    May 16, 2014
    Messages:
    39
    Oh, I see where it all started. Btw nice hack (I know that's old xD. I saw newer ones as well).
     
  8. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,020
    Re-read the rules:
    This thread didn't need bumping.
     
    Pacca, Arsen, Misinko and 2 others like this.
  9. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    error.png I've tried everything, i always end up with the ROM breaking (not loading and staying on a black screen)
    do you think you can paste the entire code? I've tried countless times, i'm at breaking point and I didn't want to use the copy+paste method but i have no other option
     
    Last edited: Mar 13, 2017
  10. Arsen

    Arsen Active Member In Limbo

    Joined:
    May 16, 2014
    Messages:
    39
    Well, firstly you need to know what disassembly you currently using. In this tutorial, he is using Hivebrain disassembly. Secondly, after copy pasting, reread the code, maybe you missing something or you have a syntax error?

    EDIT: I saw screenshot so it must have some errors because it doesn't even load "SONIC THE HEDGEHOG" on title screen.
     
    Last edited by a moderator: Mar 13, 2017
  11. ProjectFM

    ProjectFM Optimistic and self-dependent Member

    Joined:
    Oct 4, 2014
    Messages:
    912
    Location:
    Orono, Maine
    Is there a "pause" at the end of build.bat so you can read what errors have come up? When there are errors when building the rom, the rom created will be blank.
     
  12. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    From what I know, there typically aren't ROMs built if there are any errors (assuming the 2005 version).

    From the looks of things, the header isn't even showing up, so the ROM is definitely broken. What have you done to change it exactly? What disassembly are you using, also?
     
    MarkeyJester likes this.
  13. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    I'm using Hivebrains disassembly.
    (https://www.mediafire.com/?ca4ksobw09imsbf) This is the ASM file, i'm a newbie at hacking so i'm probably missing an obvious thing that i can't find, i'm so sorry for doing this

    EDIT: i just realized this the backup version (though it does the air/ground speed cap removed, yay me for pulling that off) and not the buggered up version that doesn't load
     
  14. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,020
    If you want to know the cause of the error, look no further than the assembler. As ProjectFM already said, it tells you what went wrong. Either run build.bat in a command prompt, or stick a 'pause' command at the end build.bat itself, and running it will make it display the error.
     
    Last edited: Mar 14, 2017
  15. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    THANK YOU SO MUCH
    it now works! i'm so proud of myself! :D
     
  16. Greenknight9000

    Greenknight9000 Well-Known Member Member

    Joined:
    Apr 30, 2014
    Messages:
    53
    hey i noticed an error, when you die by spikes, it used the "burned" sprites instead of the normal death sprite, what's the fix?
    (P.S: Can you add a tutorial for implementing the "background/warped" death animation for use in the Special Stages?
     

    Attached Files:

  17. Clownacy

    Clownacy Retired Staff lolololo Member

    Joined:
    Aug 15, 2014
    Messages:
    1,020
    ...no it doesn't. If you followed the guide properly, that sprite only appears when you're killed by lava, a fireball, flamethrower, or that one platform in Marble Zone that sinks into lava and catches fire.

    EDIT: Reading through it again, this guide's a little broken: instead of incorporating a simple 'if, else' on that '$1C(a0)' write, the entire subroutine gets hijacked, and directed to a different piece of code entirely. The guide even has to work around that by adding duplicate code to play the death sound. But the death sound isn't the only thing lost when you don't let the subroutine finish properly: Sonic also doesn't get set to the high priority, so he could very well fall behind the level when he dies from a fire-based attack.
     
    Last edited: Mar 14, 2017
    Bluestreak likes this.
  18. Sinkdude

    Sinkdude He looked much leaner on TV Member

    Joined:
    May 6, 2008
    Messages:
    41
    Location:
    Michigan
    I'm highly impressed with what you've done here. I'll probably experiment with the methods on Sonic 2, unless I hit a bump in the process.