-
Notifications
You must be signed in to change notification settings - Fork 1
/
Laser.java
50 lines (33 loc) · 909 Bytes
/
Laser.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
46
47
48
49
50
package FirstGame;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
public class Laser {
private Player player = GamePanel.player;
private int x;
private int y;
public static long startTimer;
public static long laserTimer;
public static long elapsed;
//Constructor
public Laser(){
//Coordinates
x = player.getx();
y = player.gety();
startTimer = System.nanoTime();
laserTimer = 20000;
}
public boolean update(){
x = player.getx();
y = player.gety();
elapsed = (System.nanoTime() - startTimer)/1000000;
if(elapsed > laserTimer) return true;
return false;
}
public void draw(Graphics2D g){
g.setColor(Color.RED);
g.setStroke(new BasicStroke(4));
g.drawLine(x+player.getr(), y+player.getr(), x+player.getr(), 0);
g.setStroke(new BasicStroke(1));
}
}