-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
51 lines (40 loc) · 1.28 KB
/
main.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
let gameEngine = new GameEngine("gameCanvas", 15);
//========================== Game Engine Functions Start =============================
//=========================== Game Engine Functions end ===============================================
function handleKeyPress(key){
gameEngine.updateCueStickPower(key.keyCode);
}
function main_loop(){
gameEngine.clearScreen();
gameEngine.drawPoolTable();
gameEngine.drawBalls();
if(gameEngine.isPlaying()){
//Execute code for the situation when it's players turn to adjust cue and hit the white ball
gameEngine.drawCueStick();
// gameEngine.old_drawAimLine();
gameEngine.drawAimGuide();
}
else if(gameEngine.isMoving()){
//Execute code for the situation when the balls are still moving
gameEngine.updateBallStates();
if(gameEngine.ballsAtRest()){
gameEngine.handleNewlyPocketed();
if(gameEngine.gameState == GS_MOVING) {
gameEngine.gameState = GS_PLAYING;
}
}
}
}
gameEngine.gameState = GS_PLAYING;
gameEngine.initBalls();
gameEngine.initCueStick();
document.addEventListener('mousemove', (event)=>{
gameEngine.handleMovingMouse(event);
});
document.addEventListener('click', (event)=>{
gameEngine.handleMouseDown(event);
});
document.onkeydown = handleKeyPress;
window.onload = function(){
setInterval(main_loop, 20);
}