neon-snake: allow starting game on keyboard
All checks were successful
/ publish (push) Successful in 1m30s
All checks were successful
/ publish (push) Successful in 1m30s
This commit is contained in:
parent
beb38f17e8
commit
ca67aadac0
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue