How it's Made: Missile Command - a Game in Excel 2010
This blog post is brought to you by Karen Cheng a Program Manager on the Excel team.
In today's post, we'll show you how the classic arcade game Missile Command was created in an Excel spreadsheet. We also explain how it's made in this video. In this game, missiles drop from the sky, attacking the city. You must click on the missiles to destroy them.
To play, you'll need -
· To download the game (here)
· To install Excel 2010, hot off the press last week. You can get a free trial here. The games use features that are new to Excel 2010, so they won't work in older versions.
When you open the file to play, don't forget to enable the macros.
The Graphics Engine
The "graphics engine" is made entirely with conditional formatting. Each cell, which represents a pixel, has a number in between 1-10 to represent a shade of grey.
You can't actually see the numbers because the cells have been shrunken down, but enlarge the cells a bit and you'll see the numbers behind the "pixels":
The numbers behind the graphics engine
The entire game runs from a macro that is triggered by clicking on Start. The macro constantly recalculates what numbers to populate the grid with.
Calculating Missile Paths
Each missile runs through this series of calculations:
1. The starting point for the missile is chosen to be somewhere at random at the top of the screen
2. Each missile will at random choose one of the remaining standing buildings to target. It chooses one cell in the general perimeter of the building
3. Based on the starting and ending cell, the slope of the path the missile is calculated, such that it travels at the correct X to Y (column to row) ratio
4. The macro then repopulates the cells in the path over and over again in a loop to "draw" the missile path
5. If the missile hits the building, the game notes which building has been destroyed. The cells around the building are redrawn to the "destroyed building" state and the missile is removed.
Destroying the Missiles
Missiles are destroyed by clicking and creating a shield, which looks like an explosion effect. If the shield and missile collide, the missile is destroyed.
1. To detect the gamer's click, the macro detects when the cell selection changes. If the new cell selection is within the playable game area, the shield is drawn.
2. To draw the shield, the macro quickly draws and redraws six frames in sequence
The shield explosion effect, frame by frame.
3. If any part of the shield and missile occupy the same cell, the missile's path is aborted and the missile is destroyed. If any part of the shield occupies a cell occupied by a standing building, that building is destroyed.
When a missile is destroyed, another one is instantly created. The number of missiles on the screen at any given time corresponds to the level. So at level 5, there will be 5 missiles on the screen at once.
The progress bar indicating how far the gamer is along a level is value in a cell formatted by a data bar.
The level progress indicator
Formatted by data bars
One more thing - you can peek behind the code (and hack away to your heart's desire) by pressing Alt-F8 and clicking edit.
The code behind the scenes
Thanks for tuning into this episode of How It's Made. In the next edition, we'll show you how the classic arcade game Tower Defense is made in Excel.