-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.java
75 lines (75 loc) · 1.82 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//Bullet
public class Bullet{
private int x, y, direction, width, height = 10;
public Bullet(int x, int y, int width, int direction){
this.x = x;
this.y = y;
this.width = width;
this.direction = direction;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public void move(){
if(direction == 0){
y -= 10;
}
if(direction == 1){
y += 10;
}
}
public boolean hit(GoodShip player){
if(player.getX() < x && player.getX() + player.getWidth() > x){
if(player.getY() < y && player.getY() + player.getHeight() > y){
return true;
}
if(player.getY() > y && player.getY() < y + height){
return true;
}
}
if(player.getX() > x && player.getX() < x + width){
if(player.getY() < y && player.getY() + player.getHeight() > y){
return true;
}
if(player.getY() > y && player.getY() < y + height){
return true;
}
}
return false;
}
public boolean hit(Alien badguy){
if(badguy.getX() < x && badguy.getX() + badguy.getWidth() > x){
if(badguy.getY() < y && badguy.getY() + badguy.getHeight() > y){
return true;
}
}
if(badguy.getX() > x && badguy.getX() < x + width){
if(badguy.getY() < y && badguy.getY() + badguy.getHeight() > y){
return true;
}
if(badguy.getY() > y && badguy.getY() < y + height){
return true;
}
}
return false;
}
public boolean hit(Boss badguy){
if(badguy.getX() < x && badguy.getX() + badguy.getWidth() > x){
if(badguy.getY() < y && badguy.getY() + badguy.getHeight() > y){
return true;
}
}
if(badguy.getX() > x && badguy.getX() < x + width){
if(badguy.getY() < y && badguy.getY() + badguy.getHeight() > y){
return true;
}
if(badguy.getY() > y && badguy.getY() < y + height){
return true;
}
}
return false;
}
}