xxxxxxxxxx
39
let snake;
let rez = 20;
let w, h;
let food;
let speed = 12;
function setup() {
createCanvas(floor(windowWidth - 2), floor(windowHeight - 2));
reset();
}
function reset() {
frameRate(speed);
w = floor(width / rez);
h = floor(height / rez);
snake = new Snake();
foodLocation();
}
function draw() {
background(0);
scale(rez);
if (snake.eat(food)) {
foodLocation();
snake.grow();
}
snake.update();
snake.show();
if (snake.endgame()) {
console.log("END");
background(255, 0, 0);
noLoop();
}
fill(255, 0, 0);
noStroke();
rect(food.x, food.y, 1, 1, 0.3);
}