-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyControl.js
More file actions
47 lines (44 loc) · 1.16 KB
/
keyControl.js
File metadata and controls
47 lines (44 loc) · 1.16 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
// ------------------------------------------------------------
// Key and Mouse Control Functions
// ------------------------------------------------------------
/**
* Handle key press events for movement and actions.
* @global isLeft, isRight, isFalling, gameChar_y, jumpSound, mode
*/
function keyPressed() {
if (keyCode == 37 || key == "A") {
isLeft = true;
} else if (keyCode == 39 || key == "D") {
isRight = true;
} else if (keyCode == 32 || key == " ") {
if (isFalling == false) {
gameChar_y -= 120;
jumpSound.play();
}
} else if (keyCode === ENTER || key === ENTER) {
mode = 1;
}
}
/**
* Handle key release events to stop movement.
* @global isLeft, isRight
*/
function keyReleased() {
if (keyCode == 37) {
isLeft = false;
} else if (keyCode == 39) {
isRight = false;
}
}
/**
* Handle mouse press events for restarting after win.
* @global castle, startGame, isRaining, game_score, bgMusic
*/
function mousePressed() {
if (castle.isReached == true) {
startGame();
isRaining = true;
game_score = 0;
bgMusic.play();
}
}