Announcing the end of Devember with a Billboard

For the last and final day of Devember, I present this:

Billboards announce what is happening

Billboards announce what is happening

What we’re seeing here is something I’m calling a billboard that displays on the screen and tells you what’s happening in the game. This version is less stylized than the version in the original Bolo Ball game, but everything is laid out so that this could be visually exciting; fade or fly in, fly or fade out, etc.

I was tempted to include some sound and music in this, but the more I pondered it the more I thought that the code from Devember 2015 includes all of the template code needed to have music playing per scene and sounds playing at various events. Instead of reashing that (or just stealing it outright) it seemed more in the spirit of Devember to spend time coding this other feature instead.

The Billboard entity is very bare bones at the moment; it has a visibility property that tells it if it should render itself or not and a text property that says what text it should contain. It is a specific size relative to the size of the stage and always centers itself on the stage and renders its content text centered within itself. For code clarity there are also a couple of simple methods that set the text and visibility in one step.

Some prior planning went into getting this all set up: This is why there are two “sets” of state logic; one that only triggers when we enter a state directly, and then one that triggers on every frame update. This is also why the StateMachine class has an API that allows you to test if it has spent at least a certain number of ticks in the current state (and why the state machine tracks that information at all). This allows for an easy check to determine when it’s time to hide the billboard or swap it for another one, etc.

So what we might do is say “When we enter the BEGIN_ROUND state, display a billboard that says the round name. Once we have been in the BEGIN_ROUND state for 2 full seconds, hide the billboard and switch to the MAZE_GENERATION state”. Similar code is used to display all of the billboards that are displayed for us:

  • the round number at the start of a round
  • which player will be the start player this time around
  • a notice when it is discovered that one or both players have no moves left
  • a notice that we’re about to remove all of the dead balls
  • a notice that we’re about to remove all of the gray bricks
  • a notice that we’re about to do the final ball drop now

In the same way that the state machine has a previousState field that it uses to see what state it used to be in, it now also has a nextState field as well, and the idea is the same: sometimes the logic to know where to go to next requires information on where it came from OR where some transient logic decided that it should go next.

This is used for the case where we indicate who the start player is using the billboard. Previously the act of entering the round would cause the state to jump directly to the start of the turn for the selected player. If we were to display the billboard this way, we would need to have handling code to know to hide the billboard at the start of both the computer and human player handling code. Worse, it would trigger every time they had a turn when it was really only needed once.

Our solution to this is to randomly select who will go first, set the appropriate state as what the NEXT state should be, and then skip to a newly created “we’re announcing the start player” state. Now we can just sit in that state doing nothing for a while and at the right time hide the billboard and swap to that already selected state.

I’m going to leave this code as-is (except for possible awful bugs that I might find in the next day or so), and so this draws to a close this year’s Devember coding marathon. Just like last year I had a great time working through some new code for an interesting game (although the internal structure is a little reminiscent of last year). If there was just one more day or I had found the source of one of those wily bugs a little sooner earlier in the month, we would be sitting here with a more polished (i.e. noisy sounding) prototype.

I’m pretty pleased with how everything has turned out, and to everyone that was following along, I hope you enjoyed my little rambles! You can expect a post mortem post in a week or so. For now I’m going to set aside working on video games and spend my free time playing some instead.

I’ll see you again with more regularly scheduled non-devember updates soon, and see you back here in a year’s time for our third spin through Devember, spreading a little coding joy.