Applying the Mental Model: Firefly Jar

In the last section, you read a few JetLag games and tried to guess how they worked. Now it's time to go the other direction and build one.

Here's the game we'll build together. It's called Firefly Jar. You already saw it, on the first page of this book:

It's night in an overgrown garden. Fireflies blink on at random spots, and blink out again a few seconds later. Use the arrow keys to catch ten of them, then get to the jar before the sun comes up. Every so often, a golden firefly appears in one of the garden's hard-to-reach corners. It's worth three, but it doesn't stay lit for long.

Play it a few times before you read any further. Try to win, and try to lose, too. Notice how the sky slowly turns pink as dawn gets closer, and how a firefly flickers right before it goes out. Those little touches are a big part of why the game feels more substantial than the four prototypes in the previous section.

Firefly Jar is small, but it's a complete game. It has a goal, a clock, a way to win, a way to lose, and a way to play again. By the end of this section, you'll have built all of it, and you'll understand every line.

We're going to build it the way real games get built: step-by-step. We'll start by making a garden where you can walk around. Then we'll make it into a game, by giving win and lose conditions and a purpose. Once the game is fun, using only plain gray shapes, then we'll give it more style.