The Hullet Bells – Part 3 (Handling It)

Handling transitions between various screens was one of the problems my friends and I encountered when developing our shmup game at university. For instance, it was a pain getting the game flow moving from the title screen to the game screen, from game screen to loading screen, and so on.

Because of the way we initially structured the main loop, it was pretty awkward to shoehorn in these transitions. We ended up with this system where the title screen would come up, and part of its main loop would have a call to the game screen’s main loop. Effectively, we were two loops deep whenever we were running the game. It’s not exactly inefficient, but it’s not pretty. The answer I discovered during my internship, long after the project died, was relatively simple. Rather than treat these screens as different loops to jump between, I implemented a system which only uses one loop. This loop repeatedly calls the update function of the current handler. Handlers are the abstractions of each screen, containing their loop logic, assets and so forth. They derive from a common base class and override its update function. It’s quite a simple approach to arrive at, but when you’re just starting out you tend to prioritise the wrong things. Learning about this pattern in a professional environment was a definite boon. It was also probably covered at university (under the much more general polymorphism), but seeing the practical use cemented it in my mind. Later, I would use this approach when designing the platform game. It was so good, it was carried over to my current project.

Here’s the base class for handlers:

class Handler(object):
  # Handlers are the wrappers for the more separated parts of the game,
  # like the title screen, the main game screen, the game over screen..
  def __init__(self, game):
    self.game = game
    self.running = True

  def update(self):
    print("Default handler")
    return True

And here’s a snippet from the title screen handler:

class TitleScreenHandler(Handler):
  ...
  def _draw(self):
    self.game.screen.blit(self.background, (0,0))
    self._drawText()

  def _logic(self):
    for button in self.buttons:
      button.update()

  def _handleInput(self):
    self.inputHandler.update()

  def update(self):
    self._draw()
    self._logic()
    self._handleInput()
    return self.running

And of course, the part of the main loop responsible for calling the handlers in the first place:

def main():
  ...
  while True:
    # Cap the frame rate.
    clock.tick(60)

    # Run the game handler.
    if not game.handler.update():
      break

    # Show our hard work!
    pygame.display.flip()

As you may have noticed, the current handler is stored as part of a Game variable. The game class is meant to carry over cross-handler information. Normally we’d expect it to store some sort of game state, but most of the information is stored inside the handler. This Game object is passed in to the handler on creation, allowing a handler to transition to another by simply altering the current handler itself. Thanks to some behind-the-scenes Python magic, these self-orphaned handlers are cleaned up and not left hanging around.

Here’s an example of how we might transition (very quickly!) from the title screen handler to the game screen:

class TitleScreenHandler(Handler):
  ...
  def _startGame(self):
    self.game.handler = GameScreenHandler(self.game)
  ...

It’s pretty simple, right? We make sure the game state is passed on so further transitions can be performed. This system also allows us to do some clever things, such as allowing us to run handlers within handlers. For instance, if we wanted to create a loading handler such that the current handler continued running until some number of assets were ready, we could write something like:

class LoadingScreenHandler(Handler):
  ...
  def update(self):
    if (self.loading):
      self.currentHandler.update()
    else:
      self.game.handler = self.nextHandler
  ...

Here the loading handler runs its own handler before transferring control to a target handler after asset loading has finished (probably via a thread). Of course, this is getting ahead of ourselves: we have no assets! Indeed, we won’t for a good while yet. Rather, we now have the framework for implementing the many screens of the game. Next time, we’ll look at the title screen and input system in more detail.

The Hullet Bells – Part 2 (Getting Organised)

Recently I embarked upon a quest: a quest to produce a platform game, the likes of which the world had never known. However, I got bored of that, but not before exercising my Python chops. Although I failed, I discovered the wonderful pygame library. Pygame is a Python wrapper for the ever-popular C++ SDL library, which I had used before when working on a small game project with a group of university friends. Much like the project preceding this one, the university project died an untimely death, this time due to heavy college workloads.

Still, both experiences provided a great number of learning opportunities, and during university a six month placement at a video game company let me take a peek under the hood of some pretty heavy AAA title stuff. I took what I learned then and tried to apply it to the platform game, but a general lack of interest on my part meant the project had no chance of survival.

Thinking back, there’s only been two genres I’ve really ever fallen in love with: Platforming and shmups. Sure, I’ve had my flirts with RPGs, particularly JRPGs. As I’ve grown however, I just don’t find them nearly as charming as I used to. Recently, I went back to Final Fantasy 7 to give it a proper playthrough, this time around older and wiser. I figured I might be able to appreciate the combat and magic systems a bit more, because now I’m a more patient, understanding guy. Sadly, I also have a lot less time than I used to, and it turns out those systems never had any depth after all: It was all just grinding in the end, like pretty much every other RPG I’ve ever played.

