Asteroids
Justin Onstine
wildone@cats.ucsc.edu
CS 160 Final Project - Spring 2001
Introduction
I chose to create a remake of the classic game "Asteroids." In this
game, the player controls a space ship (in this case, the Starship Enterprise)
and must destroy all of the Earth-bound asteroids before they destroy mankind.
At the player's disposal are phazors, and not much else.
Implementation Strategy
In order to complete this assignment in a timely manner, I chose to work
slowly through each step and ensure that it worked the best that I could
make it before moving on to a new challenge. Here is what I was able
to complete in the time given:
-
First I took on the task of creating objects and animating them.
In order to do this, I was forced to learn the add_timer function from
the FLTK library. With this function, I could force a redraw of my
scenario 30 times per second, effectively making smooth motion. I
began with only 3D color cubes for simplicity. Each asteroid rotates
randomly, begins with a random start point, and translates in an arbitrary
linear manner.
-
The second step that I took was to add in the player's ship. This
was simply a matter of drawing something myself and inserting it into the
scene. No big deal. Once it was inserted, I defined the arrow
keys to make the player move and rotate.
-
Next I began the task of collision detection. I used the bounding
box method as suggested by Professor Pang to determine when things would
collide. Once two unalike objects shared a coordinate space, I printed
out a message to standard output.
-
With collision detection working, I enabled the player to fire from their
ship. The space bar was used for this task, and the shots followed
a trajectory determined by the rotation value of the player's ship.
At first I simply used a pixel to represent the player's munitions.
I incorporated collision detection in with the shots fired as well.
-
Once these basic steps were functional, I made the asteroids shrink in
size once they were collided with. The asteroids start out large
and can be shrunk two times before being ultimately destroyed. Once
destroyed, they simply were not drawn anymore and a flag was set for that
asteroid so that the player's ship would not be destroyed by something
that was not there.
-
In an effort to add more of a game-like feel, I added the concept of lives
and points. Though not obvious in any way, the player starts out
with 3 lives, which are depleted one by one whenever they are collided
with. Once all of the player's lives are gone, they are given the
option through standard input to play again. The standard out/in
part of this feature is very annoying and I did not have time to make something
more eloquent. The points are maintained through a little output
box in the lower left hand corner. This was necessary so that I could
compete with my friends.
-
Next I decided that the player needed to cruise around in style, so I inserted
the Starship Enterprise. This was a more difficult task than I had
originally anticipated as many things needed to be scaled down or up to
accomodate the large new object on the screen. Collison detection
became a slightly more difficult task at this point as well.
-
I then improved the look of the player's bullets. I created a 3 dimensional
object out of 8 triangles, sort of like a double sided pyramid. This
object is colored red for easy visibility. I also designed a trail
of pixels to follow behind the player's shots and make things look cool.
The pixels can only travel a short distance from the rear of the player's
shot and are in many different colors.
-
From here, I created (with the help of Jonathan Cheatham) a texture map
for my asteroids to give them more of a rustic dirt look. I applied
this texture map to each side of the asteroids and that made them seem
a bit more authentic.
-
Finally, I engineered a sort of explosion which occurs whenever the ship
or asteroid is destroyed. Though not perfected, it is still effective
and serves its purpose. When an asteroid is shot, a field of small
pixels erupt from that point and expand outward for a second. When
the player's ship is collided with, a larger explosion with bigger pixels
is generated.
How to Play
Before play can begin, the user must type in the program name from the
prompt:
>asteroids
From there, the user will be prompted to enter a seed for the random
number generator used so heavily in this program. This was absolutely
necessary so that you don't play the same configuration every time.
Up Arrow - moves the player in the direction they are facing
Down Arrow - applies reverse thrusters and moves the player in the opposite
direction that they are facing
Right Arrow - rotates the player clockwise (I think)
Left Arrow - opposite of the right arrow
Space Bar - fire phazers
Comments
I really enjoyed writing this program. I wish I had more time to
incorporate some of my ideas that didn't make the cut. Towards the
end I started toying with perspective viewing and trailing behind the player's
ship as he turned and shot the asteroids, but this proved to be too much
work for the little time that I had left. I plan on continuing this
project even though the quarter is over. Thanks to Jonathan for all
his help at the end.
wildone@cats.ucsc.edu