-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnemy.java
More file actions
118 lines (92 loc) · 2.97 KB
/
Enemy.java
File metadata and controls
118 lines (92 loc) · 2.97 KB
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
111
112
113
114
115
116
117
118
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Rectangle2D;
import java.awt.Color;
import java.util.Random;
import java.awt.Image;
public abstract class Enemy implements EntityInterface{
protected GamePanel panel;
protected int x;
protected int y;
protected int width;
protected int height;
protected int dx; // increment to move along x-axis
protected int dy; // increment to move along y-axis
protected Color backgroundColour;
protected Random random;
protected Car bat;
protected Bullet bullet;
protected EnemyBullet oppBullet;
protected SoundManager soundManager;
protected Image alienImage, imageUp, imageDown, imageLeft, imageRight;
protected ImageFX imageFX1;
protected int enemy_num; //keeps track of which enemy this is
protected int rand, rand1;
protected boolean side;
protected long lastShotTime, shotDelay;
protected int type;
public void setLocation(){
int panelWidth = panel.getWidth();
int panelHeight= panel.getHeight();
x = random.nextInt (panelWidth - width);
y = random.nextInt(panelHeight- height);
dx+= 2;
};
public void draw(Graphics2D imageConxtext, double cameraX, double cameraY){
int drawX = (int)(x - cameraX);
int drawY = (int)(y - cameraY);
Graphics g = panel.getGraphics ();
Graphics2D g2 = (Graphics2D) g;
imageConxtext.drawImage(alienImage, drawX, drawY, width, height, null);
g.dispose();
};
public void erase(){
Graphics g = panel.getGraphics();
Graphics2D g2 = (Graphics2D) g;
g2.setColor (backgroundColour);
g2.fill (new Ellipse2D.Double (x, y, width, height));
g2.setColor(backgroundColour);
g2.draw(new Ellipse2D.Double (x, y, width, height));
g.dispose();
};
public void shoot(){
};
protected void checkBounds(){
if(x<=260) x= 260;
if(x>= 1660) x= 1660;
if(y<=260) y= 260;
if(y>= 1340) y= 1340;
}
public void move(){
};
public Rectangle2D.Double getBoundingRectangle(){
return new Rectangle2D.Double (x, y, width, height);
};
public boolean collideWithPlayer(){
Rectangle2D.Double myRect = getBoundingRectangle();
Rectangle2D.Double batRect = bat.getBoundingRectangle();
return myRect.intersects(batRect);
};
public boolean collideWithBullet(){
Rectangle2D.Double myRect = getBoundingRectangle();
Rectangle2D.Double bulletRect = null;
if(bullet!= null){
bulletRect = bullet.getBoundingRectangle();
return myRect.intersects(bulletRect);
}
return false;
};
public int getX(){
return this.x;
};
public int getY(){
return this.y;
};
public int getType(){
return this.type;
}
public boolean takeDamage() {
return true;
}
}