Accessibility
 
Home / Developer Center / Macromedia Flash Developer Center /

Macromedia Flash Article

Aaron E. Silvers
Aaron E. Silvers
www.24-7g.com
 
Making and playing Asteroids with Macromedia Flash MX

When Macromedia released Flash MX, I couldn't wait to play with it. With its new drawing features and ability to create movie clips in ActionScript, I was all aglow with accomplishing "the impossible": making the classic arcade game Asteroids completely with code, just as Atari did it over 20 years ago. Within a surprisingly short amount of time I was able to accomplish this small feat. This article explains how you can do it too. I call this game "Asteroids MX."

Although you should feel free to build the game no matter how comfortable you think you are with ActionScript, I do assume you're familiar with the fundamentals of programming. If you're unfamiliar with programming basics (arrays, functions, assigning values to variables) or some basic elements of ActionScript (dot-syntax, assigning _x and _y positions, the onEnterFrame method, etc.), then you'll probably be more comfortable copying my blocks of code into Macromedia Flash MX.

I've tried to organize this article so you can access specific parts quickly and easily, especially if you have a question about how a certain part of this game works. Either use this tutorial in its entirety to rebuild the game or just read individual parts to help you with another project of yours with similar functionality.

All code is entered into the first frame in the movie—nowhere else. This is an exercise in programming. You don't have to do any old-fashioned Flashing—no importing graphics or making symbols.

When you finish this article you should be able to accomplish the following tasks with ActionScript:

  • Create an instance of an empty movie clip with ActionScript
  • Animate a movie clip by using the onEnterFrame method
  • Draw simple shapes using ActionScript
  • Display text boxes dynamically with aliased text
  • Facilitate simple interactions between movie clip instances by developing a model for collision detection without using hitTest
  • Implement a simple game engine to manage lives, scoring, and difficulty levels

Specifications for Asteroids MX:

  • Movie size = 600 x 400
  • Background color = #990000
  • Ship color = #FFFFFF
  • Asteroid color = #00FF00
  • Ship must be able to go forward, turn right, and turn left
  • All objects must wrap inside the screen, horizontally and vertically
  • Game starts with three lives
  • If an asteroid comes in contact with the ship, a life is lost
  • Ship must be able to fire lasers in the direction of its flight
  • If a laser hits an asteroid the first time, it breaks into two smaller asteroids
  • If a laser hits a smaller asteroid, it breaks into two tiny asteroids
  • If a laser hits a tiny asteroid, it does not break up into anything else
  • Each asteroid hit is worth 200 points
  • When a level is cleared, another asteroid is added to the next level
 
Table of contents
· 
Draw an asteroid
· 
Make an asteroid move
· 
Draw a spaceship
· 
Control the spaceship's movement
· 
Make the spaceship fire lasers
· 
Get the collision detection working
· 
Create a control panel for your game
· 
Score points
· 
Control lives
· 
Vary difficulty with levels
· 
Extend the game
 
Source files
The following files are required for this tutorial:
Windows
Download the sample file asteroids_mx.zip (74.5K)
 
 
  Next
 

About the author
Aaron Silvers is a former public school teacher turned Macromedia Flash guru with five years of Flash development experience and a Master's in Educational Technology from the University of Wisconsin. Aaron is a key member of the independent web venture 24-7group and a senior developer for Learning Insights. He enjoys Cherry Icees and is unbeatable at the Six Degrees of Kevin Bacon. You can reach him at Asteroids@24-7g.com.