Since I’d like to discuss barrel introductions (the process of which is surprisingly complicated) , I’m going to limit my ramblings to just DK for the moment.
Firstly, barrel introductions are divided into two subroutines. The first (at $2C03) essentially files requests, and the other (at $2C8F) fulfills requests by animating DK grabbing the barrel and either throwing or rolling it out. Requests are only considered handled after the barrel is released — no new requests can be filed during this time.
The first three requests are very specific. The first barrel is immediately requested, and must always be thrown. The whole process takes only about 26 frames — less than one second. As soon as DK drops the barrel, a new request is put in for the second barrel, followed by the third barrel. These two barrels are ALWAYS rolled out. The code specifically forgoes the 1 in 16 random check to request a barrel be thrown.
The rest of the barrels, up to a point, are requested about once every half second. However, since it takes a little over a second and a half to actually animate the launching sequence (unless throwing, which is slightly faster), barrel requests can never be serviced at this rate. Apparently, the programmers attempted to increase the frequency of barrel introductions as the game difficulty goes up, but because requests cannot be made while barrels are being launched, the check at $2C1B has only very subtle effects on the timing of requests and launches.
There’s an interesting check at $2C33 that allows for a 50-50 chance to abort the request if the barrel stack is now half depleted. Apparently, this was intended to give the player a break after the initial onslaught of the first half. Another check involving the barrel stack occurs at $2CE6. This causes the barrel stack to the left of DK to disappear one by one as the last four barrels are launched. Since the bonus counter is decremented once every barrel launch, the barrel stack vanishing is a visual indicator of the last six seconds or so before the player dies.
Next up I’ll attempt to explain how the barrel introduction code has been “hijacked” by DK Jr. to introduce blue traps and sparks. The whole thing is an unfortunate mess that I’m certain even the original programmers poorly understood.