397402 Java game

Completado Publicado Mar 9, 2010 Pagado a la entrega
Completado Pagado a la entrega

This is the description of the assignment and below are attached the files needed.

Objective

1. To reinforce your skill in writing classes.

2. To familiarize you with inheritance and abstract classes.

Problem: Comets

The software company you're working for is developing a game named Comets that is essentially a clone of an old popular arcade game. The player controls a spaceship that floats around in two-dimensional space propelled by its engines and carried by its inertia. Comets are also floating around in the same space. Anything that goes off one side of the screen re-emerges on the opposite side. The player's goal is to destroy all of the comets without colliding with any of them. The situation is complicated somewhat by the fact that shooting larger comets causes them to break into several smaller comets, thus making them more difficult to avoid.

A basic game interface is already written, so you don't need to worry about drawing anything on the screen or responding to the player pressing buttons. All you need to do is write classes to represent the various objects in the game. All classes are to be located in the package "comets". JavaDoc specifications for these classes are provided on WebCourses (along with a few other important files), but here's a general outline:

SpaceObject is an abstract class representing all of the objects in game, including the comets, bullets fired by the player, and even the player's ship. This should keep track of the position, velocity, and size of the object. It provides methods for updating the object's position based on its velocity, determining whether the object is overlapping with another object, and accessors for the object's position and size. SpaceObject has static fields for the playfield width and height that are set up by the main class and should be used to determine the size of the play area for wrap-around purposes.

Shot objects represent shots fired by the player. Shots should only stay on the screen for a certain length of time, so they have an age counter that increments every time the shot is told to move. The main class will take care of removing the shot from the game based on this age.

Comet is an abstract class representing comets. LargeComet, MediumComet, and SmallComet all extend Comet. Large comets break into two medium comets when shot, and medium comets break into three small comets. Small comets are destroyed outright by being shot. Every comet has an explode() method that returns a Vector containing newly created comets that are produced by their destruction, although SmallComet should return an empty vector since it doesn't spawn additional comets.

Ship represents the player's spaceship. The ship has a direction that it is facing that it uses to figure out the change in velocity when it accelerates, as well as the trajectory of the shots it fires. A ship has methods to turn left, turn right, accelerate, and fire shots. The fire() method returns a Shot object that originates from the center of the ship and travels in the direction that the ship is facing, adjusted, of course, for the ship's own velocity. An important note about acceleration: Even though in real space objects can basically travel arbitrarily fast, it wouldn't be much fun if the ship travels so fast that you can't see it. Limit the maximum speed of the ship to 10 pixels per frame (i.e. per move()). That's fast enough for the game to be exciting, but not so fast that it's impossible to follow the ship.

CometsMain is already provided as part of this assignment via WebCourses. The classes you write MUST be compatible with CometsMain in its original form. CometsMain isn't very good, unfortunately. Up to 25 points of extra credit are available on this assignment for making substantial improvements to CometsMain. Contact the professor with your ideas to see how much extra credit it would be worth.

A configuration file named "[url removed, login to view]" should be placed in the root directory of the project. This gives the initial layout of the comets. Each line in the file describes a comet. The string at the start of the line specifies the size of the comet ("Large", "Medium", or "Small"), the two numbers after that are the position of the comet (x and y coordinate), and the last two numbers are its velocity.

Game Constants

Shot radius – 3 pixels Ship radius – 10 pixels

Large comet radius – 40 pixels Medium comet radius – 30 pixels

Small comet radius – 20 pixels Maximum ship speed – 10 pixels/frame

Ship acceleration – 0.1 pixels/frame2 Ship turning rate – 0.1 radians/frame

Shot speed – 3 pixels/frame in the direction of the shot + velocity of the ship when it was fired

Useful Formulas

Determining if two objects overlap:

Let objects one and two be at positions (x1, y1) and (x2, y2) and have radii r1 and r2, respectively. Objects one and two overlap if:

Updating the position of an object:

Let an object at position (x0, y0) be traveling with velocity (vx, vy). Its position (x, y) after being moved is determined by:

Accelerating the ship:

Let the ship have direction θ in radians. The change in x and y velocity when accelerating is given by:

The ship's speed, s, is:

If this speed is greater than 10, scale the velocity down by multiplying both the x and y velocity by 10/s.

Firing a shot:

If a shot is fired from a ship traveling at velocity (vship.x, vship.y) and facing at angle θ in radians, the resulting shot velocity should be:

Deliverables

You must submit the source code (The .java files, not the .class files) for your programs over WebCourses by 11:55 PM on Monday, March 15th, 2010. You must send your source files as an attachment using the "Add Attachments" button. Assignments that are typed into the submission box will not be accepted.

Restrictions

Your program must compile using Java 6.0 or later. It's okay to develop your program using the IDE of your choice, although Eclipse is recommended. Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date.

Grading Details

Your programs will be graded upon the following criteria:

1) Correctness.

2) Conformance to specifications. Even if your program behaves correctly from the user's perspective, you will incur a significant penalty if you do not implement the required classes with the required methods.

3) Your programming style and use of white space. Even if you have a plan and your program works perfectly, if your programming style is poor or your use of white space is poor, you could get 10% or 15% deducted from your grade.

Java Odd Jobs

Nº del proyecto: #2143258

Sobre el proyecto

1 propuesta Proyecto remoto Activo Jul 11, 2012

Adjudicado a:

Atrigen

Discussed in the PMB

$70 USD en 4 días
(0 comentarios)
0.0