Author Topic: Spring Theory  (Read 49780 times)

0 Members and 1 Guest are viewing this topic.

Offline xelnia

  • Administrator
  • Spring Jumper
  • *
  • Posts: 2869
  • Stop using 0.106
    • Twitch
    • Awards
Spring Theory
« on: September 01, 2013, 07:58:28 am »
Ever since I started playing DK I've been fascinated with the elevator stage. Of all the boards, it truly is the only one on which no player should ever die. However I still find myself dying, as do even the best players. I decided to take a closer look at the stage when the code for the game was posted on the forums. What follows in this post, and probably the several after it, is a technical, code-level analysis of the springs. Since I'm not a programmer, engineer, or math expert I apologize up front for any mistakes or inconsistencies in the terminology and presentation. I encourage everyone to dig in, double-check my work, and break it down even further.

Let me also state that I don't think any of the following information will be groundbreaking or crucial for most players, especially beginners. This is just an extraction of information that lies in the code and is intended for those of us who enjoy looking under the hood.? I won't be delving too deep into actual spring strategy, but hopefully this post will get the wheels churning and someone will see something useful.

I used a variety of methods to gather this information. Starting with the DK code posted by Jeff Willms, I used WolfMAME 106, 140, and 149 and a variety of save-states to analyze the spring behavior in Donkey Kong US Set 1 and D2K: Jumpman Returns.

This post is concerned with the actual springs themselves. Hopefully further analysis on fireball movement, leeching opportunities, elevator movement, etc. will come later.

Spring Basics

Rate of Generation

First and foremost, how often are the springs generated? Each new spring corresponds with the Bonus Timer ticks and one spring is generated for every 100 that the timer decrements.

Spring Generation:
Level 1 (Japan Set, D2K) = Every 120 frames, or 2 seconds. 3 extra at 000 Bonus. 52 total.
Level 2 = Every 100 frames or 1.667 seconds. 3 extra at 000 Bonus. 62 total.
Level 3 = Every 80 frames or 1.333 seconds.4 extra at 000 Bonus. 73 total.
Level 4+ = Every 60 frames or 1 second. 5 extra at 000 Bonus. 84 total.

Each spring has a life of 180 frames. The beginning and end of this life cycle occurs off-screen. Depending on the length and scrunchiness of the spring, it can spend anywhere from 1 to 9 frames off-screen before it makes its appearance. All springs take 25 frames (inclusive of their off-screen movement) to make their initial on-screen landing near Kong's feet. They then bounce along for another 75 frames before entering their falling state, which lasts a further 56 frames before they disappear off the bottom of the screen. At this point they still exist in the code, but only for 24 frames before their memory location is used for the next spring. This timing occurs for every spring, regardless of level. The only difference between levels is how often the springs are generated.

Spring Path

From here on out, please note that x-values INCREASE as Jumpman moves to the right, and y-values DECREASE as Jumpman moves up.

Every spring follows the same parabolic path. The 25 y-values for this path are as follows (in hex):
50 4D 4A 47 45 43 41 3F 3E 3D 3D 3C 3C 3C 3D 3D 3E 3F 41 43 45 47 4A 4D 50

This pattern repeats until the spring falls. You'll notice that at the beginning and end of the path the spring is at y=50. This causes the spring to slide along the girder for two frames every time it lands. This has the potential to make two different springs appear to be the same, depending on when the player processes the landing animation. Springs move 2 pixels horizontally every frame during the bounce phase, and their vertical distance varies depending on where they are in their path. During the falling phase, springs drop at a rate of 3 pixels per frame.

A simple graph of this movement looks like this:



Spring Length

Now, the spring quality that most people are interested in: length. I will use the numbering system that Dean Saglio used in his pop quiz: 0 for the shortest spring and 15 for the longest.

