Game Over, Man! Game Over!

Once again just a small set of simple changes; busy day with holiday errands which also included taking the car in for servicing and having the dog fluffed and folded (no starch, though). Additionally, super early morning trip across the border is planned, so early bed time as well.

In any case, Rx changes! There is now a display of the upcoming capsule, and a simple game over screen that uses some rendering tricks.

The next capsule is pretty simple overall; create a second Capsule entity positioned below the level number, hidden while the game is not actively running (viruses are generating or the game is over). When it comes time to randomly select the next capsule, instead of generating it directly to the user controlled capsule we copy the type of the next capsule to it and then randomly generate the other one.

I guess this shows a great use for OOP style or what have you, since all of the magic for drawing the capsule is en-capsule-ated (groan) and easy to re-use. I’ve always found this kind of pattern useful long before I knew anything about OOP though, like back in my Pascal days. I tend to refactor redundant code with wild abandon, which is something that I’m trying to curtail a bit with my game development as you can go pretty crazy with that sort of thing.

The other change is that there is now a game over scene. My “engine” supports multiple scenes by just having the stage invoke the update() and render() methods for the current scene, as well as telling a scene when it is being activated or deactivated.

In main we create a game over scene, and in the main game scene we switch to it when the game is over. The game over scene switches back to the game scene when you press a key; simple.

One little “trick” I’m using here is that when the game over scene becomes active, it keeps a reference to the previous scene, which it assumes to be the game scene. In its render method instead of clearing the screen it calls the render method of the other scene (or as a fallback clears the screen if it doesn’t know what the previous scene is).

This allows us to just display some options right over top of the final state of the game, depicting the empty bottle and final score and level, without having to recreate how that is rendered.

Tomorrow I want to include a simple title screen that allows you to select the game level before you start, and if I have time, alter the game over screen to allow you to try again (go back to the game) or quit (go back to the title screen). Hopefully I will have time for all of that.