A very interesting sprite is the ghost.
The ghost of our game will be able to appear in random stages for a few seconds.
In these seconds it will try to catch the dog. If it does, the game will end.
It is therefore an opponent.
Another important detail regarding the behavior of the ghost is that it will be able to pass through walls.
So when we will add the maze we will not have to change this scenario as there is no interaction between them.
Let's add the ghost from the scratch library.
Its size is quite large. I'll cut it down a bit. Let’s say 60%.
I will also change its axis of rotation to horizontal so it never looks upside down.
We will probably need two scenarios running in parallel.
In the first scenario, throughout the game the ghost will chase the dog.
be shown and hidden for a random period of time.
Let me start with the 2nd scenario.
We will definitely need the repeat structure "Forever" as we want the show-hide process to continue throughout the game.
At first we do not want it to appear. From the "looks" instruction palette, use the "hide" instruction.
Then we want it to remain invisible for a random period of time between 5 to 10 seconds.
You need to combine the 'wait' instruction - you will find it in the “control” panel with the scratch instruction that creates random numbers from the palette “operators”.
Very nice.
Once this random time has passed, we want the ghost to move at a random area of our stage and then to appear again.
It is important not to forget to set and then display a random time frame for the ghost to appear until the instructions start running from the beginning.
Let's create the script and try the outcome.
The script works very well. However, when the ghost appears, it remains still.
Also, its contact to the dog does not create any interaction. Let's fix it.
We will create a new scenario. The script will run throughout the game alongside the previous one.
The purpose is to make the sprite always look at the dog and move slowly towards it.
This scenario combines without a problem to the previous one as it does not cancel any of the actions that the previous one performs.
These ghost moves can be done either on the stage or not.
Let me now type the appropriate instructions.
For the duration of the game
Turn to the dog.
Move 1 step.
And if you touch the dog Stop everything!
Let me try it...
It works perfectly. Time to create the maze...