Springs can be generated in one of 16 locations. They always start, off-screen, at y=50, but their x-value can be any of 16 points, each separated by 1 pixel. Technically, spring Types 0 through 7 are actually generated on the right side of the screen. The shortest spring, Type 0, initially bounces to the left of the elevator pulley and has an x-value (hex) of 28 when it lands. The longest spring, Type 15, has a value of 37. So, the initial landing spot (near Kong's left foot) of all 16 springs shakes out like this:

Type 0: 28
Type 1: 29
Type 2: 2A
Type 3: 2B
Type 4: 2C
Type 5: 2D
Type 6: 2E
Type 7: 2F
Type 8: 30
Type 9: 31
Type 10: 32
Type 11: 33
Type 12: 34
Type 13: 35
Type 14: 36
Type 15: 37

Here is an animated GIF that demonstrates the initial landing spots for all 16 springs.



Getting Up Pauline's Ladder

Once you've traversed the lower obstacles and made it up to Kong's girder, all that remains is to navigate the springs and rescue Pauline. There are various strategies for doing this, but they all boil down to one fact: you must get close enough to the ladder on one spring so you have time to ascend the ladder before the next spring hits you. The amount of wiggle room you have varies depending on the level and the type of springs that are bouncing your way.

The following information is mostly about what is theoretically possible in a pixel-perfect, frame-by-frame world.

Safe Spots and Pauline's Ladder

The two safe spots are each 13 pixels wide. These safe spots are areas where no spring will ever hit you. The edges of these safe spots are determined by the shortest and longest springs. The longest spring (15) determines the LEFT edge of the safe spots, and the shortest spring (0) determines the RIGHT edge.

The 1st safe spot extends from x=A7 to x=B4. For reference, Jumpman's position when he ascends the ladder to Kong's girder is x=B3. The edge of Kong's girder is x=BB. So, there are actually 7 pixels of danger to the right of Jumpman as he stands in the 1st safe spot...but why would you be going in that direction anyway? ;)

The 2nd safe spot extends from x=75 to x=82. The center of Pauline's ladder is at x=93, but since the ladder is 8 pixels wide (x=90 to x=97), it is actually offset to the left.

As stated above, these two areas are permanent safe zones. However, the edges of these zones can shift as different springs enter the screen. Below is a table of how the x-value for each safe spot’s inner edge shifts for every spring.

Type     1st Safe Spot  2nd Safe Spot
Type 0   98             82
Type 1   99             83
Type 2   9A             84
Type 3   9B             85
Type 4   9C             86
Type 5   9D             87
Type 6   9E             88
Type 7   9F             89
Type 8   A0             8A
Type 9   A1             8B
Type 10  A2             8C
Type 11  A3             8D
Type 12  A4             8E
Type 13  A5             8F
Type 14  A6             90
Type 15  A7             91


It's easy to see that running right up to the ladder is possible on the longest and shortest springs, depending on which safe spot you're in. As each spring shifts the safe spot, Jumpman can get a "jump" on the ladder, of varying lengths, which increase the odds of making the final run up to Pauline.

Here are some related graphics:

This graphic needs a little refining. The spring paths are basically showing the path followed by the bottom center of each spring.






There are also safe spots ON Pauline's ladder.

As most players know, certain springs reach higher than others and can collide with Jumpman even when he's almost to the top. When Jumpman is standing at the bottom of the ladder, his sprite is centered at y=50. He moves up the ladder in 2 pixel increments and when he reaches y=30 he has reached the top. However, Jumpman only needs to reach y=38 to be safe from all springs.

I advise everyone to check out Ethan Daniels' hitbox diagram in order to get an idea of how much space is needed to avoid the springs:

https://donkeykongforum.net/index.php?topic=493.msg8905

Below is a table showing each spring type, the extreme x,y coordinates for Jumpman and each spring when they collide on the ladder (essentially the boundary Jumpman must cross to survive), and the y-value Jumpman must reach in order to be safe for each given spring.

                             Ladder Collision:                              Spring
        Landing "x" - [Spring "x,y"/Jumpman "x,y"] - Jumpman Safe "y" - Collision Direction - 1st Safe Spot - 2nd Safe Spot
Type 0      28            98,43         93,3C             3A                  up                   98              82
Type 1      29            97,45         93,3E             3C                  up                   99              83
Type 2      2A            98,45         93,3E             3C                  up                   9A              84
Type 3      2B            97,47         93,40             3E                  up                   9B              85
Type 4      2C            98,47         93,40             3E                  up                   9C              86
Type 5      2D            97,4A         93,44             42                  up                   9D              87
Type 6      2E            8E,4A         93,44             42                  down                 9E              88
Type 7      2F            8F,4A         93,44             42                  down                 9F              89
Type 8      30            8E,47         93,40             3E                  down                 A0              8A
Type 9      31            8F,47         93,40             3E                  down                 A1              8B
Type 10     32            8E,45         93,3E             3C                  down                 A2              8C
Type 11     33            8F,45         93,3E             3C                  down                 A3              8D
Type 12     34            8E,43         93,3C             3A                  down                 A4              8E
Type 13     35            8F,43         93,3C             3A                  down                 A5              8F
Type 14     36            8E,41         93,3A             38                  down                 A6              90
Type 15     37            8F,41         93,3A             38                  down                 A7              91




Jumpman's Movement

An important, albeit code-level, factor in approaching the spring stage is that when Jumpman is puttering around the board, his sprite has an internal value that is constantly changing and he actually pauses every third frame. There's more on this here: https://donkeykongforum.net/index.php?topic=383.msg6904;topicseen#msg6904

Essentially, memory address 620F is a movement indicator (this is the comment for this location in the code posted on DKF) and counts down 2-1-0, one value per frame (1/60 second), repeatedly, while running. Value 2 is when the sprite changes and Jumpman pauses, values 1 and 0 occur when Jumpman is actually moving. When climbing a ladder the same memory address counts down 4-3-2-1-0. For values 3-2-1-0 Jumpman is stationary on the ladder, and when the value reaches 4 again he moves up the ladder 2 pixels.

Why is this important? When standing and waiting to make a move on the springs, the value stored in 620F determines how soon Jumpman will move after you make a joystick or keyboard input. If the value is 2 or 1, he will move right away. If the value is 0, there will be a dead frame where the value changes to 2 and the sprite is updated before any movement occurs. More importantly, this effects the point at which Jumpman can climb the final ladder. Jumpman can NOT climb a ladder until 620F reaches 0. So, if he reaches the left edge of ladder, but 620F is at 1, it will take one extra frame to start climbing the ladder regardless of the timing of the up input. This can have huge ramifications if one does not corner up the ladder as described by Dean here: https://donkeykongforum.net/index.php?topic=429.msg7645#msg7645

What Does It All Mean? (aka TOO MANY WORDS JUST POST PICTURES JFC)

To determine which spring combinations are passable, I asked myself the following questions:

1) What are the minimum frame requirements to get from each safe spot on the girder to each safe spot on Pauline's ladder?

