-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.java
More file actions
50 lines (33 loc) · 1.36 KB
/
Copy pathProjectile.java
File metadata and controls
50 lines (33 loc) · 1.36 KB
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
45
46
47
48
49
50
import java.awt.Color;
import java.awt.Graphics;
public class Projectile{
//Variables ================================================================================================
public double x;
public double y;
public double xVelocity;
public double yVelocity;
public int size=8;
public int power;
//================================================
//Constructor================================================
Projectile(int initialX, int initialY, int finalX, int finalY, int power){//This finds the location of the frog and the click, calculates the angle, calculates the x and y components of velocity and sets the proper values for instance variables.
x=initialX;
y=initialY;
double theta = Math.atan( ((double) (finalY-initialY)) / ((double) (finalX-initialX)) );
if (finalX<=initialX)
theta+=Math.PI;
xVelocity = (15*Math.cos(theta));
yVelocity = (15*Math.sin(theta));
this.power=power;//For now, power is always passed in as 10. This can be changed in Frogger
}
//================================================
//Methods================================================
public void update (){
x+=xVelocity;
y+=yVelocity;
}//update
public void draw (Graphics g){
g.setColor(Color.WHITE);
g.fillOval((int)x+size/2, (int)y+size/2, size, size);
}//draw
}//Projectile