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 movienowhere
else. This is an exercise in programming. You don't have to do
any old-fashioned Flashingno 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
|