Actions

SCHG How-to

Change Spike behavior in Sonic 1

From Sonic Retro

Revision as of 01:44, 9 April 2010 by PicklePower (talk | contribs)

(Original guide by FraGag)

In Sonic 1, spike damage behavior differs from any other Sonic game: when Sonic touches spikes, the game doesn't check if Sonic is invulnerable (he is invulnerable when he flashes). So, if Sonic hits spikes and falls back on spikes again, he dies immediately instead of being temporarily invulnerable.

However, in Sonic 2, this behavior was altered; instead of hurting Sonic regardless of invulnerability status, the game would allow the flashing invulnerability to protect Sonic from further spike damage. This change in behavior is very easy to apply to Sonic 1.

Hivebrain's Sonic 1 disassembly (2005)

In Hivebrain's Sonic 1 disassembly, find the label Obj36_Hurt. Object 36 is the spikes, and Obj36_Hurt checks if Sonic should be hurt or not by the spikes according to his state. This is the original code:

<asm> Obj36_Hurt: ; XREF: Obj36_SideWays; Obj36_Upright tst.b ($FFFFFE2D).w ; is Sonic invincible? bne.s Obj36_Display ; if yes, branch move.l a0,-(sp) ... </asm>

This code checks if Sonic is invincible (he is invincible when he destroys an invincibility monitor), but not if he is invulnerable. There are only two instructions to add to the code (indicated by +'s in the comments, which you may of course remove):

<asm> Obj36_Hurt: ; XREF: Obj36_SideWays; Obj36_Upright tst.b ($FFFFFE2D).w ; is Sonic invincible? bne.s Obj36_Display ; if yes, branch tst.w ($FFFFD030).w ; +++ is Sonic invulnerable? bne.s Obj36_Display ; +++ if yes, branch move.l a0,-(sp) ... </asm>

At $FFFFD030 is stored the time left for Sonic's temporary invulnerability. It is set to 120 (2 seconds) as soon as Sonic gets hit, but starts decreasing only when Sonic touches the ground (or another set of spikes!), so even if Sonic falls directly on spikes, he will be invulnerable to them, which is the desired effect.

Sonic 1 disassembly (svn version)

The svn version of the disassembly splits the objects' code in separate files. The code for the spikes object is located in _incObj\36 Spikes.asm. Locate this: <asm> Spik_Hurt: ; XREF: Spik_SideWays; Spik_Upright tst.b (v_invinc).w ; is Sonic invincible? bne.s Spik_Display ; if yes, branch move.l a0,-(sp) </asm>

and replace it with this: <asm> Spik_Hurt: ; XREF: Spik_SideWays; Spik_Upright tst.b (v_invinc).w ; is Sonic invincible? bne.s Spik_Display ; if yes, branch tst.w (v_player+$30).w ; +++ is Sonic invulnerable? bne.s Spik_Display ; +++ if yes, branch move.l a0,-(sp) </asm>