So I’ve come to appreciate the platformers and shmups. With less time to spend on leisure than ever before, it’s important to me that I maximise the enjoyment I get from the limited time I spend on games. Don’t misunderstand, I do branch out occasionally with new releases outside my comfort zone! But when I need to relax, being able to pick up a platformer and speed through it means a lot. The average shmup won’t take more than an hour per playthrough, so you already know in advance how long you’re likely to spend on it (Side note: There are some insane examples of shmups with multiple ‘loops’, meaning you start back and play through again on an increased difficulty level. These can take several hours to fully beat, and must generally be done in one sitting!).

Why did my platforming game die? I’m not sure myself. I think there was a deadly combination of boredom and laziness. While I’d love to get in to the Procrastination Formula, that might be a topic for another time. The short of it is; I didn’t block time to get my teeth in to it, and when I did have time I wouldn’t develop the right features to bring it towards a minimum viable game. Rather, I spent time developing fluff features like ladders or tweaking values that could wait until later.

This time around, there is a system. I intend to spend at least 25 minutes a day focused on this shmup engine, more if I’m on a roll. I have also mapped out some of the key requirements for what will constitute a complete shmup. In a somewhat mock-Agile approach, these requirements take the form of one-line user stories grouped by screen (title screen, game screen, options screen, etc.).

Having once taken a half-day Agile course, I’m something of an expert on the topic. I can do away with that separation of product owner, scrum master and development team garbage because I am in fact all three! Indeed, this is why I call this shaky approach ‘mock-Agile’, because I’m making a mockery of it. That said, taking parts of Scrum seems to work even for a one-man dev team. Here’s an example of the embarrassing list of requirements I came up with:

Title Screen

  • I want to be able to navigate a menu at the start of the game
  • I want to be able to start the game via the menu
  • I want to be able to quit the game via the menu

It might look silly and insignificant, but this sort of thing keeps me on task and aware of what needs to be done. At this point, you may be wondering if I’ve even done any development yet, what with all the mocking and pondering. Well, take a look at this!

The white box is the player, the green box is a baddie, and the blue one is a bullet! This is cutting edge stuff, guys.

The white box is the player, the green box is a baddie, and the blue one is a bullet! This is cutting edge stuff, guys.

Prior to finally buckling down and properly organising myself, I did a bit of development on and off, tearing bits out of the platform engine and transplanting them in to the shmup. In all, I estimate that about four to five hours of actual work went in to the shmup over the course of a month. It’s time to buckle down and make something. Next post I will give you a sneak peak behind the scenes of how I’ve structured the game.

Beginning Chess

Back in secondary school, I was part of an ill-fated three man chess club. We were terrible. Our supervisor, while well intentioned, was beatable by complete rank amateurs (read: us). It was not an environment under which we could grow as players, but we were having a blast, so who cared?

Fast forward over ten years. Now in my mid-twenties, with zero chess experience since then, I came across an article on Hacker News with the straightforward title ‘How to get Good at Chess, Fast‘. Having barely thought of the game in the intervening years, the link piqued my interest. I could feel my competitive side stirring. With a single click I was drawn back in to the domain of rooks and knights.

It turns out that there’s quite the system to becoming a good chess player. Like you’d expect, a key component is a willingness to play the game! What may be surprising is the amount of tactical study required to made any sort of headway (of course, there are prodigies who learn incredible amounts from their own games with little effort). Strictly speaking, you are not studying to memorise: one is aiming to train their pattern recognition abilities by observing and reasoning about thousands of positions. By doing so, they begin to gain an intuitive grasp and understanding of the game, allowing the skilled player to analyse a board and next few moves with a reasonable amount of insight. Being able to accurate determine the consequences of a particular move, and being able to use those consequences to gain material (win pieces) is known as being capable of tactical play. Tactics are short-term, sometimes two moves in length, often more. If you know that an opponent must react in a certain way in response to your play in order to maintain the material balance, get out of check, or avoid checmate, such tactics are said to employ forcing moves.

But perhaps this is learning to run before one can walk. Also put forward in the article is the idea of training the eye to automatically see certain tactical positions instantly, with such a skill granting a great boon when getting through the aforementioned thousands of exercises. Without such an ability to pinpoint the so-called forks and skewers, a player would spend far longer on the exercises than would be desirable for fast growth. By training the eye, certain opportunities arise automatically.

I’ve been applying the principles set forth in the article, and indeed I have noticed an increase in my tactical ability! The sheer number of exercises involved means memorisation is all but impossible, so subsequent attempts continue to directly test your tactical skill. The article recommends a full seven rounds of the exercises you choose to do. I’m working my way through Chess Tactics for Beginners. I’ll write up a review of it one of these days, but here’s a look at one of my favourite positions so far:

Chess is sometimes pretty cool!

I won’t spoil it, but the objective is to win the black rook, white to move.

