-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameOver.js
122 lines (105 loc) · 2.96 KB
/
gameOver.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Game over conditions and logic is here
*/
let gameConstantsModule = require('./gameConstants.js');
let gameOverPlayer = false;
let gameOverCom = false;
let pauseAll = false;
let gameOverFreeze = false;
module.exports = {
getGameOverFreeze, setGameOverFreeze, getGameOverPlayer, setGameOverPlayer,
getGameOverCom, setGameOverCom, getPauseAll, setPauseAll,
pauseOnGameOver, globalPause, displayGameOverText
}
function getPauseAll(){
return pauseAll;
}
function setPauseAll(value){
pauseAll = value;
}
function getGameOverFreeze(){
return gameOverFreeze;
}
function setGameOverFreeze(value){
gameOverFreeze = value;
}
function pauseOnGameOver(){
gameOverFreeze = true;
}
function globalPause(p, moveValues){
if(p.key === 'p' && !getGameOverPlayer() && !getGameOverCom()){
pauseAll = true;
}
if(p.key === 'o'){
pauseAll = false;
}
if(pauseAll){
displayPauseText(p);
}
let ballMoveValues = pauseUnPauseTheBall(moveValues[0], moveValues[1]);
let playerPaddleMoveValues = pauseUnPauseThePlayerPaddle(moveValues[2], moveValues[3]);
let comPaddleMoveValues = pauseUnPauseTheComPaddle(moveValues[4], moveValues[5]);
return [ballMoveValues, playerPaddleMoveValues, comPaddleMoveValues]
}
function displayPauseText(p){
p.push();
p.textAlign(p.CENTER);
p.textSize(15);
p.fill(0, 0, 255);
p.strokeWeight(0.5);
p.text('Paused - Press o to unpause', gameConstantsModule.CANVASX/2, gameConstantsModule.CANVASY/2);
p.pop();
}
function pauseUnPauseTheBall(ballMove, ballTempMove){
if(pauseAll === false){ //case sensitive
//console.log("Pause ball here");
ballTempMove = ballMove;
}
if(pauseAll === true){//case sensitive
//console.log("Unpause ball here");
ballMove = ballTempMove;
}
return [ballMove, ballTempMove];
}
function pauseUnPauseThePlayerPaddle(playerPaddleMove, tempPlayerPaddleMove){
if(pauseAll === false){ //case sensitive
//console.log("Pause ball here");
tempPlayerPaddleMove = playerPaddleMove;
}
if(pauseAll === true){//case sensitive
//console.log("Unpause ball here");
playerPaddleMove = tempPlayerPaddleMove;
}
return [playerPaddleMove, tempPlayerPaddleMove];
}
function pauseUnPauseTheComPaddle(comPaddleMove, tempComPaddleMove){
if(pauseAll === false){ //case sensitive
//console.log("Pause ball here");
tempComPaddleMove = comPaddleMove;
}
if(pauseAll === true){//case sensitive
//console.log("Unpause ball here");
comPaddleMove = tempComPaddleMove;
}
return [comPaddleMove, tempComPaddleMove];
}
function displayGameOverText(text, p){
p.textAlign(p.CENTER);
p.textSize(25);
p.fill(0, 102, 153);
p.strokeWeight(0.5);
p.text(text, gameConstantsModule.CANVASX/2, gameConstantsModule.CANVASY/2);
pauseOnGameOver();
}
function getGameOverPlayer(){
return gameOverPlayer;
}
function setGameOverPlayer(value){
gameOverPlayer = value;
}
function getGameOverCom(){
return gameOverCom;
}
function setGameOverCom(value){
gameOverCom = value;
}