2) How long must I wait after each spring passes over Jumpman's head, in both the 1st and 2nd safe spots, before I can make my approach to the ladder?

3) How long has the trailing spring been heading my way while I wait for my opportunity to ascend the ladder?

Let me reiterate that this is all about what is technically possible, not necessarily practical.

Due to the sprite values discussed earlier, there are 3 possible answers for every location in Question 1. For example, running from 2nd safe spot x=82 to ladder safe spot y=38 can take 76, 77, or 78 frames.

For Question 2, you must wait for the spring to pass over your head by 2 frames/4 pixels in the 2nd safe spot before you can run. So, if you're standing at x=82, you must wait for the spring to be at x=88 before you can run. In the 1st safe spot, you must wait at least 3 frames after the spring bounces in front of you before you can run. This is all assuming you've given yourself the maximum jump allowed by each spring type.

The exception to these numbers are the two longest springs, 14 and 15. Since you can wait at the left edge of the ladder for these springs to pass, you can press up as they pass you. However, cornering a ladder this way automatically warps you to the middle of the ladder. In the case of a Type 14, this is x=90 to x=93. For a Type 15, it's x=91 to x=93 (but you might as well just wait at x=90...it doesn't make a difference for a Type 15). This warp necessitates waiting an extra frame before climbing the ladder. Therefore, Types 13, 14, and 15 all have the same wiggle room when sneaking between springs from the 2nd safe spot. This extra frame of waiting also explains the D2K killscreen. A pixel-and-frame perfect run up the ladder requires 1 extra frame of waiting, and is 1 frame short of reaching safe spot on Pauline's ladder. One f***ing frame!!!

