-
Notifications
You must be signed in to change notification settings - Fork 1
/
Enemy.java
57 lines (53 loc) · 1.44 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
public class Enemy extends Player {
// New instance variables
private boolean enemyMovementRight;
/**
* Constructor that takes in the enemy's x and y coordinate and the height and
* width
*
* @param x
* @param y
* @param h
* @param w
*/
public Enemy(int x, int y, int h, int w) {
super(x, y, h, w);
this.enemyMovementRight = true;
}
/**
* Getter method that returns if the enemy is supposed to move right or not
*
* @return enemyMovementRight
*/
public boolean getEnemyMovementRight() {
return enemyMovementRight;
}
/**
* Setter method that sets which direction the enemy is to move in
*
* @param state
*/
public void setEnemyMovementRight(boolean state) {
enemyMovementRight = state;
}
/**
* Sets the enemy's movement speed and direction
*
* @param enemySpeed
*/
public void enemyMovement(int enemySpeed) {
if (getEnemyMovementRight() == true) {
if (getX_Coordinate() >= 930) {
moveDown(50);
setEnemyMovementRight(false);
}
moveRight(enemySpeed);
} else {
if (getX_Coordinate() <= 0) {
moveDown(50);
setEnemyMovementRight(true);
}
moveLeft(enemySpeed);
}
}
}