Today’s update brings us really close to an actual fully playable game prototype! The only thing missing is a constantly applied drop force for the current capsule; currently the player has to move it down on their own. Apart from that, everything is more or less there.
So a capsule appears inside the neck of the bottle, which is outside of the content area of the bottle. The capsule is always horizontal and has randomly selected colors. The player can use the arrow keys to move the capsule left and right and drop it down, plus the ‘Z’ and ‘X’ keys to rotate the capsule left and right.
Rotation is only allowed while inside the bottle, and then only when there is nothing blocking the position that the capsule will ultimately take. For a horizontal to vertical rotation, this means that the space above the left end of the capsule has to be free. For a vertical to horizontal, this is a little more complicated (but only a touch).
When going in this orientation, the capsule will “wall kick” away from an obstruction on the left when rotating left or on the right when rotating right. Here “wall kick” just means that the position will shift over one to the left or right in order to facilitate the rotation. As such, the rotation code needs to check to see if such a kick is possible if the rotation won’t work the other way.
When a drop attempt fails because the capsule is blocked, it will insert its segments into the bottle, then trigger it to find matches. The bottle in turn will also call back to the game scene when, after an attempt to find matches, no matches are found. This is the scene’s notification that it needs to reset the capsule back to the top of the bottle and go again.
Simple game over detection triggers when the drop fails but the capsule is still outside the bottle. In this case we just clear the bottle and stop everything.
Normally, the capsule treats the bottom/left segment as its first color and its top/right segment as its second. This slightly complicates rotations that require the color order to swap around. Since there are three colors, we just treat the colors as a base three number; using the same trick to pull out the right and left colors, we can pull out the right color and multiply it by three to “move it to the left”, and then add it to the previous left color to end up with the new enum constant for the colors.
Lastly, the original Dr. Mario allows you to rotate the capsule from horizontal to vertical even in the top row of the bottle; when this happens, the upper segment appears outside the bottle, but if the drop stops there, gets truncated away. Our little version here does the same. We render the upper segment with some alpha transparency in this case so that it’s more visually distinct. This also paves the way for our ability to show a “ghost capsule” on the bottom of the bottle to show you where the current capsule is going to end up.
The next steps will be to add the automated dropping and clean up the input a little bit. Right now capsule changes can only happen in the update loop, which is cleaner but makes the movement a little chunky due to the timing I put in place to stop a movement update from happening in every frame update. I have a potential solution to this, but I ran out of time to implement it.
Once these two things are done, the prototype is playable on its own, although it still has no scoring or sounds. Still, progress!

User controlled capsules are in!