Java代写:CS415 Sling Shot

遵循现实物理模型,代写一款弹球游戏,要求碰撞过程合理。

Important Dates and Requirements

The submission code is 9P
Your main application must be named Program9.java

New Ideas

Loops and Collections.

The Assignment

For this assignment you will create an application that allows the user to shoot projectiles with a slingshot. The projectile can be aimed at a collection of buildings and if the projectile collides with a building the building is destroyed. For animation you will be using the AnimationTimer that you used in the labs this week.

Download

There are no starting files for this assignment.

Slingshot Class

Create a class to represent the Slingshot. The slingshot should have dX a small (but at least 8X8) Ellipse located at the slingshot “center” that Slingshot center represents the slingshot “pocket”. This pocket should be draggable and dY as it is dragged it should keep a rubber line attached to the center (this represents the slingshot bungee cord.) On the mouseReleased event projectile dragged from center you should create a new Projectile at the location of the pocket and return the pocket to the center. The projectile should be passed to the main application and animated to move according to the dX and dY offset of the pocket from the center at the time of release.

Projectile Class

The Projectile class should have a constructor with parameters for the initial startX, startY location and the dX and dY slingshot offset.

The projectile will need a move() method that can be called by the animate method to move the projectile one step in the animation of the projectile flight. The move method will calculate the new location based on the original (starting) location and the “time” since launch (time is just an integer counter that keeps track of how many times the move method has been called). For accuracy you should calculate all positions as doubles and only convert them it integers when necessary (for instance when you pass them to the setLocation method.) We want the projectile to move with respect to the initial velocity given to it by the slingshot and by the velocity given to it by “gravity”. The effect of velocity due to the slingshot will simply be proportional to dX and dY. So for example, the new x location for the move command is:

startX + time * c * dX

Where c is some constant that makes the motion seem as natural as possible (you will have to experiment with various values of c). and the new y location is

startY + time * c * dY + gravity

Thanks to Newton, the effect of gravity on the y location is given by

gravity = 0.5 * g * time * time

Where “g” depends on what planet you are from, (I found g = 0.2 worked well for my c constant but you may have to experiment to find a good g.).

The projectile should create a small dot (Ellipse about 2X2) at each location it traverses (see Angry Birds) in order to draw the path of flight. You must keep these in a collection so that when the next projectile is launched the dots for the previous track can be hidden and removed from the collection.

Building Collection

You must create a collection of “buildings”; to start these can just be Rectangles. You should have at least 10 buildings along the bottom right side of the frame and a Slingshot near the bottom left side. When a projectile collides with a building the building should be destroyed and disappear.

Building Class and animating explosion

Instead of using simple Rectangles for buildings create a Building Class that looks more interesting. For example, with random sizes, roofs or window etc., add an animation sequence to emphasize a building hit.

Program9 Class

Your main application must be named Program9, it should create the slingshot and create the collection of buildings, it must implement Animator and animate the movement of the projectile created by the slingshot.

Grading

  • Slingshot
    • A Slingshot that can launch one projectile in a straight line
    • Projectile can be aimed (speed and direction)
    • Multiple projectiles can be launched
    • Projectiles draw path with dots
    • Path of previous projectile erased
    • Projectile path simulates gravity
  • Program9
    • Collection of buildings
    • Building disappears when hit
    • Building are random sizes
    • Buildings are more than a simple Rectangles (roofs, windows etc.)
    • Building is replaced with rubble when destroyed.
    • Some sort of explosion animation when building is hit.

Notes

  • Your main application must be named Program9.java
  • If you have to resubmit you must resubmit all the files for the assignment.
  • We will grade the last submission you make.
  • Be sure to use checkstyle and remove all style errors (Up to 20 points may be deducted).
  • A movie is posted showing a sample solution.