fix(snake): should not be able to go in reverse direction - resolve #2

feat(snake): increase speed over time
This commit is contained in:
Mahdi Dibaiee 2015-12-14 21:25:07 +03:30
parent b84775a431
commit c4c02c167d
2 changed files with 11 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}