Actions

SCHG How-to

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

From Sonic Retro

m (Re-fixing category for sorting purposes)
(Added instructions for svn version)
Line 5: Line 5:
 
However, in ''[[Sonic the Hedgehog 2 (16-bit)|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''.
 
However, in ''[[Sonic the Hedgehog 2 (16-bit)|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 [[Media:Sonic 1 (Split and Text by Hivebrain).zip|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:
 
In [[Media:Sonic 1 (Split and Text by Hivebrain).zip|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:
  
Line 28: Line 29:
  
 
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.
 
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 ([[Community SVN Project|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 Obj36_Display ; +++ if yes, branch
 +
move.l a0,-(sp)
 +
</asm>
  
 
[[Category:SCHG How-tos|Change Spike behavior in Sonic 1]]
 
[[Category:SCHG How-tos|Change Spike behavior in Sonic 1]]

Revision as of 01:55, 3 March 2009

(Original guide by FraGag)

In Sonic 1, spikes work differently than in any other Sonic game: 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.

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 Obj36_Display ; +++ if yes, branch move.l a0,-(sp) </asm>