-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEnemy.java
58 lines (52 loc) · 1.41 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
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import javax.swing.ImageIcon;
public class Enemy
{
public int healthPoints, x, y, width, height, speed;
volatile int direction;
public SpaceInvadersPanel panel;
ImageIcon image;
static File sound;
public Enemy(int x, int y, int width, int height, int healthPoints, int speed, SpaceInvadersPanel panel)
{
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.healthPoints = healthPoints;
this.speed = speed;
this.direction = 1;
this.panel = panel;
try {
this.sound = Classes.getSound("invaderHit");
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void draw(Graphics g)
{
}
public void hit()
{
makeSound();
this.healthPoints -= 5;
if(this.healthPoints <= 0)
{
SpaceInvadersPanel.enemies.remove(this);
}
}
public static void makeSound()
{
Classes.sound(sound);
}
}