wok view boulderdash/stuff/freeze.u @ rev 24126

Add eudev-lib
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Oct 14 06:54:52 2021 +0000 (2021-10-14)
parents
children
line source
1 --- boulderdash.js
2 +++ boulderdash.js
3 @@ -4,7 +4,7 @@ Boulderdash = function() {
4 // GENERAL purpose constants and helper methods
5 //=========================================================================
7 - var KEY = { ENTER: 13, ESC: 27, SPACE: 32, PAGEUP: 33, PAGEDOWN: 34, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40 };
8 + var KEY = { ENTER: 13, ESC: 27, SPACE: 32, PAGEUP: 33, PAGEDOWN: 34, LEFT: 37, UP: 38, RIGHT: 39, DOWN: 40, F: 70 };
10 var Dom = {
11 get: function(id) { return (id instanceof HTMLElement) ? id : document.getElementById(id); },
12 @@ -162,6 +162,7 @@ Boulderdash = function() {
13 this.step = 1/this.fps; // how long is each game frame (in seconds)
14 this.birth = 2*this.fps; // in which frame is rockford born ?
15 this.timer = this.cave.caveTime; // seconds allowed to complete this cave
16 + this.freeze = 0;
17 this.idle = { blink: false, tap: false }; // is rockford showing any idle animation ?
18 this.flash = false; // trigger white flash when rockford has collected enought diamonds
19 this.won = false; // set to true when rockford enters the outbox
20 @@ -261,8 +262,12 @@ Boulderdash = function() {
21 this.endFrame();
22 },
24 + toggleFreeze: function() {
25 + this.freeze = 1 - this.freeze;
26 + },
27 +
28 decreaseTimer: function(n) {
29 - this.timer = Math.max(0, this.timer - (n || 1));
30 + if (this.freeze === 0) this.timer = Math.max(0, this.timer - (n || 1));
31 this.publish('timer', this.timer);
32 return (this.timer === 0);
33 },
34 @@ -755,6 +760,7 @@ Boulderdash = function() {
35 case KEY.DOWN: moving.startDown(); handled = true; break;
36 case KEY.LEFT: moving.startLeft(); handled = true; break;
37 case KEY.RIGHT: moving.startRight(); handled = true; break;
38 + case KEY.F: game.toggleFreeze(); handled = true; break;
39 case KEY.ESC: game.reset(); handled = true; break;
40 case KEY.PAGEUP: game.prev(); handled = true; break;
41 case KEY.PAGEDOWN: game.next(); handled = true; break;