Barrels drove me crazy


I'd like to share something about how I programed the barrels object.

The original game features 4 types of barrels:

1. Falls vertically

2. Rolls and falls through ladders

3. Falls diagonally

4. Rolls and falls through ladder but do not disappear when y > player.y+16


Initially I thought I could program this object in a couple hours but then it ended up being the most complex part of the game so far (except Mario himself)

The original arcade game seems to have sequences of 8 barrels with the first one being  falling vertically and the second one rolling but 'taking' the first two ladders. All the subsequent ones follow some sort of randomization about type with prevalence of the one rolling (#2). The first of each sequence of 8 will always either be a type 4 (about 80-90% if the times) or a type 1.

When a barrels is below the player, it will not continue rolling down if barrel,y > player.y +18. Type 4 barrels does not follow this rule and keeps falling down.

I initially thought to implement a control system which would set the player 'layer' based on what 'floor' he/she is at. This was working great excluding cases where player is almost at the top of the ladder hence its y can make the below barrels disappear.

However, with the purpose of fidelty to the original game I implemented the same solution that apparently was chosen at the time by the game programmer(s). The check is done when the barrel touch the layer after falling from one above, if the condition is met it disappear over the end of the screen (performing the little bounce)

Bounces! These were easy to implement.  There seem to be only 3 discrete elasticity level in the game, 4-2-1 plus zero.

Based on height of the fall the barrel will bounce with a decreasing elasticity.

With type 2 and 4 it will always be 2 with the following sequence for y coordinate:

[-1,0,0,-1,0,0,0,0,0,1,0,0,1]


All right, I think this is enough, If I had to write more details it would take too much time and I am not sure if anyone is interested.

Get Donkey Kong Redux

Leave a comment

Log in with itch.io to leave a comment.