Add WASD jumps to the LU trainer

This commit is contained in:
nyan404 committed 2026-11-22 18:19:44 +03:00
1 parent ba074df4ec
commit a2751971cd
6 files changed
+59 -5

No files matched your search

+15 -1
View File
@@ -4,6 +4,7 @@ import {playSound, stopSound} from './audio.js';
const $ = id => document.getElementById(id);
const compact = matchMedia('(max-width: 700px), (pointer: coarse)');
const phoneMap = matchMedia('(max-width: 700px), (max-width: 1100px) and (max-height: 500px) and (pointer: coarse)');
const jumpKeys = new Map([['KeyW',[0,-1]], ['KeyA',[-1,0]], ['KeyS',[0,1]], ['KeyD',[1,0]]]);
const sounds = ['Звуков нет', 'Едва различимый шорох', 'Тихий шорох', 'Приглушённый шорох', 'Громкий шорох'];
let game, selected = START, hints = new Set(), hintTimers = new Map();
let messages = [];
@@ -123,6 +124,19 @@ function makeGrid(id, isMap) {
return;
}
let next;
const step = !isMap && jumpKeys.get(event.code);
if (step && !event.isComposing) {
event.preventDefault();
const view = game.view();
if (event.repeat || ended(view)) return;
const x = view.position % COLS + step[0], y = Math.floor(view.position / COLS) + step[1];
if (x < 0 || x >= COLS || y < 0 || y >= ROWS) return;
const target = y * COLS + x;
buttons[target].focus();
selectCell(target);
act('jump');
return;
}
if (event.key === 'Home') next = buttons[Math.floor(index / COLS) * COLS];
else if (event.key === 'End') next = buttons[Math.floor(index / COLS) * COLS + COLS - 1];
else {
@@ -200,7 +214,7 @@ function render() {
$('mark-count').textContent = view.marks; $('hazard-count').textContent = view.hazards;
$('rating-count').textContent = view.ratings;
$('attempt-state').textContent = {ready:'Готов к прыжку',playing:'На уступах',won:'Карта готова',lost:'Падение'}[view.status];
$('scene-instructions').textContent = compact.matches ? 'Выберите клетку, затем нажмите нужную кнопку под полем.' : 'Нажмите на соседнюю клетку, чтобы прыгнуть. Правая кнопка мыши или Shift+Enter ставят или снимают флажок.';
$('scene-instructions').textContent = compact.matches ? 'Выберите клетку, затем нажмите нужную кнопку под полем.' : 'Клик по соседней клетке или WASD при фокусе на поле: прыжок. Правая кнопка мыши или Shift+Enter ставят или снимают флажок.';
const cell = view.cells[selected], note = cell.marked ? 'Снять отметку' : 'Отметить опасной';
const selectionState = finished ? 'попытка завершена' : cell.id === view.position ? 'вы здесь' :
cell.entrance ? (cell.available ? 'старт' : 'старт, вне досягаемости') :