Thursday, August 4, 2011

Descending ladders

One of the interesting things (if not the only interesting thing) about disassembling DK Jr. is that, as mentioned before, it builds on the same code used by the original DK. For example, the code that implements the fireball's AI is almost completely reused by the red traps on the "vines" and "chains" boards. In addition, the blue traps (and the blue sparks, to some extent) reuse portions of the barrel AI.

An interesting component of the barrel AI is how taking a ladder (or rolling past) is decided. Once an object is at the proper alignment to descend a ladder, the code checks a few things (if you're interested in following along, this starts at $217F).

First, the object must not be too far below the player. After all, there's not much point in taking a ladder if it's not going to cross the player's path, and it's much better to allow the barrel to scuttle off the sides of the screen and get recycled (although this is not possible for blue trap).

Second, there is a 75% chance that the process will be aborted and the barrel (or blue trap) will simply breeze by. This probability decreases as the game gets more difficult (at the highest difficulty, it's only 25%).

Third, there are checks to determine if we're likely to cross the path of the player once the descent takes place. If we're directly above the player, we always descend. If we're either side of the player and he's heading towards us, we also descend.

Notice the code makes no check to determine the slant of the girder (and hence which direction it'll take at the bottom of the ladder). It merely uses the players heading as an indication. This means, to some extent, that you can influence whether or not a ladder is taken. For example, if you want a barrel to descend rather than pass over you, you could push the joystick in the opposite direction to make it more likely that the barrel will descend and then harmlessly head off in the opposite direction. If you're on the wrong side of the ladder and you're worried a barrel will come down, you can simply stop moving and decrease the probability that it will.

Lastly, even if it doesn't appear that the barrel will cross the player's path (as described in the third step), there's still a one in four chance that it will take the ladder anyway.

As interesting as this all is, the intricacies of this process are wasted on DK Jr., since the blue traps only appear on the first board, and the logic described above only comes into play on the first platform. In fact, when a blue trap takes the leftmost or rightmost vine off the first platform, it's not even as a result of these checks (usually) . The blue sparks also have completely separate code that governs ladder descent.

Ah, well.

No comments:

Post a Comment