Concealing the Respawn Time…

Newspaper spin and headlines sprite sheet.png
The spinning newspaper animation spritesheet.

As I mentioned in last week’s blog post, respawning of enemies takes some time to perform, roughly a few milliseconds to a a couple of seconds depending on how many enemies being spawned. This meant that the game would freeze while the RespawnEnemies function would run; not a very elegant or immersive procedure.

 

After discussing this problem with my group, we remembered a cut feature planned during early development: A spinning newspaper that was supposed to appear between levels and add flavour to the setting by describing the ongoing events of the game, with humour.

There were already art assets for its animation and a few different variant headers for the final frame. Although they were without a picture, this was easy enough for the art department to finalize, even making a little fanfare sound to play while  the animation would run.

So, now that the feature was planned for and its assets complete, I would still need to implement it in the code. As the function for respawning enemies takes some time to complete, it would need to run during the last frame of the animation as to not halt it.

When the player returns to the starting area of the map, the game pauses and a bool related to the newspaper animation and enemy spawning is set to true. This allows the game to continue looping through the Update function to reach the Draw function necessary for animation, while disabling player and enemy movement. In addition, the fanfare sound starts playing as soon as the bool is true.

An sf::Clock is used to measure the length of the frames, the last frame sticking around for a couple of seconds; otherwise the text on the newspaper might be difficult to read if there are few enemies to spawn. When the timer of the last frame is finished, the bool checking the function is set to false, allowing the updating of the game to proceed as normal.

The newspaper is animated with the Animation function I’ve described in one of my previous blog posts, but as the last frame is reached, the texture containing the spinning newspaper spritesheet changes to image with the different newspapers. One of the five newspapers are chosen based on an int set to Rand % 4 + 1, giving a random number between 1 and 5.

newspapers.png
The different variations of newspapers that might pop up: Nothing like a little humour to cover up the limits of your programming…

About Erik Nord

2015 Programming