Actions

Difference between revisions of "SPG:Ring Loss"

From Sonic Retro

m (Ring Distribution)
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Note: Research gathered from Sonic 1 (Genesis/Mega Drive), but it is highly likely that it holds true for Sonic CD, Sonic 2, Sonic 3, and Sonic & Knuckles.
+
{{SPGPages}}
 +
'''Notes:'''
 +
*''The research applies to all four of the [[Sega Mega Drive]] games and [[Sonic CD]].''
  
===Ring Limit===
+
==Ring Limit==
  
When Sonic gets hit, the number of rings he is carrying scatter away, unless he is carrying more than 32, in which case any rings over 32 are ignored.  Sonic is therefore no safer carrying 100 rings than 32.
+
When [[Sonic]] gets hit, the number of [[rings]] he is carrying scatter away, unless he is carrying more than 32, in which case any rings over 32 are ignored.  Sonic is therefore no safer carrying 100 rings than 32.
  
===Ring Distribution===
+
==Ring Distribution==
  
 
The rings that scatter away from Sonic are distributed in a specific pattern of 2 concentric circles, each containing a maximum of 16 rings.  The rings in the first circle move outward faster than the rings in the second.  Here is a formula for creating the rings, which can be converted into the programming language of your choice:
 
The rings that scatter away from Sonic are distributed in a specific pattern of 2 concentric circles, each containing a maximum of 16 rings.  The rings in the first circle move outward faster than the rings in the second.  Here is a formula for creating the rings, which can be converted into the programming language of your choice:
  
  {
+
  let t = 0
+
let ring_counter = 0
  let angle = 101.25 ; assuming 0=right, 90=up, 180=left, 270=down
+
let ring_angle = 101.25° (184) ($B8)  // assuming 0=right, 90=up, 180=left, 270=down
  let n = false
+
let flip = false
  let speed = 4
+
let speed = 4
 
    
 
    
  while t is less than the number of rings
+
// perform loop while the ring counter is less than number of lost rings
    {
+
while ring_counter < number of rings (max 32)
    create a bouncing ring object
+
{
    set the ring's vertical speed to -sine(angle)*speed
+
    // create the ring
    set the ring's horizontal speed to cosine(angle)*speed
+
    create a bouncing ring object at the Player's X and Y Position
    if n is true
+
    ring's X Speed = cosine(ring_angle) * speed
      {
+
    ring's Y Speed = -sine(ring_angle) * speed
      multiply the ring's horizontal speed by -1
+
   
      increase angle by 22.5
+
    // ever ring created will moving be at the same angle as the other in the current pair, but flipped the other side of the circle
      }
+
    if flip == true
    let n = not n ; if n is false, n becomes true and vice versa
+
    {
    increase t by 1
+
        ring's X Speed = ring's X Speed * -1 // reverse ring's x speed
    if t = 16
+
        ring_angle += 22.5° (240) ($F0)  // we increment angle on every other ring which makes 2 even rings either side
      {
+
    }
      let speed = 2 ; we're on the second circle now, so decrease the speed
+
   
      let angle = 101.25 ; and reset the angle
+
    // toggle flip
      }
+
    flip = !flip  // if flip is false, flip becomes true and vice versa
    }
+
   
  }
+
    // increment counter
 +
    ring_counter += 1
 +
   
 +
    // if we are halfway, start second "circle" of rings with lower speed
 +
    if ring_counter == 16
 +
    {
 +
        speed = 2
 +
        ring_angle = 101.25° (184) ($B8)  // reset the angle
 +
    }
 +
}
  
 
So, the first 16 rings move at a velocity of 4 pixels per step, and the second 16 move at half that rate, or 2 pixels per step.
 
So, the first 16 rings move at a velocity of 4 pixels per step, and the second 16 move at half that rate, or 2 pixels per step.
  
===Ring Gravity===
+
==Regathering Rings==
 
 
Rings do not heed the same gravity constant as Sonic does.  Instead, their gravity is a force of 0.09375.  So, this value is added to the rings' vertical speed every step.
 
 
 
===Ring Bounce===
 
 
 
When the scattered rings hit the ground, their vertical speed is multiplied by a factor of -0.75.  This has the effect of reversing their vertical motion, as well as slowing it somewhat.  This calculation is performed after the addition of the gravity.  Their horizontal speed is unaffected by bouncing.
 
 
 
When the rings bounce off the floor, they do so so imprecisely, it is almost embarrassing.  But this is really not noticed during normal play, and was perhaps necessary to avoid too much slowdown.  It looks to me like they don't check to see if they are colliding with the ground every step, so they sometimes pass well into the ground before deciding to bounce away.  This is something not really worth emulating.
 
 
 
But there are further limitations on bouncing rings, probably also in place to avoid processor load.  They are totally unaffected by walls, and are only concerned with vertical surfaces.  Moreover, they only check to see if they are colliding with a solid when they are moving downward (i.e. their vertical speed is positive).  Thus they can also fly up through ceilings.  This can actually become a bother to Sonic if he is struck in a small corridor, as most of his rings are lost in the ceiling and don't fall back down to be regathered.
 
 
 
