neon-snake: allow starting game on keyboard
All checks were successful
/ publish (push) Successful in 1m30s

This commit is contained in:
Leon Mika 2025-12-23 22:04:27 +01:00
parent beb38f17e8
commit ca67aadac0

View file

@ -174,7 +174,7 @@
</div>
</div>
<div class="controls-hint">Desktop: Arrows/WASD | Mobile: Swipe</div>
<div class="controls-hint">Desktop: Arrows/WASD/IJKL | Mobile: Swipe</div>
<script>
const canvas = document.getElementById('gameCanvas');
@ -222,6 +222,7 @@
function startGame() {
startScreen.classList.add('hidden');
gameOverScreen.classList.add('hidden');
nextTouch = null;
// Reset State
snake = [{x: 10, y: 10}, {x: 9, y: 10}, {x: 8, y: 10}];
@ -331,6 +332,7 @@
function gameOver() {
isGameRunning = false;
clearInterval(gameInterval);
nextTouch = startGame;
if (score > highScore) {
highScore = score;
@ -344,8 +346,16 @@
// Input Handling
document.addEventListener('keydown', changeDirection);
let nextTouch = startGame;
function changeDirection(event) {
if (nextTouch) {
let nt = nextTouch;
nextTouch = null;
nt();
return;
}
const LEFT_KEY = 37;
const RIGHT_KEY = 39;
const UP_KEY = 38;