CS 51 Test Program #2
Asteroids
Due: Wednesday, May 2 at 4 PM.
Design due: Wednesday April 25, by 11AM.
Asteroids is a classic arcade game that was released by Atari in 1979. It was an instant hit, and remains popular today (according to wikipedia it's scheduled for release via Xbox Live Arcade for the Xbox 360 in 2007). If you'd like to play the classic asteroids, go to: http://www.80smusiclyrics.com/games.shtml and scroll down until you get to asteroids.
In case you haven't guessed, for your final test program we would like you to write a program that implements Asteroids. To be more precise, we would like you to write a program that implements "almost Asteroids". We have simplified the game considerably from the original in order to make the assignment more reasonable ...however, there is a long list of extra credit points that you can earn by making your game more closely resemble the original.
The asteroids are of different sizes and they move across the screen at different speeds. When an asteroid gets to the edge of the screen it wraps around and reappears at the opposite edge. Unlike the original Asteroids, the ship is fixed in the center of the screen, although it can aim its gun in any direction. If the player clicks on the right-arrow button on the keyboard, the gun rotates clockwise by 15 degrees (=Math.PI/12 radians); if the player clicks on the left-arrow button the gun rotates counterclockwise. If the player clicks on the space button, a bullet is fired from the end of the gun.
Each time a bullet hits an asteroid, the player gets 10 points. The game is over either when an asteroid hits the ship or when the player gets 200 points. In either case, a message is displayed to the user in the score area, indicating "You Won" or "Game Over". In either case, the player should no longer be able to shoot bullets.
You should begin the game by setting up the sky, a score-keeping mechanism, a ship, and asteroids.
The scorekeeper should display the score at the bottom of the screen. It needs to be able to increase the score when an asteroid is hit.
The ship is blue and consists of a body and a gun protruding from it (in practice, a circle with a line). The ship appears at the center of the screen. It must respond to the player's key clicks. That is, the gun should rotate clockwise and counterclockwise, and it must be able to shoot. If the ship is hit, it should turn grey.
The bullets shot at the asteroids will be active objects. They should move in the direction that they were fired, stopping either when they reach the edge of the screen or when they hit an asteroid.
Each asteroid has its own size, speed, and starting location. You may use the gif file that we provide, or something different. An asteroid should move across the screen appropriately, wrapping around whenever it reaches the edge of the screen. When an asteroid is destroyed, another one should appear at one of the edges of the screen.
Your program will comprise several classes, corresponding to the objects just described.
One slightly tricky aspect is making the gun rotate appropriately, and having the bullets appear to be fired from the gun. It is easiest to think of this in terms of an angle theta (where theta=0 is directly to the right, and theta=Math.PI/2 is straight up) and to calculate both the endpoint for the line representing the gun and the dx,dy for the bullets from theta. Note that theta is in radians (and that PI radians is equal to 180 degrees).
As indicated in the heading of this document, you will need to turn in a design plan for your Asteroids program well before the program itself. This design should be a clear and concise description of your planned organization of the program.
You should include in your design a sketch of each class including the types and names of all instance variables you plan to use, and the headers of all methods you expect to write. You should write a brief description of the purpose/function of each instance variable and method.
In addition, you should provide pseudo-code for any method whose implementation is at all complicated. In particular, if a method is complicated enough that it will invoke other methods you write (rather than just invoking methods provided by Java or our library), then include pseudo-code for the method so that we will see how you expect to use your own methods.
We strongly encourage you to proceed as suggested below to assure that you can turn in a running program. While a partial program will not receive full credit, a program that does not run at all generally receives a lower grade. Moreover it is easier to debug a program if you know that some parts do run correctly.
There is a great deal of functionality to aim for in this test program. As indicated above, do not worry if you cannot implement all of the functionality. Get as much of it working as you can. At the end of this handout we have included some basic grading guidelines for this test program. You should note the large number of points assigned to issues of style. It is always best to have full functionality, but you are better off having most of the functionality and a beautifully organized program than all of the functionality with a program that is sloppy, poorly commented, etc.
Since we have deliberately left out many of the features of the original Asteroids game in our implementation, there are clearly many additional features you could add to your program. In general we will award 1-2 points for each extension, for a maximum of 10 points extra credit. The number of points possible if you do not do any extra credit is 95. Thus you must do some extra credit to have a chance at getting 100 points or more. The following are some suggestions, together with the maximum number of points that will be awarded for each:
Your design should be turned in on paper in class or e-mailed to both professors by 11AM on Wednesday April 25. Keep a copy for yourself since we won't be able to return it to you until after the program is due.
When your work is complete you should deposit in the dropoff folder (note that the deadline is 4PM on Wednesday May 2). Before turning it in, please be sure that your folder contains all of the .java files, .class files, etc. as we can't give credit for anything we don't receive.
Before turning it in, make sure the folder name includes your name and the phrase "TP2". Also make sure to double check your work for correctness, organization and style.
Grading Point AllocationsValue | Feature |
Design preparation (20 pts total) | |
Syntax Style (15 pts total) | |
6 pts. | Descriptive and helpful comments |
2 pts. | Good names |
2 pts. | Good use of constants |
2 pts. | Appropriate formatting |
3 pts. | Appropriate use of public/private |
Code quality (25 pts total) | |
5 pts. | conditionals and loops |
5 pts. | General design/efficiency issues |
5 pts. | Parameters, variables, and scoping |
5 pts. | Good correct use of arrays |
5 pts. | Miscellaneous |
Correctness (35 pts total) | |
5 pts. | Gun rotates correctly w/ key presses |
5 pts. | Ship fires projectiles |
5 pts. | Asteroids move correctly |
5 pts. | Ship projectiles destroy asteroids |
5 pts. | Asteroids can destroy ship |
5 pts. | Scoring is correct |
5 pts. | Asteroids generated correctly |
Extra Credit (5 - 10 pts total) | |