For Question 3, the trailing Level 4 spring has been headed your way 13 frames by the time you can make your move from the 2nd safe spot, and 14 frames by the time you can make your move from the 1st safe spot. On Level 3, the trailing spring has yet to be generated, still needing 7 frames or 6 frames depending on safe spot. Level 2 springs need 27 or 26, and Level 1 D2K springs need 47 or 46 frames to be generated.

For example, on Level 4 I'm waiting in 2nd the safe spot and I see a Type 12 spring. I move into the most ideal position (x=8E), and as it passes me I run for the ladder and see that a Type 4 spring has landed and is on its way. In this case, I only need 43 frames get to the safe spot on Pauline's ladder (for Type 4, y=3E). It takes a Type 4 spring 79 frames to reach Jumpman on the ladder, but since it's already been heading my way for 13 frames before I can run, it only needs 66 more frames to reach the ladder. 66 frames minus the 43 I need to reach the safe spot = 23 frames of wiggle room.

Instead of pasting my enormous collection of thousands of data points, I will try to summarize my findings below in the graphics below.

First, find the Type of spring that is the leading spring in the vertical column on the left. Then, move horizontally to find the Type of spring that is the trailing spring. Where the two rows intersect is the wiggle room, in frames, that you have to complete the run up the ladder. Cells that are colored orange are spring combinations that may or may not be possible depending on Jumpman's sprite value at 620F when you make a run for it. Referring to the example above, use the L4 chart and find "12" row in the left hand column of the "2nd safe spot" chart. Then follow it over to "4" column, and you'll see that 23 frames is the amount of wiggle room to pass a [12,4] combo.

I will end this post with these graphics because 1) my brain is full, and 2) I want to give people a chance to digest all of this and suggest corrections, additions, etc.

Other things to address:
1) Does scrunchiness matter? (no)
2) How many possible combos can you pass in order to get from the 1st safe spot to the 2nd?
3) Could jumping springs be realistically incorporated into the game?

Level 1 (Japan Set, D2K) Combos



Level 2 Combos



Level 3 Combos



Level 4 Combos



tl;dr. wait for a long, then go on a short.

Edit: Fixed some not good grammar. Clarified a couple of paragraphs. Changed the link to Ethan's hitbox diagram.
« Last Edit: February 21, 2020, 08:16:10 pm by xelnia »
"Do not criticize, question, suggest or opine anything about an upcoming CAG event, no matter how constructive or positive your intent may be. You will find nothing but pain and frustration, trust me. Just go, or don't go, and :-X either way!" -ChrisP, 3/29/15
Member for 11 Years snek CK Killscreener IGBY 2016 DKF Team Member IGBY 2015 DKF Team Member IGBY 2014 DKF Team Member DK Killscreener Blogger Twitch Streamer

Offline f_symbols

  • Spring Jumper
  • *
  • Posts: 835
  • wht u mean
    • Awards
Re: Spring Theory
« Reply #1 on: September 01, 2013, 08:10:17 am »
Love it  :o  Thanks mate!  The collision chart implies a need to learn comfort with springs #4-9 as they require the least y-value clearance...
« Last Edit: September 01, 2013, 08:20:15 am by f_symbols »
Member for 11 Years IGBY 2016 DKF Team Member Winner of a community event Former DK Remix World Record Holder DK Remix Killscreener IGBY 2015 DKF Team Member DK 1M Point Scorer IGBY 2014 DKF Team Member Blogger DK Killscreener Twitch Streamer

