Change Spike behavior in Sonic 1
From Sonic Retro
Revision as of 09:52, 25 August 2018 by Black Squirrel (talk | contribs) (Text replacement - "\[\[Category:SCHG How-tos.*" to "")
(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 (andlabs - ASM68K), 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:
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)
...
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):
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)
...
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 (Git 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:
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)
and replace it with this:
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)
|Change Spike behavior in Sonic 1]]