-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
48 lines (30 loc) · 1.03 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
const game = new Game()
let gameStarted = false
function setup(){
createCanvas(1385,600)
game.setup()
}
function preload(){
game.preload()
}
function draw(){
if(gameStarted){ //if game has started then execute game's draw()
if(game.lives > 0)
game.draw()
else{
game.gameOver()
}
}
else //else display game instructions
game.gameInstructions()
}
function keyPressed(){
if(keyCode === 32 && !gameStarted) //Spacebar for initial starting of the game
gameStarted = true
if(keyCode === 32) //Spacebar for jump
game.player.jump()
if(keyCode === 13) //Enter for playing again/ screen reload
location.reload()
if(keyCode === 16) //Shift for game pause
game.pause = !game.pause
}