-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bullet.java
45 lines (33 loc) · 1019 Bytes
/
Bullet.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
45
import java.awt.*;
import javax.swing.*;
public class Bullet {
public int xPos, yPos;
public double angle;
public int distanceTraveled;
public static int time = 12;
public String owner;
public double bulletSpeed;
public Bullet(int x, int y, double direction, String origin){
xPos = x;
yPos = y;
angle = direction;
distanceTraveled = 0;
owner = origin;
bulletSpeed = owner.equals("player")?18:9;
}
public void move(){
// Update position
xPos += Math.round(bulletSpeed * Math.cos(Math.toRadians(angle)));
yPos -= Math.round(bulletSpeed * Math.sin(Math.toRadians(angle)));
//Update distance travelled
distanceTraveled +=12;
//Wrap around the screen
yPos = (yPos + 700) % 700;
xPos = (xPos + 1000) % 1000;
}
public void draw(Graphics g){
//Draw the bullet
g.setColor(Color.white);
g.fillOval(xPos-2,yPos-2,4,4);
}
}