-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
64 lines (58 loc) · 1.41 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
52
53
54
55
56
57
58
59
60
61
62
63
64
let playing = false;
function startGame() {
playing = true;
document.querySelector("button").style.visibility = "hidden";
let counter = 60;
timer = document.querySelector(".timer");
timer.innerText = counter;
const interval = setInterval(function() {
counter--;
if (counter <= 0) {
clearInterval(interval);
playing = false;
setTimeout(function() {
window.location.reload();
}, 5000);
document.querySelector("button").style.visibility = "visible";
}
timer.innerText = counter;
}, 1000);
}
const game = new Game();
function preload() {
game.gamePreload();
}
function setup() {
let canvas = createCanvas(1000, 800);
canvas.parent("canvas");
game.gameSetup();
}
function draw() {
if (!playing) {
if (!game.player1Score && !game.player2Score) {
return;
}
if (game.player1Score > game.player2Score) {
textSize(35);
fill("white");
text("Game over - Player 1 wins!", 300, 350);
} else if (game.player2Score > game.player1Score) {
textSize(35);
fill("white");
text("Game over - Player 2 wins!", 300, 350);
} else {
textSize(35);
fill("white");
text("Game over - Draw", 370, 350);
}
}
playing && game.gameDraw();
}
function keyPressed() {
if (keyCode === 32) {
game.player2.playerJump();
} else if (keyCode == 16) {
game.player1.playerJump();
}
return false;
}