Add an incredibly bad level select
This commit is contained in:
parent
a76a44e1b8
commit
6076b3c9a1
60
js/main.js
60
js/main.js
@ -310,7 +310,7 @@ class Level {
|
|||||||
}
|
}
|
||||||
else if (actor === this.player) {
|
else if (actor === this.player) {
|
||||||
if (player_direction) {
|
if (player_direction) {
|
||||||
console.log('--- player moving', player_direction);
|
//console.log('--- player moving', player_direction);
|
||||||
direction_preference = [player_direction];
|
direction_preference = [player_direction];
|
||||||
actor.last_move_was_force = false;
|
actor.last_move_was_force = false;
|
||||||
}
|
}
|
||||||
@ -532,6 +532,59 @@ class Level {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class LevelBrowserOverlay {
|
||||||
|
constructor(game) {
|
||||||
|
this.game = game;
|
||||||
|
this.root = mk('table.level-browser');
|
||||||
|
for (let [i, stored_level] of this.game.stored_game.levels.entries()) {
|
||||||
|
this.root.append(mk('tr',
|
||||||
|
{'data-index': i},
|
||||||
|
mk('td', i + 1),
|
||||||
|
mk('td', stored_level.title),
|
||||||
|
// TODO score?
|
||||||
|
// TODO other stats??
|
||||||
|
mk('td', '▶'),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.root.addEventListener('click', ev => {
|
||||||
|
let tr = ev.target.closest('table.level-browser tr');
|
||||||
|
if (! tr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
let index = parseInt(tr.getAttribute('data-index'), 10);
|
||||||
|
this.game.load_level(index);
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Don't propagate clicks on the root element, so they won't trigger a
|
||||||
|
// parent overlay's automatic dismissal
|
||||||
|
this.root.addEventListener('click', ev => {
|
||||||
|
ev.stopPropagation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
open() {
|
||||||
|
if (this.game.state === 'playing') {
|
||||||
|
this.game.set_state('paused');
|
||||||
|
}
|
||||||
|
|
||||||
|
let overlay = mk('div.overlay', mk('div.dialog', this.root));
|
||||||
|
document.body.append(overlay);
|
||||||
|
|
||||||
|
// Remove the overlay when clicking outside the element
|
||||||
|
overlay.addEventListener('click', ev => {
|
||||||
|
this.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
close() {
|
||||||
|
this.root.closest('.overlay').remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// - some kinda visual theme i guess lol
|
// - some kinda visual theme i guess lol
|
||||||
// - level password, if any
|
// - level password, if any
|
||||||
@ -561,7 +614,7 @@ const GAME_UI_HTML = `
|
|||||||
<h2 class="level-name">Level 1 — Key Pyramid</h2>
|
<h2 class="level-name">Level 1 — Key Pyramid</h2>
|
||||||
<nav class="nav">
|
<nav class="nav">
|
||||||
<button class="nav-prev" type="button">⬅️\ufe0e</button>
|
<button class="nav-prev" type="button">⬅️\ufe0e</button>
|
||||||
<button class="nav-browse" type="button" disabled>Level select</button>
|
<button class="nav-browse" type="button">Level select</button>
|
||||||
<button class="nav-next" type="button">➡️\ufe0e</button>
|
<button class="nav-next" type="button">➡️\ufe0e</button>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
@ -668,6 +721,9 @@ class Game {
|
|||||||
this.load_level(this.level_index + 1);
|
this.load_level(this.level_index + 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
nav_el.querySelector('.nav-browse').addEventListener('click', ev => {
|
||||||
|
new LevelBrowserOverlay(this).open();
|
||||||
|
});
|
||||||
|
|
||||||
// Bind buttons
|
// Bind buttons
|
||||||
this.pause_button = this.container.querySelector('.controls .control-pause');
|
this.pause_button = this.container.querySelector('.controls .control-pause');
|
||||||
|
|||||||
@ -224,6 +224,9 @@ const TILE_TYPES = {
|
|||||||
level.make_slide(other, 'force');
|
level.make_slide(other, 'force');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
force_floor_all: {
|
||||||
|
// TODO cc2 cycles these...
|
||||||
|
},
|
||||||
bomb: {
|
bomb: {
|
||||||
// TODO explode
|
// TODO explode
|
||||||
on_arrive(me, level, other) {
|
on_arrive(me, level, other) {
|
||||||
@ -261,6 +264,7 @@ const TILE_TYPES = {
|
|||||||
blocks: true,
|
blocks: true,
|
||||||
is_object: true,
|
is_object: true,
|
||||||
is_block: true,
|
is_block: true,
|
||||||
|
ignores: new Set(['fire']),
|
||||||
},
|
},
|
||||||
green_floor: {},
|
green_floor: {},
|
||||||
green_wall: {
|
green_wall: {
|
||||||
|
|||||||
26
style.css
26
style.css
@ -43,9 +43,33 @@ body > header > nav {
|
|||||||
gap: 0.5em;
|
gap: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.overlay {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
background: #0004;
|
||||||
|
}
|
||||||
|
.dialog {
|
||||||
|
max-width: 80%;
|
||||||
|
max-height: 80%;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 1em;
|
||||||
|
border: 1px solid black;
|
||||||
|
color: black;
|
||||||
|
background: #e8e8e8;
|
||||||
|
box-shadow: 0 1px 3px #000c;
|
||||||
|
}
|
||||||
|
|
||||||
main {
|
main {
|
||||||
flex: 0;
|
flex: 0;
|
||||||
margin: auto; /* center in both directions baby */
|
margin: auto; /* center in both directions baby */
|
||||||
|
isolation: isolate;
|
||||||
display: grid;
|
display: grid;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
grid:
|
grid:
|
||||||
@ -107,7 +131,7 @@ main > header > nav {
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
z-index: 99;
|
z-index: 1;
|
||||||
font-size: 48px;
|
font-size: 48px;
|
||||||
padding: 10%;
|
padding: 10%;
|
||||||
background: #0009;
|
background: #0009;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user