Personally, if I were using a system with more power than the Genesis/Mega Drive, I would make the rings check for horizontal collisions.  If they collide, then they should multiply their horizontal speed by a factor of -0.25.  I would also check for ceilings, by asking in their vertical collision check whether they are moving up or down.  If they are moving down, they should bounce as normal, but if they are moving up, they should set their vertical speed to 0.  This is kinder to the player, for most of the rings do not get lost due to system limitations.
 
 
 
===Ring Lifespan===
 
 
 
All scattered rings are destroyed after 256 steps if they have not been regathered.  Also, if they leave the horizontal view boundaries, they are destroyed.  Again, on a more powerful system, you may choose not to include this feature.
 
 
 
===Regathering Rings===
 
  
 
64 steps must have passed since Sonic was hit before he can regather any rings, scattered or otherwise.
 
64 steps must have passed since Sonic was hit before he can regather any rings, scattered or otherwise.
  
===Invulnerability===
+
==Invulnerability==
  
 
Sonic remains invulnerable for a short time after being hit.  This invulnerability lasts while Sonic is flying back from the blow, and then 120 steps more after he recovers movement.  During those 120 steps, he flashes on and off, spending 4 steps on and 4 steps off.
 
Sonic remains invulnerable for a short time after being hit.  This invulnerability lasts while Sonic is flying back from the blow, and then 120 steps more after he recovers movement.  During those 120 steps, he flashes on and off, spending 4 steps on and 4 steps off.
  
===Ring Animations===
+
While in this state, Sonic can not collect level rings until less than 90 invulnerability steps remain.
 
 
Fixed rings have 4 frames of animation, and spend 8 steps showing each frame before moving to the next.  Scattered rings are more complicated, in that they have a much faster animation speed when they are created, but this slows down over their lifespan.  They begin only showing each frame for about 2 steps, and wind up at the end slowing to a crawl, showing each frame for 16 steps or more.  I do not know the precise values yet.  Scattered rings are created showing their initial frame of animation, which is the ring shown face on.
 
  
===Ring Depth===
+
==Ring Depth==
  
 
All rings, scattered or fixed, have a higher depth than Sonic, i.e. behind him.  But they have a lower depth, i.e. in front of him, when they turn into sparkles.
 
All rings, scattered or fixed, have a higher depth than Sonic, i.e. behind him.  But they have a lower depth, i.e. in front of him, when they turn into sparkles.
  
[[Category:Sonic Physics Guide]]
+
[[Category:Sonic Physics Guide|Ring Loss]]

Revision as of 15:14, 31 July 2021

Sonic Physics Guide
Collision
Physics
Gameplay
Presentation
Special

Notes:

Ring Limit

When Sonic gets hit, the number of rings he is carrying scatter away, unless he is carrying more than 32, in which case any rings over 32 are ignored. Sonic is therefore no safer carrying 100 rings than 32.

Ring Distribution

The rings that scatter away from Sonic are distributed in a specific pattern of 2 concentric circles, each containing a maximum of 16 rings. The rings in the first circle move outward faster than the rings in the second. Here is a formula for creating the rings, which can be converted into the programming language of your choice:


let ring_counter = 0
let ring_angle = 101.25° (184) ($B8)  // assuming 0=right, 90=up, 180=left, 270=down
let flip = false
let speed = 4
 
// perform loop while the ring counter is less than number of lost rings
while ring_counter < number of rings (max 32)
{
    // create the ring
    create a bouncing ring object at the Player's X and Y Position
    ring's X Speed = cosine(ring_angle) * speed
    ring's Y Speed = -sine(ring_angle) * speed
    
    // ever ring created will moving be at the same angle as the other in the current pair, but flipped the other side of the circle
    if flip == true
    {
        ring's X Speed = ring's X Speed * -1  // reverse ring's x speed
        ring_angle += 22.5° (240) ($F0)  // we increment angle on every other ring which makes 2 even rings either side
    }
    
    // toggle flip
    flip = !flip  // if flip is false, flip becomes true and vice versa
    
    // increment counter
    ring_counter += 1
    
    // if we are halfway, start second "circle" of rings with lower speed
    if ring_counter == 16
    {
        speed = 2
        ring_angle = 101.25° (184) ($B8)  // reset the angle
    }
}

So, the first 16 rings move at a velocity of 4 pixels per step, and the second 16 move at half that rate, or 2 pixels per step.

Regathering Rings

64 steps must have passed since Sonic was hit before he can regather any rings, scattered or otherwise.

Invulnerability

Sonic remains invulnerable for a short time after being hit. This invulnerability lasts while Sonic is flying back from the blow, and then 120 steps more after he recovers movement. During those 120 steps, he flashes on and off, spending 4 steps on and 4 steps off.

While in this state, Sonic can not collect level rings until less than 90 invulnerability steps remain.

Ring Depth

All rings, scattered or fixed, have a higher depth than Sonic, i.e. behind him. But they have a lower depth, i.e. in front of him, when they turn into sparkles.