- commit
- c523408ddb1d1e04f8d5794df3b5586d7d60fb5e
- parent
- d590af138e5c646344a93cc03c11e7b405ba93b1
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-10-08 06:41
display level in top right corner
Diffstat
| M | game.go | 2 | ++ |
| M | static/main.js | 8 | ++++++-- |
2 files changed, 8 insertions, 2 deletions
diff --git a/game.go b/game.go
@@ -163,6 +163,7 @@ func (game *Game) MaybeNextLevel() {
163 163 game.generateMap()
164 164 game.Enqueue(Message{
165 165 "action": "setLevel",
-1 166 "level": game.Level,
166 167 "rects": game.Rects,
167 168 "ladder": game.Ladder,
168 169 })
@@ -252,6 +253,7 @@ func (game *Game) run() {
252 253 })
253 254 player.Enqueue(Message{
254 255 "action": "setLevel",
-1 256 "level": game.Level,
255 257 "rects": game.Rects,
256 258 "ladder": game.Ladder,
257 259 })
diff --git a/static/main.js b/static/main.js
@@ -57,6 +57,7 @@ var binSearch = function(key) {
57 57
58 58 var game = {
59 59 id: -1,
-1 60 level: 0,
60 61 rects: [],
61 62 seen: {},
62 63 objects: {},
@@ -267,9 +268,11 @@ var screen = {
267 268 },
268 269
269 270 renderHealth() {
270 -1 var health = Math.round(game.stats.health / game.stats.healthTotal * this.cols);
-1 271 var cols = this.cols - 4;
-1 272 var health = Math.round(game.stats.health / game.stats.healthTotal * cols);
271 273 this.commitSpan('='.repeat(health), 1);
272 -1 this.commitSpan('='.repeat(this.cols - health), 0);
-1 274 this.commitSpan('='.repeat(cols - health), 0);
-1 275 this.commitSpan(('' + game.level).padStart(4), -1);
273 276 $pre.append('\n');
274 277 },
275 278
@@ -373,6 +376,7 @@ socket.onmessage = function(event) {
373 376 if (msg.action === 'setId') {
374 377 game.id = msg.id;
375 378 } else if (msg.action === 'setLevel') {
-1 379 game.level = msg.level;
376 380 game.rects = msg.rects;
377 381 game.ladder = msg.ladder;
378 382 game.seen = {};