-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path16_2_pausing.html
37 lines (36 loc) · 1010 Bytes
/
16_2_pausing.html
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
<link rel="stylesheet" href="css/game.css" />
<body>
<script>
// The old runLevel function. Modify this...
let pause = false;
window.addEventListener('keydown', e => {
if (e.key === 'Escape') {
pause = !pause;
console.log(pause ? 'paused' : 'unpaused');
}
});
function runLevel(level, Display) {
let display = new Display(document.body, level);
let state = State.start(level);
let ending = 1;
return new Promise(resolve => {
runAnimation(time => {
if (pause) time = 0;
state = state.update(time, arrowKeys);
display.syncState(state);
if (state.status == 'playing') {
return true;
} else if (ending > 0) {
ending -= time;
return true;
} else {
display.clear();
resolve(state.status);
return false;
}
});
});
}
runGame(GAME_LEVELS, DOMDisplay);
</script>
</body>