-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.java
executable file
·111 lines (90 loc) · 1.9 KB
/
Enemy.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.awt.*;
import java.awt.Graphics;
import java.awt.Image;
public class Enemy {
private PlayerBullet[] pb;
private int ex, ey;
private int ExprosionTime;
private int NUM_BULLET;
private boolean isAlive;
private boolean isCollision;
private boolean ERight; //EnemyRight
private boolean ELeft;
private Image enemyimage;
private Image explosionimage;
public void setExplosionImage(Image explosionimage){
this.explosionimage = explosionimage;
}
public void setEnemyx(int ex){
this.ex = ex;
}
public void setIsCollision(boolean isCollision){
this.isCollision = isCollision;
}
public void setExprosionTime(){
if (ExprosionTime < 1){
this.ExprosionTime += 1;
}else{
this.isCollision = false;
this.ExprosionTime = 0;
}
}
public void setEnemyImage(Image enemyimage){
this.enemyimage = enemyimage;
}
public void setNUM_BULLET(int NUM_BULLET){
this.NUM_BULLET = NUM_BULLET;
}
public void setPlayerBullet(PlayerBullet[] pb) {
this.pb = pb;
}
public int getEnemyx(){
return this.ex;
}
public int getEnemyy(){
return this.ey;
}
public Enemy() {
this.ExprosionTime = 0;
isAlive = false;
int r = (int)(Math.random() * 50) + 1;
if (r <= 25){
ELeft = false;
ERight = true;
}else{
ELeft = true;
ERight = false;
}
}
public boolean isAlive() {
return isAlive;
}
public boolean isCollision(){
return this.isCollision;
}
public void set() {
ex = (int)(Math.random() * 1150) + 1;
ey = (int)(Math.random() * 260) + 1;
isAlive = true;
}
public void move() {
if (ex < 1280 -79 && ERight){
ELeft = false;
ex += 10;
}else {
ELeft = true;
}
if (ex > 0 && ELeft){
ERight = false;
ex -= 10;
}else {
ERight = true;
}
}
public void draw(Graphics g) {
g.drawImage(this.enemyimage, this.ex, this.ey, null);
}
public void exprosiondraw(Graphics g) {
g.drawImage(this.explosionimage, this.ex, this.ey, null);
}
}