-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGhosts.js
50 lines (42 loc) · 1.13 KB
/
Ghosts.js
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
import { DIRECTIONS, OBJECT_TYPE } from './setup';
class Ghost {
constructor(speed = 5, startPos, movement, name, pacman) {
this.name = name;
this.movement = movement;
this.startPos = startPos;
this.pos = startPos;
this.dir = DIRECTIONS.ArrowRight;
this.speed = speed;
this.timer = 0;
this.isScared = false;
this.rotation = false;
this.pacman = pacman
}
shouldMove() {
if (this.timer === this.speed) {
this.timer = 0;
return true;
}
this.timer++;
}
getNextMove(objectExist) {
// Call move algoritm here
const { nextMovePos, direction } = this.movement(
this.pos,
this.dir,
objectExist, this.pacman
);
return { nextMovePos, direction };
}
makeMove() {
const classesToRemove = [OBJECT_TYPE.GHOST, OBJECT_TYPE.SCARED, this.name];
let classesToAdd = [OBJECT_TYPE.GHOST, this.name];
if (this.isScared) classesToAdd = [...classesToAdd, OBJECT_TYPE.SCARED];
return { classesToRemove, classesToAdd };
}
setNewPos(nextMovePos, direction) {
this.pos = nextMovePos;
this.dir = direction;
}
}
export default Ghost;