Offline marinomitch13

  • Spring Jumper
  • *
  • Posts: 1806
    • How to Play DK
    • Awards
Re: Spring Theory
« Reply #2 on: September 01, 2013, 08:21:27 am »
I'm blown away.

Love the 'tl;dr' comment. Thanks a TON Jeremy.
"Thou hast made us for Thyself, and our heart is restless until it finds its rest in Thee." -Augustine, Confessions.
Member for 11 Years IGBY 2015 DKF Team Member DK Killscreener Blogger Twitch Streamer

Offline Bliss1083

  • Elite Member
  • *
  • Posts: 291
    • Awards
Re: Spring Theory
« Reply #3 on: September 01, 2013, 09:14:31 am »
I've been working on the Right of the ladder climb for awhile now. Weird how now others are looking at this too! Def. Gain a lot of points from it
Donkey kong  arcade 867,000 kill screen
Donkey kong arcade 1-1 12,800 12,200 12,100 and 12,000
Donkey kong end of level 4 132k
working on my hello kitty island adventure skills
Member for 11 Years DKJR Killscreener DK Killscreener Blogger Twitch Streamer

Offline JNugent

  • Senior Member
  • *
  • Posts: 239
  • Just a guy who likes to play games.
    • Awards
Re: Spring Theory
« Reply #4 on: September 01, 2013, 11:01:45 am »
I'm freaking impressed Kappa.

567,200 - Crazy Kong (MAME) - ended on L=21 rivets
555,000 - Donkey Kong (MAME)
Member for 11 Years Twitch Streamer Blogger

tom bradley

  • Guest
Re: Spring Theory
« Reply #5 on: September 01, 2013, 11:15:05 am »
Thanks for posting that for the community Jeremy! Although I probably misunderstood what you meant by the 16 springs, I'm sure there are springs that go further than the ones on the gif you provided?

Drunkguy89

  • Guest
Re: Spring Theory
« Reply #6 on: September 01, 2013, 11:34:32 am »
Yeah, huge amount of detail and effort in this, good job Boss  8)

SQUIIDUX

  • Guest
Re: Spring Theory
« Reply #7 on: September 01, 2013, 03:45:03 pm »
GDAMN MAN :o :o :o

Offline f_symbols

  • Spring Jumper
  • *
  • Posts: 835
  • wht u mean
    • Awards
Re: Spring Theory
« Reply #8 on: September 01, 2013, 05:30:55 pm »
Thanks for posting that for the community Jeremy! Although I probably misunderstood what you meant by the 16 springs, I'm sure there are springs that go further than the ones on the gif you provided?

Tom, there are ONLY 16 different spring types with regard to where they land on the girders, all springs will land within a 16 pixel range (x-value), the shortest is termed "0" and the longest is termed "15", then, they travel a set distance, on a set arc, between each bounce, the distance traveled is "fixed" and the only variable is where the spring first landed; the overlay image summarizes this well, it shows all 16 possible landing spots and the respective paths thereafter.
« Last Edit: September 01, 2013, 05:35:24 pm by f_symbols »
Member for 11 Years IGBY 2016 DKF Team Member Winner of a community event Former DK Remix World Record Holder DK Remix Killscreener IGBY 2015 DKF Team Member DK 1M Point Scorer IGBY 2014 DKF Team Member Blogger DK Killscreener Twitch Streamer

dru

  • Guest
Re: Spring Theory
« Reply #9 on: September 01, 2013, 10:45:17 pm »
Holy sheets of foil wrapped delicious brownies. This is an awesome guide, well done!  ;D

Offline xelnia

  • Administrator
  • Spring Jumper
  • *
  • Posts: 2869
  • Stop using 0.106
    • Twitch
    • Awards
Re: Spring Theory
« Reply #10 on: September 01, 2013, 11:04:41 pm »
Love it  :o  Thanks mate!  The collision chart implies a need to learn comfort with springs #4-9 as they require the least y-value clearance...

