Revisit Nintendo’s early gaming years with a Python homage to Game & Watch classic Fire. Mark Vanstone has the code in the latest edition of Wireframe magazine, available now.
As the seventies turned into the eighties, Nintendo began a line of handheld games: the Game & Watch. Created by Gunpei Yokoi, these featured a liquid crystal screen and simple controls – often just left and right buttons. One such game was Fire, where the player had to control a pair of firefighters as they attempted to save people jumping out of a burning building. Although the moving graphics were monochrome, there was a colour overlay showing the burning building, the ground, and the ambulance.
These LCD game graphics weren’t drawn with a matrix of pixels like a computer game, but had a defined set of areas on the screen where shapes could appear. This limited the variations of possible graphics in one game, and due to the speed of the electronics behind the handheld, the refresh rate was considerably slower than most computer games: only around two frames per second.
For this example, we’re going to recreate the look and feel of the original Fire with Pygame Zero. As we have in previous editions of Source Code, we’ve downloaded our graphics from spriters-resource.com. The first thing we need to do is sort out that frame rate. We want the
draw() function to draw every update, but we only want the game objects to move every 30 updates, so what we do is have a count variable and only fire the
doUpdate() function if
count%30 is zero. The % sign returns the remainder when we divide by 30, so we’ll get numbers between 0 and 29 in this case.
We draw the background image first, and then we need to have our two firefighters move between three positions along the ground. We can catch the left and right arrow key presses, but we only want to have one movement per refresh, so we set a
movement variable to -1 or 1 and then do the movement when the next refresh happens. We actually have three Actors for the firefighters, one for each position, and only draw the one at the current position.
Now for the people jumping out of the building. There are only 22 positions which a jumping person can be in, so we can put them in a list of tuples which represent the x and y co-ordinates of the positions on the screen. We also have a different image for each position on the screen, so as our person moves, their image is changed to reflect the position on the screen. We start the game by making a new jumping person in the form of an actor and add that to a list of jumpers. Then, each update we move all the jumpers in the list along by one frame and change their image. When we get to the
draw() function, we draw all our jumpers at the co-ordinates for their frame.
So now we have a game that we can control the firefighters left and right, and have people jumping out of the building following a predefined set of positions on the screen. We need to detect if the firefighters are stopping the people from hitting the ground, so we test to see if a jumper is at any of the frames where they need to be caught, and if so, are the firefighters in the right position to catch them? If not, the person will fall to the ground and the game’s over. If the firefighters are in the right position to save the person all the way across the screen, however, they’ll bounce into the ambulance and the player’s score increases.
With that, the game’s pretty much complete. The original Fire gave you three lives and two difficulty levels, but as always, we’ll leave you to add those features in for yourself.
Get your copy of Wireframe #63
And if you prefer your magazines in digital form, you can also download Wireframe issue 63 as a free PDF!