Actions

SCHG How-to

Difference between revisions of "Change Spike behavior in Sonic 1"

From Sonic Retro

(Initial version)
(No difference)

Revision as of 03:07, 13 January 2008

In Sonic the Hedgehog, there is a bug with the spikes: when Sonic touches them, 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.

This bug is actually very simple to fix. 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.