xxxxxxxxxx
69
// Integrating our code into the Pac-Man sketch (Step 3 of 3)
let eaten = new Array(100);
let score = 0;
function updateEaten() {
for (let a = 0; a < 10; a++) {
for (let b = 0; b < 10; b++) {
let k = a * 10 + b; // k == the current food
let x1 = mouseX; // PacMan's x coordinate // 1) DELETE
let y1 = mouseY; // 2) DELETE
let x2 = 33 + a * 48; // current food's x coordinate
let y2 = 33 + b * 48;
let distance = dist(x, y, x2, y2); // 3) Change x1 to x
// and y1 to y
if (distance < 10) {
eaten[k] = true;
}
}
}
}
function drawFood() {
for (let a = 0; a < 10; a++) {
// Horizontal dots
for (let b = 0; b < 10; b++) {
// Vertical dots
let k = a * 10 + b;
if (eaten[k] === false) {
// print("-------");
// print(a + ", " + (a * 10));
// print(b);
// print("--");
// print((a * 10) + b);
fill(180, 130, 100);
ellipse(33 + a * 48, 33 + b * 48, 5, 5);
}
}
}
}
function eatenFalse() {
for (let i = 0; i < 100; i++) {
eaten[i] = false;
}
eaten[48] = true;
}
function updateScore() {
let newScore = 0;
for (let i = 0; i < 100; i++) {
if (eaten[i] === true) {
newScore++;
}
}
score = newScore;
}
function drawScore() {
textSize(15);
fill(0);
text("Your score is: " + score, 35, 520);
}