Hideable treat

You have a treat, cat wants a treat.

We need to make the treat disappear when it gets close to the cat’s mouth. Om nom.

⌨️ Make a boolean

At the top of our code [before the setup() function], declare a new boolean called showTreat and set it equal to true.

let showTreat = true;

function setup() {
  // ...
}

This boolean will remember if our treat is uneaten (or not).

⌨️ Add an if statement to our treat [aka the ellipse()]

We will use an if statement to control whether or not we draw our treat. This is important if the cat eats our treat, because eaten treats shouldn’t be visible [according to science].

if(showTreat) {
	ellipse(mouseX, mouseY, 30, 20);
}
Translate this to plain English

You can test whether it’s working by changing let showTreat = true to false. Does the treat disappear? [Remember to change it back to true]

Next up…

Treat goes bye-bye