Despite my tactical practice, I have yet to win a single game on the popular lichess website, making huge strategic blunders in the mid game. Indeed, my ability to form strategy is poor, and I constantly overlook moves that end up costing me powerful pieces and positions. To view a computer analysis of any of my games would reveal an ability to hold my own.. In the first four or five moves. This is often followed by a subtle decline in positional advantage, followed by complete and utter ruin.

With tactics eventually falling in to place, one must turn their mind to strategy: The long game of positioning your pieces for maximum tactical advantage. Initial strategic ability is not built through thorough analysis of openings and the mid game, but rather through analysis of your own mistakes. The opening is less about of doing well, and more about not making position-destroying mistakes.

So I will continue to play and learn, and once I am confident, I will try leaving the virtual world of lichess, just for a while, and seek out the local chess clubs. Making a physical debut will be quite exciting if I have the skills to back it all up! If you ever want to play with me (over the board, or online!), hit me up and we’ll give it a go! Only if you promise to analyse the game with me after, of course..

The Hullet Bells – Part 1 (A Primer on Shmups)

As a would-be hardcore gamer, for me shoot ’em ups, or ‘shmups’, are a fascinating intersection of complexity, fun and playability.

With humble roots in Space Invaders, shmups began with a simple premise: The player controls a ship (or perhaps a flying witch or android) and must defend themselves against wave after wave of enemy attacks. Typically, the player will shoot them, although some games reward dodging over destruction.

The genre split in to two distinct schools of design: fewer, often faster bullets, and denser, slower bullet clouds. The former emphasises reaction speed, the latter memorisation. For example, R-Type and Gradius fall in to the former category, while games such as ESP Ra. De and DoDonPachi epitomise the other.

ESP Ra. De, a bullet hell game
R-Type III, a more traditional game focused on environment

Towards the end of either type of game, the two styles begin to converge: Bullets can only get so fast or dense before they become impossible to dodge, so elements of the other style begin to creep in.

The mechanics of these games vary. Often in simple games, the only variations will be in the graphics and bullet patterns, while the mainstays of lives, power ups and bombs are changed only in token ways. Such games are not necessarily bad! I can revel in the simplicity of a game like Strikers or Raiden, so even with limited mechanics it is possible to construct entertaining games.

That isn’t to say that there isn’t innovation happening! Far from it. The arcade roots of shmups meant that you had to stand out in a sea of other shmups. Some games introduced alternate modes of fire, giving the player a choice between whether they mow down their enemies with scattered shots or concentrated blasts. Others capitalised on the nature of the competitive high score lists omnipresent in the arcade, implementing complicated scoring systems that would require months to master, but for huge score rewards.

More recently, games like Ikaruga have aimed to maintain the old school shmup elements while placing unique and innovative mechanics on top. In Ikaruga’s case, the inclusion of the polarity switch (each polarity allowed players to absorb one of two kinds of bullet) added an entirely new dimension of gameplay, requiring not only that players dodge bullets, but also take in to consideration whether they should be absorbed or not.
Ikargua is a challenging polarity-based shooting game
Generally speaking, once play begins the player will always be looking at the playfield, with the ship present on screen at all times. Plot is sacrificed for an uninterrupted game experience, due to the very nature of the arcade itself: players are here to play games and not take up time on the machine watching cutscenes! This was something of a missed opportunity. CAVE, the popular shmup creators, would be forced to explain the majority of the plot in a 15 second cutscene at the start of the game, with the remainder inferred from short boss dialogues and cryptic ending scenes (if any). With the advent of releasing shmups in both the arcade and then porting them to home console, games have begun to include a longer ‘story mode’ in addition to the ‘arcade mode’ they would normally experience.

This is a completely different story to the doujin and independent game scene. Doujin games are created with the intention of sold at Japanese conventions. Touhou is a popular doujin game shmup series. While the story is probably just as deep as any given fable, a huge fan community has sprung up to fill in the blanks for the world, creating a vibrant living setting with hundreds of different interpretations.

The independent game Sine Mora has a very strong plot with a moderately challenging game to go with it. Indeed, the plot is explained over the course of the game with haunting monologues between levels, and heated dialogue during the game itself. In a rare twist for the genre, control is occasionally taken from the player for plot purposes.

The world of shmups is hugely varied, despite the basic principles being the same between games. This thread that runs through them means skills learned are transferable, while the player can still experience something new and challenging. The best way to experience it is to get out there and try some of the linked games in this post! I can’t possibly describe the fun you’ll experience.

I have a deep enjoyment of these games. While I don’t have the artistic ability or level design experience, there is still one thing I can do to help this dying genre: I can write an easily extensible, open source engine for the creation of shooting games. Over the next few months, I hope to build a small demo game in this engine, graphics be damned! I will also have to write the engine, of course.

I will document this journey here, both to provide insight in to the development process and to keep myself motivated. Maybe one day you’ll even want to build a shmup yourself!