Introduction to Keeping Application Pure Through Spaceship Game

Let's look at how application purity can be achieved through a step-by-step implementation of a space shooter game.

To show how we can keep an application pure, we’ll build a video game in which our hero fights endless hordes of enemy spaceships. We’ll make heavy use of Observable pipelines, and I’ll point out along the way when it might be tempting to store state outside the pipeline and how to avoid it.

Video games notoriously keep a lot of external state—scores, screen coordinates for the characters, timers, and so on. Our plan is to build the whole game without relying on a single external variable that keeps state.

In our game, the player will move the spaceship horizontally using the mouse and will shoot by clicking the mouse or tapping the spacebar. Our game will have four main actors: the moving star field in the background, the player’s spaceship, the enemies, and the shots from both the player and the enemies.

It will look like this:

Get hands-on with 1200+ tech skills courses.