This project focuses on the addition of game logic, animation, and special effects to our Disasteroids game. The overall goal is a finished game that is fun to play. As before, you need not be restricted by what you did in the previous assignments, and you can redesign your program at this point if you wish. But your program should still provide the features and requirements called for in the previous assignments.
Continue to follow the object-oriented programming methodology we have been using (some of our design and programming practices are repeated below).
Animate your spaceship, asteroids, and aliens. Each item already has a location and a way to draw itself in its current location. Add some instance variables or logic to determine its movement. For example, maybe aliens don't move in a straight line, or maybe they change direction at random. Then, your program simply needs to update each item's location on every clock tick and then redraw them all.
A good way to handle this kind of simulation is to think of each game
element as if it were an independent object. To advance the
simulation, the main program will call a tick() member
function for each item, at regular intervals. The tick()
method should simply compute an item's new position, based on its
previous position and on its velocity and direction. Different
objects or subclasses of GameElement will move differently by
overloading tick().
We will use a Timer object to keep the simulation running. It will send timeout events to our process, and we will provide a callback routine to be called each time the timeout is received. Your callback routine updates the locations (by calling tick() on all the items) and then triggers a repaint of the window.
In addition, each time an object moves, your program will need to
check for collisions, and take appropriate action depending on the
rules of your game. It might update the score, perhaps delete the
item that was hit, or reset your Spaceship (if it has any remaining
lives). You will need code for comparing the locations of two objects
to determine whether they are touching or not. This can be done in a
number of ways. You could use a simple bounding rectangle, or you
could use some of the java.awt.Shape methods for checking
intersection.
Add the following rules to make your program playable:
You should also add your own logic or rules for the game, to make it interesting to play. For example, you could have aliens enter and leave at random times, or special weapons, or special objects that provide bonus points or extra lives.
For this assignment, implement two special effects (and document them in your README). Here are some suggestions for special effects to add:
(The rest of this still applies from previous assignments)
Your program design should exploit the features of object-oriented programming (encapsulation of code and data, support for abstract data types, polymorphism/overloading, inheritance). In particular, object-oriented programming provides us a good way to handle the various data needed in callback routines. You should use objects to encapsulate each interactive widget with the routines and data you need to use it.
You should provide an object for each interactive widget or small group of widgets you create. That object should hold anything you need to remember about the widget from one callback to another, all the data pertinent only to the command for that widget or that you need to operate this control, (including, in most cases, a pointer to the graph or other outside object to perform the actual action the user requested), and the widget's own listener callback routines.
If you have several widgets that share some behavior or properties, you should organize your objects into an appropriate inheritance hierarchy.
You will have other data that must be accessed by several widgets, particularly shared information about the state of the program or global information about the state of the user interface. Provide additional classes and objects for holding this kind of information.
Remember to trigger your drawing to repaint itself explicitly whenever one of your commands causes a change in the state of the graph that should be reflected on the screen. And remember that the way to change the screen is first to change the data stored in the Graph or other classes and then to trigger the repaint.
You should follow these general Java programming practices:
And, finally, for uniformity please name your Java class that has your main program in it Main, in file Main.java
ownwhich other objects)
usesor collaboration relationships (which objects use which other objects to perform functions)
secretsof each of your classes (i.e., what design decisions are entirely encapsulated within that class).
Submit this documentation electronically in text form. Include it as part of the readme file that you submit with your assignment.