Purpose

You are going to create a space invaders game. You will be given some working objects that interact in a universe, and you will need to figure out how to inherit from these objects in order to create the game.

Requirements

You will write a program that draws at least 8 spaceships on the screen and moves them back and forth across the window. These spaceships should drop bombs randomly. The bombs should destroy the hero if they hit him. The hero is controlled by your mouse and resides at the bottom of the screen. The hero can shoot missiles that will destroy spaceships when they hit them. Your spaceships should inherit from the class SpaceThing and override any behaviors that they need to to implement the game. You should inherit from your spaceship class to create at least two other kinds spaceships that change size or disappear and reappear.

Your program should have:

  1. Each class in a separate file.
  2. When a spaceship hits one of the edges, it should reverse direction.
  3. Bombs and missiles should be deleted when they hit the top or bottom of the screen (just because you can not see them, does not mean that they have been deleted).

Think before programming

Plan out your class hierarchy. Which classes will inherit from which other classes? What instance variables will you need to implement new behaviors? What new methods will you need to implement the new behaviors?

Start with the basic asteroids working code and gradually add new objects to the game.

Once you have a spaceship, get it to drop bombs and make sure they interact with the hero correctly.

Then get the hero to stick to the bottom of the screen and fire missiles correctly.

Finally, add additional spaceship behaviors.

You will need to use the ACM library, so you may want review the tutorial on using the ACM library.

Again, take a look at the examples.

Requirement: use separate files

We require that you use a separate .java file for all of your classes for this project. The SpaceThing object you inherit from will have a instance variable that references the universe to allow you to add things to the canvas.

Recommended: start with the provided code

The Space example starts you off with a lot of valuable code for this project. If you understand how all of the code for that example works, then you should be able to complete this project with relative ease. If you do not understand how that code works, then you should study it, change it, and work with it until you do. TAs can help explain it to you, but it is best if you first make an effort to understand it for yourself. If you do not understand the code that you are working with, you will shoot yourself in the foot over and over. Please, please, understand the code.

You can download a zip file containing a project with the working Space example at (http://dna.cs.byu.edu/cs142/AsteroidsStudent.zip). In order to load it into Eclipse, go to File/Import/General/Existing Projects into Workspace/Select Archive File/Browse. Select the zip file (Eclipse will unzip it for you). It should cleanly import a project named Asteroids.

Pass-off procedure

When you have your program working, you will need to show it to a TA. The TA will evaluate your code based on the following criteria:

  1. Your game includes a hero and at least 8 spaceships that bounce off of the left and right edges (5 points)
  2. Your spaceships drop bombs that can destroy the hero(5 points)
  3. Your hero launches missiles that can destroy the spaceships (5 points)
  4. Your missiles and bombs are also removed from the program when they go off of the screen (5 points)
  5. You have created 3 different classes for enemies which inherit from Space Thing (the basic enemy and two variants) that have different behaviors (10 points)
  6. Is your code properly formatted and has a separate file for spaceship (indenting blocks, comments, spacing, reasonable names of variables)? (5 points)

5 points extra credit: Do something creative that really impresses the TA.

Extra Credit: Pass off early (1 point per day (excluding Sunday) up to 3 points)

Further tips

  • For ideas on how to draw some different shapes and colors, see ACM library tips
  • Create Missile, Bomb, and Alien classes that extend SpaceThing.
  • Use setDeltax() and setDeltay() to change how your things move.
  • In subclasses of SpaceThing, try overriding the act() and/or move() methods to make Missiles, Bombs, the Hero, and Aliens behave differently.
  • Look at the Asteroid class for an example of how to deal with collisions. Notice how it uses the Universe class. Do something like that for your Bombs and Missiles.
  • Understand the uses of the “super” keyword in Java.

Images you can use

Heros

Aliens

Asteroids

Spaceships

Bombs

Missiles

cs-142/fall-2010/labs/spaceinvader.txt · Last modified: 2014/11/19 15:52 by ryancha
Back to top
CC Attribution-Share Alike 4.0 International
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0