forked from hajarhesham/SuperCube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.pde
37 lines (27 loc) · 965 Bytes
/
Enemy.pde
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
public class Enemy extends AnimatedSprite {
float boundaryLeft, boundaryRight;
public Enemy(PImage img, float scale, float bLeft, float bRight) {
super(img, scale);
moveLeft = new PImage[1];
moveLeft[0] = loadImage("Mace.png");
moveRight = new PImage[1];
moveRight[0] = loadImage("Mace.png");
moveLeft = moveRight = new PImage[1];
moveLeft[0] = moveRight[0] = loadImage("Mace.png");
currentImages = moveRight;
direction = RIGHT_FACING;
boundaryLeft = bLeft;
boundaryRight = bRight;
change_x = 2;
}
void update() {
super.update();
if (getLeft() <= boundaryLeft) {
setLeft(boundaryLeft);
change_x *= -1;
} else if (getRight() >= boundaryRight) {
setRight(boundaryRight);
change_x *= -1;
}
}
}