-
Notifications
You must be signed in to change notification settings - Fork 2
/
ShipProjectile.java
44 lines (35 loc) · 1.02 KB
/
ShipProjectile.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
/**
*
* @author Derick Owens
*
*/
public class ShipProjectile extends MovingScreenObject {
/**
*
* @param location location of the projectile
* @param size size of the projectile
* @param i image of the projectile
* @param angle angle the projectile is aiming toward
*/
public ShipProjectile(Point location, Rectangle size, Image i, double angle){
super(location, size, i, angle);
double endX = location.x;
double endY = location.y;
double newEndX = location.x + (endX - location.x)*Math.cos(Math.toRadians(angle));
double newEndY = location.y + (endY - location.y)*Math.sin(Math.toRadians(angle));
double changeX = (newEndX - location.x);
double changeY = (newEndY - location.y);
arbitraryVector = new ObjectVector(changeX, changeY);
}
/**
* simulates movement of the projectile
*/
public void move()
{
location.x += arbitraryVector.getChangeX();
location.y += arbitraryVector.getChangeY();
}
}