Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Any help would be great! For this program, you will implement an interface that will allow you to move around a rocket of your own

Any help would be great! For this program, you will implement an interface that will allow you to move around a rocket of your own design. You will need to implement your own classes for the rocket and a test driver, but you will also be able to use the same Blobz.jar external JAR file as for Program 3, which contains useful utilities for creating a graphics context and for supporting your calculations. The only output of the program should be your rocket displayed in the sandbox, and you should be able to move it around using the up, left, and right arrow keys on your keyboard. Program Development

1. The Rocket class must extend the PolyBlob class and also implement the BlobAction interface. Both of these are in the Blobz.jar file and should be imported into your program from the blobz package.

2. The first statement in your Rocket constructor should be: "super(0,0,0);" This will create a stationary PolyBlob in the upper left corner of the sandbox. Then, use the Rocket's setLoc() method, which is inherited from Blob, to set the location to the input location specified by the input parameters to the constructor. The constructor should have

3 input parameters: an int x-coordinate, an int y-coordinate, and the sandbox that your RocketTest test driver instantiated. 3. Your rocket shape will be defined by the polygon you set using the setPolygon() method. You can create your shape on paper and then use those values to initialize the coordinates of the Point[] array that you will pass to setPolygon(). Remember, the coordinates are relative to the origin, which is point (0,0).

4. Since the Rocket class implements the BlobAction interface, the Rocket class must have a public void keyAction(KeyEvent e) method. This method should have separate processing blocks for handling key codes 37 (left arrow), 38 (up arrow), and 39 (right arrow).

5. The Rocket class should also have these instance variables: private double angle = 0.0; private final double delta = 0.15; and private final double speed = 5.0; .

6. The rocket shape that you specify can have as many vertices as you wish. However, no value in the polygon arrays can be less than -10 or greater than +10. Also, when your rocket is first placed in the sandbox, it should be oriented so that the direction of forward motion is to the right as one looks at the screen. This is the direction that should correspond to the initial value of angle = 0.0.

7. The variable "angle" keeps track of the orientation of your rocket. It is initially set to zero, which represents pointing to the right as you look at the screen. Turning to the right will involve adding "delta" to the current angle. Turning to the left will involve subtracting delta from the current angle. You will need to add or subtract 2*PI as appropriate to keep the current angle within the range from 0 to 2*PI. Once you determine what the new angle should be, you should update the rocket's orientation using the setAngle() method.

8. The forward motion block of your keyAction() method should retrieve the current x and y coordinates of your rocket's location, then adjust the locations using the "speed" configuration parameter and the current value of "angle" (which was set to 0.0 initially in the rocket class constructor), and finally should update the location of the rocket using the setLoc() method.

9. The RocketTest class must implement the BlobGUI interface and should have a main() method that contains only the line "new RocketTest()". This is a call to the constructor for the class.

10. The constructor for the RocketTest class should take no input parameters, but it should perform the following actions: (a) create a sandbox; (b) set the sandbox to be in "flow" mode; (c) set the frame rate to 15 frames per second; and (d) pass a reference to itself to the sandbox by running the sandbox's init() method, for example, "sb.init(this)", where "sb" represents the sandbox instance you have created.

11. The RocketTest class should also have a generate() method, which it is required to have since it implements the BlobGUI interface. This generate method will be called every time the user presses the "Start New Game" button on the GUI. The generate() method should instantiate a new Rocket at the location that is at the center of the sandbox. There are several ways to do this. One way to do this is to hard-code the location of the center knowing that the sandbox is 600 x 600 pixels in size. Also, don't forget that the Rocket constructor should have three input parameters, as described in step 2 above in this section. Once the rocket is instantiated, the generate() method should then add it to the sandbox using your sandbox's addBlob() method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions

Question

=+ Should the MNE belong (why, why not)?

Answered: 1 week ago

Question

=+ What is the role of government in bargaining?

Answered: 1 week ago