In this game, the player must keep the teeth clean by scrubbing away the slime that forms on the teeth. If the player isn’t quick enough cracks will start to form on the teeth and they will become rotten.
Sprites
Make our background a colour other than white, we will be using white as our teeth colour.
Slime Sprite
The slime sprite needs to have a second costume, this is going to be the crack sprite. This can be added by selecting the file icon in the costumes tab.
Toothbrush
We want the toothbrush to follow the players mouse around the screen, to make this happen we are going to use the following script:
Variables
We need to keep track of how much time has passed and how many cracks have formed on the players teeth. Create two new variables; Cracks and Time
Slime
We want some slime to appear randomly on our teeth, we are going to use a clone of the slime so that we can have many patches of slime on the screen at the same time.
First, we make sure the number of cracks starts at zero when our game is starting up. Next, we make sure that the sprite costume is set to slime, we will change it to a crack later if it doesn’t get cleaned up.
Now we create a new slime clone every second. You can speed this up for more slime!
When our clone starts, we want to make sure it’s positioned in the correct spot.
I’ve picked numbers that match the left and right sides of my mouth sprite (X position) and the top and bottom heights of the mouth sprite (Y position).
I used the x and y positions below the game to find the correct positions.
We want to make sure that our slime only lands on the teeth sprite, so let’s test to see if it is touching white.
Now if we test our game we find that we have spots of slime getting added to our teeth.
We need a way to get rid of them when the toothbrush is over them.
We repeat 100 times a check to see if the mouse down and if the clone is touching the toothbrush. If it is, then we delete the clone as it has been cleaned up.
Try changing the repeat number to make the slime last longer or shorter. After the repeat block is done, we add one to the cracks variable and then switch to the crack costume to show a different image on the screen.
Game Score
On our teeth sprite, we check to see if the number of cracks is large enough to stop our game. We also have a timer that advances every second, this can be used to show the player how long they kept their teeth in good condition for.