COMPUTING

CS 1410 | Syllabus | Assignments | Schedule | Canvas Course | [print]

CS 1410: Asteroids Part 1

Nearly everyone has played or at least heard of the famous arcade game Asteroids. But, if you have not, you can play it here. The game involves a player-controlled spaceship that can turn left or right, accelerate forward, and shoot bullets. A collection of rocks (asteroids) move through space, potentially on a collision course with the spaceship. If a collision between the spaceship and a rock occurs, then the spaceship is destroyed. If a bullet collides with a rock, the rock and bullet are both destroyed. The objective of the game is to eliminate all of the rocks, by successfully shooting them from the spaceship, before a devastating collision incident occurs.

Assignment

Your assignment is to recreate a simple Asteroids game using Python and Pygame. The assignment will consist of two sequential parts. For this first part, you are required to implement the following features of the game:

  1. A player-controlled spaceship that can turn in either direction, to point in any direction, and accelerate forward. All three spaceship functions should be controlled by keyboard or mouse input from the user. Remember, the ship may only accelerate in the forward direction (relative to the direction that the ship is currently oriented); it may not ever accelerate in the backward direction. The spaceship should be drawn using a simple polygon that resembles a spaceship. Either use the original game for inspiration, or use your own creativity. The polygon should rotate visually on the screen according to the rotation commands given by the player. Also, if the spaceship moves off the screen, then it should instantly reappear on the opposite side of the screen, still traveling in the same direction and at the same speed. This should apply to all four sides of the screen (left/right and top/bottom).

  2. A number of rocks that move freely through space, at random directions and speeds. Rocks will rotate at a fixed rate; they simply move along a straight line, in a random direction, never accelerating. The shape and size of each rock should also be randomly different. The rocks should be drawn using a simple polygon that resembles an asteroid (i.e. a rock). Again, feel free to use the original game for inspiration. Just like the spaceship, rocks should reappear on the opposite side of the screen when they travel off the screen.

For part 1 of the assignment, no additional functionality is required (e.g. shooting bullets and destroying rocks or colliding with rocks). You will add these features in part 2. You are welcome to continue working on additional features once you complete the requirements for part 1, but it is your responsibility to complete the requirements for part 1 of the assignment first, and submit it by the due date.

For this assignment, you are required to demonstrate use of the object oriented principles inheritance, polymorphism and aggregation when implementing the classes that have been designed for you to represent the game and its various components. For instance, the Movable class implements the game logic for moving an object (and enabling it to wrap around the screen edges, etc.).

You should use our PyGame starter kit.

Part 1 Unit Tests

Required Classes

The required classes are listed in the UML Diagram. Not all of the methods will be described in detail here. For example, most getter methods will not be listed. However, if they are in the UML diagram, they are required. If you have questions about the required functionality, please ask questions in class or in the discussion forums.

This browser does not support PDFs. Please download the PDF to view it: Download PDF.

Movable Class

The Movable class handles most aspects of objects that have a location and may be able to move.

Movable Data Members

Movable Methods

Rotatable Class

The Rotatable class adds the ability to rotate objects, using inheritance to keep all of the functionality of the Movable class. It also implements the accelerate method, making it possible to change the motion of objects.

Rotatable Data Members

Rotatable Methods

Polygon Class

The Polygon class adds the ability to track the shape of an object as a list of points and the ability to draw the object to the Rotatable class.

Polygon Data Members

Polygon Methods

Ship Class

The Ship class adds the ability to evolve (update) like a ship to the Polygon class.

Ship Data Members

Ship Methods

Rock Class

The Rock class adds the ability to evolve (update) like a rock to the Polygon class.

Rock Data Members

Rock Methods

Asteroids Class

The Asteroids class is the overall game class that creates and controls all objects.

Asteroids Data Members

Asteroids Methods

Hints

Last Updated 09/27/2019