Indeed. Dean has mentioned how he always thought there was a "sweet" spot somewhere in the middle, and I think that 5 and 6 are your best friends. 5, 6, and 7 all have the same y-value clearance, but 7 can nab you one frame sooner than 5 and 6.
"Do not criticize, question, suggest or opine anything about an upcoming CAG event, no matter how constructive or positive your intent may be. You will find nothing but pain and frustration, trust me. Just go, or don't go, and :-X either way!" -ChrisP, 3/29/15
Member for 11 Years snek CK Killscreener IGBY 2016 DKF Team Member IGBY 2015 DKF Team Member IGBY 2014 DKF Team Member DK Killscreener Blogger Twitch Streamer

Offline muscleandfitness

  • Pie Kicker
  • Elite Member
  • *
  • Posts: 328
  • Wall jump WR Holder x3
    • Awards
Re: Spring Theory
« Reply #11 on: September 02, 2013, 01:00:49 am »
wht da im lost after the first word.. fkkkk
59 wall jumps new world record on mame
55 wall jumps on a cab New World Record
longest convener ride in dk history New World Record
World Record for standing behind oil can until end of lev
A Reverse finish on Rivet  board. 12 ks's HS 992900
Member for 11 Years IGBY 2016 DKF Team Member IGBY 2015 DKF Team Member DK Killscreener Twitch Streamer

tom bradley

  • Guest
Re: Spring Theory
« Reply #12 on: September 02, 2013, 01:24:33 am »
Thanks for posting that for the community Jeremy! Although I probably misunderstood what you meant by the 16 springs, I'm sure there are springs that go further than the ones on the gif you provided?

Tom, there are ONLY 16 different spring types with regard to where they land on the girders, all springs will land within a 16 pixel range (x-value), the shortest is termed "0" and the longest is termed "15", then, they travel a set distance, on a set arc, between each bounce, the distance traveled is "fixed" and the only variable is where the spring first landed; the overlay image summarizes this well, it shows all 16 possible landing spots and the respective paths thereafter.

Thanks for explaining that Ethan, I really wasn't getting that one bit :P.

hchien

  • Guest
Re: Spring Theory
« Reply #13 on: September 02, 2013, 08:11:08 am »
Bookmarked.  Awesome awesome job. 

I still haven't read through the entire post, but I'll share some of my observations (since I know some of you, ahem Vincent, aren't very good with numbers):

1- The 2nd spring is more important than the 1st spring

I have felt this way for a long time.  I posted this "hunch" on cagdc/old tg forums a few times, but never had any concrete evidence for it.  If you look at the chart titled "L4 2nd safe spot wiggle room", you'll see a 2 pixel change in the 2nd spring results in a large difference in the range of 1st springs which are green, but in the reverse situation the difference is smaller.

2- No matter how good of a jump you have, if you get a very long 2nd spring (14 or 15) you will never make it up.

I was never sure if this was true or not.  I knew it was very close.  Now I know!

3- It is easier to finish the board from the 2nd safe spot than the 1st, but not by much!

Does this mean we should be attempting to finish the board from the right more often?

Offline stella_blue

  • High Score Moderator
  • Spring Jumper
  • *
  • Posts: 1530
    • Awards
Re: Spring Theory
« Reply #14 on: September 02, 2013, 09:37:53 am »

Jeremy, allow me to join the others in commending you on an excellent and thorough analysis.

Could we please have 206 additional sets (in color, collated, and bound) by 9:00 AM tomorrow for our annual convention?  We currently have 204 forum members, but I'm operating under the assumption that Vincent will lose his copy, twice.

I'll arrange for delivery of 8 dozen "South of the Border" ultimate nachos platters.

DK High Score 
1,064,500
  (L22-1)
DK Level 1-1 
13,400
DK No Hammer 
535,300
  (L15-2)
Member for 11 Years Most Time Online DK 1M Point Scorer DK Killscreener Blogger Twitch Streamer