-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemy.java
executable file
·48 lines (48 loc) · 1.07 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
import java.io.*;
import sun.audio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
public class Enemy extends Hostile
{
public Enemy(double a, double b, double c, double d)
{
super(a, b, c, d);
}
public int hit()
{
return 1;
}
public void destroyed()
{
try{
InputStream in = (this.getClass().getResourceAsStream("Resources/explosion.wav"));
AudioStream audioStream = new AudioStream(in);
AudioPlayer.player.start(audioStream);
}
catch(Exception e){
}
}
public void draw(Graphics g)
{
g.setColor(Color.WHITE);
g.drawOval((int)myX+6, (int)myY, 18, 18);
g.fillOval((int)myX, (int)myY+10, 30, 20);
}
public void move()
{
if(getX()>600)
setX(0-30);
else if(getX()<(0-30))
setX(600);
else
setX(getX()+dx);
if(getY()>600)
setY(0-30);
else if(getY()<(0-30))
setY(600);
else
setY(getY()+dy);
}
}