-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameCharacterVelocity.js
More file actions
78 lines (69 loc) · 2.05 KB
/
gameCharacterVelocity.js
File metadata and controls
78 lines (69 loc) · 2.05 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
Window.GameCharacterVelocity = (function Character(){
var obj = null,
slowRate = null,
atomicFlags = {
Inky: 0,
Clyde: 0,
Blinky: 0,
Blinky: 0
};
var stepBystep = function(chasing){
/*
* this does the effect of [move|stop],
* if in chase mode flip the logic and rate on how to stop and move
*/
if (atomicFlags[obj.characterName] < slowRate){
atomicFlags[obj.characterName] += 1;
return (chasing ? static() : move());
} else {
atomicFlags[obj.characterName] = 0;
return (chasing ? move() : static());
}
}
var move = function(){
return (obj.dir === 'increment' ? obj.trackCoordinates.increment(obj.coordinate) : obj.trackCoordinates.decrement(obj.coordinate));
}
var static = function(){
return obj.pacmanProperties[obj.coordinate];
}
var slowMotion = function(){
var chasing = null;
/*
* if ghost in chase mode
*/
if (obj.ghostChaseMode && obj.characterType !== 'Pacman' || obj.ghostChaseMode && obj.slowVelocity > 20) {
chasing = true
return stepBystep(chasing)
}
/*
* if Ghost and Ghost has not beein bitten
*/
if (obj.characterType !== 'Pacman' && !obj.HasBeenBitten){
/*
* slowrate controls the velocity of the ghost in normal mode here 20 means
* run move() 20 times and stop 1 time it gives the effect of having pacman
* running more faster than the ghosts
*/
chasing = false;
if (obj.characterName == "Blinky"){
slowRate = 1000;
} else {
slowRate = window.globalConstants.slowRateGhost;
}
return stepBystep(chasing);
} else {
return move();
}
}
var characterVelocity = function(object){
obj = object;
slowRate = obj.slowVelocity || 2;
/*
*if game is just starting stop characters
*/
return Window.SoundEffects.startGameSound().playing || window.globalConstants.stopCharacters ? static() : slowMotion();
}
return {
modulateVelocity : characterVelocity
}
})();