-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerBullet.java
executable file
·92 lines (74 loc) · 1.58 KB
/
PlayerBullet.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.awt.*;
public class PlayerBullet {
private static final int SPEED = 8;
private MyModel mm;
private int x, y;
private int px, py;
private int[] ex, ey;
private int Hit;
private int NUM_ENEMY;
private boolean isAlive;
private boolean isCollision;
public void setEnemyx(int[] ex){
this.ex = ex;
}
public void setEnemyy(int[] ey){
this.ey = ey;
}
public void setIsCollision(boolean isCollision){
this.isCollision = isCollision;
}
public void setMyModel(MyModel mm){
this.mm = mm;
}
public void setNUM_ENEMY(int NUM_ENEMY){
this.NUM_ENEMY = NUM_ENEMY;
}
public int getCollisionx(){
return this.x;
}
public int getCollisiony(){
return this.y;
}
public PlayerBullet() {
Hit = 0;
isAlive = false;
isCollision = false;
}
public boolean isAlive() {
return isAlive;
}
public boolean isCollision() {
return isCollision;
}
public void set(int x, int y) {
this.x = x + 100 / 2;
this.y = y + SPEED;
isAlive = true;
}
public void move() {
if (y < -100) {
isAlive = false;
} else {
y -= SPEED;
}
}
public void init(int px, int py) {
this.x = px;
this.y = py;
}
public void CollisionDetection() {
for (int i = 0; i < NUM_ENEMY; i++){
if (isAlive == true && this.x > this.ex[i] && this.x < this.ex[i] + 100 && this.y < this.ey[i] + 100 && this.y > this.ey[i]){
Hit += 1;
System.out.println("Enemy[" + i + "] " + " Hit -> " + Hit + " x-> " + this.x + " y -> " + this.y);
isCollision = true;
isAlive = false;
}
}
}
public void draw(Graphics g) {
g.setColor(Color.RED);
g.fillRect(x, y, 2, 10);
}
}