-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlane.java
65 lines (51 loc) · 1.33 KB
/
Plane.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package planeProject;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.util.Random;
import javax.swing.ImageIcon;
public class Plane extends Position{
private String planeImage = "/images/Picture1.png"; // pass the image in
int speed = 2;
private Rectangle pRect;
Drone da;
public boolean hit = false;
public Plane(int x, int y) {
super(x, y);
// TODO Auto-generated constructor stub
}
/*public void draw(Graphics2D g2d)
{
g2d.drawImage(getPlaneImage(), x, y, null);
}*/
public void draw(Graphics2D g2d) {
g2d.drawImage(getPlaneImage(), x, y, null);
Rectangle rect = new Rectangle(x, y, 100, 50);
//g2d.draw(rect);
Rectangle dRect = PlanesControl.d.getDroneRect();
checkCollision(rect, dRect);
}
public Rectangle getPlaneRect(){
return pRect;
}
public void checkCollision(Rectangle plane, Rectangle drone){
if(drone.intersects(plane))
hit = true;
}
public void update()
{
//x+=speed;
Random rand1 = new Random();
int n2 = 150 * rand1.nextInt(10) + 600;
//Random rand2 = new Random();
//int speed = rand2.nextInt(6) + 1;
x -= speed;
if(x == -150) // to make plane come out from the right again
x = n2;
}
public Image getPlaneImage()
{
ImageIcon i = new ImageIcon(getClass().getResource(planeImage));
return i.getImage();
}
}