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