-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnemySpecial.java
52 lines (40 loc) · 1.27 KB
/
EnemySpecial.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
package com.company;
import java.awt.*;
public class EnemySpecial extends EnemySimple {
private int esWidth = 16;
private int esHeight = 16;
public EnemySpecial(int x, int y, int x_Vel, int y_Vel) {
pos = new Vector2D(x, y);
vel = new Vector2D(x_Vel, y_Vel);
try {
canImageBeApplied(4);
} catch (ImageApplyingException e){
image = ImageLoader.getDefaultImage();
}
}
public EnemySpecial() {
pos = new Vector2D(0, 0);
vel = new Vector2D(0, 0);
}
@Override
public Rectangle getBounds() {
return new Rectangle((int)getxPos(), (int)getyPos(), esWidth, esHeight);
}
@Override
public void render(Graphics g) {
g.drawImage(image, (int)getxPos(), (int)getyPos(), null, null);
}
@Override
// override this method, so that special enemies can bounce back from walls
public void ensureNotGoingOffScreen() {
int tempVel;
if (getyPos() <= 0 || getyPos() >= 590) {
tempVel = (-1) * getyVel();
setyVel(tempVel);
}
if (getxPos() <= 0 || getxPos() >= 770) {
tempVel = (-1) * getxVel();
setxVel(tempVel);
}
}
}