-
Notifications
You must be signed in to change notification settings - Fork 2
/
Enemy.java
70 lines (61 loc) · 1.37 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
/******************************************************
*Programmer: Derek Babb
*File: Enemy.java
*
*Purpose: This is the player class for the game Escape!
* The player can move around the board moving one
* cell at a time using the keyboard.
*****************************************************/
import java.awt.*;
import javax.swing.*;
public class Enemy extends Player
{
public Enemy(int c)
{
super(c);
}
public Enemy(int c, int w, int h)
{
super(c, w, h);
}
public void setAlive(boolean a)
{
alive = a;
}
public void move(int pX, int pY)
{
if(alive)
{
if(pY < row)
super.move(NORTH);
else if(pY > row)
super.move(SOUTH);
if(pX < column)
super.move(WEST);
else if(pX > column)
super.move(EAST);
}
}
public void draw(Graphics g)
{
int x = width * column + width/10;
int y = height * row +height/10 ;
if(alive)
{
g.setColor(Color.BLUE);
g.fillRect(x, y, width*17/20, height*17/20 );
}
else
{
x = x-width/10 - width/6;
y = y - width/10 - width/6;
int w = width/5;
int h = height/5;
int[] xp = {x+3*w, x+4*w, x+6*w, x+4*w, x+6*w, x+4*w, x+3*w, x+2*w, x, x+2*w, x, x+2*w};
int[] yp = {y, y+2*h, y+2*h, y+3*h, y+4*h, y+4*h, y+6*h, y+4*h, y+4*h, y+3*h, y+2*h, y+2*h};
g.setColor(Color.ORANGE);
g.fillPolygon(xp, yp, 12);
//g.fillRect(x, y, width*8/10, height*8/10 );
}
}
}