fix(snake): should not be able to go in reverse direction - resolve #2
feat(snake): increase speed over time
This commit is contained in:
parent
b84775a431
commit
c4c02c167d
@ -57,7 +57,7 @@ function loop() {
|
||||
createPart();
|
||||
score++;
|
||||
|
||||
FRAME--;
|
||||
FRAME -= 5;
|
||||
}
|
||||
|
||||
if (head.collides(snake.slice(2))) {
|
||||
@ -103,6 +103,7 @@ ui.onKey(function () {
|
||||
});
|
||||
|
||||
function changeDirection(dir) {
|
||||
if (head.direction === UP && dir === DOWN || head.direction === DOWN && dir === UP || head.direction === LEFT && dir === RIGHT || head.direction === RIGHT && dir === LEFT) return;
|
||||
head.direction = dir;
|
||||
}
|
||||
|
||||
@ -176,6 +177,8 @@ function gameover() {
|
||||
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
||||
ui.write(RETRY);
|
||||
|
||||
FRAME = 100;
|
||||
|
||||
stop = true;
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ function loop() {
|
||||
createPart();
|
||||
score++;
|
||||
|
||||
FRAME--;
|
||||
FRAME -= 5;
|
||||
}
|
||||
|
||||
if (head.collides(snake.slice(2))) {
|
||||
@ -89,6 +89,10 @@ ui.onKey(() => {
|
||||
})
|
||||
|
||||
function changeDirection(dir) {
|
||||
if (head.direction === UP && dir === DOWN ||
|
||||
head.direction === DOWN && dir === UP ||
|
||||
head.direction === LEFT && dir === RIGHT ||
|
||||
head.direction === RIGHT && dir === LEFT) return;
|
||||
head.direction = dir;
|
||||
}
|
||||
|
||||
@ -156,6 +160,8 @@ function gameover() {
|
||||
ui.cursor.goto(ui.center.x - RETRY.length / 2, ui.center.y + 2);
|
||||
ui.write(RETRY);
|
||||
|
||||
FRAME = 100;
|
||||
|
||||
stop = true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user