Max,
i refactored this function and as per console.time() it is a lot faster.
The original version is executed in 0.300-500ms, this one in 0.010-0.020.
I found that interesting.
function setFood() {
var randomX= Math.round(Math.random() * (grid.width - 1)),
randomY= Math.round(Math.random() * (grid.height - 1));
if(grid.get(randomX, randomY) === SNAKE) {
setFood();
} else {
grid.set(FRUIT, randomX, randomY);
}
}
Thanks for the great tutorials.
Max,
i refactored this function and as per console.time() it is a lot faster.
The original version is executed in 0.300-500ms, this one in 0.010-0.020.
I found that interesting.
function setFood() {
var randomX= Math.round(Math.random() * (grid.width - 1)),
randomY= Math.round(Math.random() * (grid.height - 1));
}
Thanks for the great tutorials.