-
Notifications
You must be signed in to change notification settings - Fork 1
/
EnemyObj.java
47 lines (40 loc) · 1.41 KB
/
EnemyObj.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
import java.awt.Image;
import java.awt.Graphics;
import java.awt.Rectangle;
public class EnemyObj extends GameObj {
public EnemyObj() {
super();
}
public EnemyObj(Image img,int x,int y,int width,int height,double speed,Planewar frame) {
super(img,x,y,width,height,speed,frame);
}
@Override
public void paintSelf(Graphics gImage) {
super.paintSelf(gImage);
y += speed;
if (this.getRec().intersects(this.frame.planeObj.getRec())) {
Planewar.currentState = Planewar.GameState.GAMEOVER;
Planewar.explode = SoundUtil.playSoundWithVolume(GameUtil.planeExplodeSound, false, Planewar.volume);
}
if (y > Planewar.height) {
this.x = -200;
this.y = 200;
GameUtil.removeList.add(this);
}
for (ShellObj shellObj : GameUtil.shellObjList) {
if (this.getRec().intersects(shellObj.getRec())) {
shellObj.setX(-100);
shellObj.setY(100);
this.x = -200;
this.y = 200;
GameUtil.removeList.add(shellObj);
GameUtil.removeList.add(this);
Planewar.score++;
SoundUtil.playSoundWithVolume(GameUtil.enemyExplodeSound, false, Planewar.volume*0.9f);
}
}
}
public Rectangle getRec() {
return new Rectangle(x,y,width,height);
}
}