👽⛵️ Checkpoint
./script.js:9517054/8047
This commit is contained in:
parent
591c7df84b
commit
0aeefdb5bc
1 changed files with 6 additions and 3 deletions
|
@ -76,7 +76,7 @@ function update() {
|
|||
const x = Math.floor(Math.random() * game.size);
|
||||
const y = Math.floor(Math.random() * game.size);
|
||||
game.apple = [x, y];
|
||||
|
||||
|
||||
if (!inSnek(game.apple[0], game.apple[1])) break;
|
||||
}
|
||||
} else {
|
||||
|
@ -92,7 +92,7 @@ function update() {
|
|||
if (l[0] < 0 || l[0] >= game.size || l[1] < 0 || l[1] >= game.size) {
|
||||
reset();
|
||||
}
|
||||
|
||||
|
||||
// uncomment to wrap
|
||||
// if (next[0] < 0) next[0] = game.size - 1;
|
||||
// if (next[0] >= game.size) next[0] = 0;
|
||||
|
@ -104,7 +104,7 @@ function update() {
|
|||
// update score display
|
||||
if (game.snek.dir !== null) {
|
||||
const score = b.length - 5;
|
||||
if(score > game.highscore) game.highscore = score; // update high score if necessary
|
||||
if (score > game.highscore) game.highscore = score; // update high score if necessary
|
||||
info.innerText = `${score < 15 ? "length" : "longth"}: ${score}`;
|
||||
highscore.innerText = `highscore: ${game.highscore}\n`;
|
||||
}
|
||||
|
@ -129,8 +129,11 @@ function update() {
|
|||
|
||||
// change direction on keypress
|
||||
document.addEventListener("keydown", (e) => {
|
||||
if (e.ctrlKey || e.shiftKey) return;
|
||||
|
||||
const s = game.snek;
|
||||
if (s.dir !== s.newdir) update(); // avoid snek from crashing into itself
|
||||
e.preventDefault();
|
||||
switch (e.key) {
|
||||
case "ArrowLeft":
|
||||
return s.dir !== "right" ? (s.newdir = "left") : 0;
|
||||
|
|
Loading…
Reference in a new issue