In this add-on, you're going to do something
completely different and change how the game
is played and won.
Before, the object of the game was to get to the goal
as fast as possible.
In this add-on, you'll program the goals sprite
to chase the player sprite.
Instead of trying to catch the goal,
the player will have to stay away from it.
To start, click on goal sprite.
For the goal sprite to chase a player,
it needs to point towards the player.
Then move forever, repeatedly.
To do that, go to the motion menu
and drag on a point toward block.
Then change the value to the name of the player sprite.
When that block is clicked,
the goal sprite will point toward the player.
Next, the goal sprite needs to move toward the player.
Drag on a move block and attach it
to the point towards block.
When that block sec is run,
the goal sprite points toward the player then moves.
Add a forever loop, to make this block sec run forever.
Test this!
The goal sprite points toward the player,
moves ten steps and so on.
This ensures that no matter where the player is,
the goal sprite will point towards it
then move forward.
Hmm, that seems way too fast.
Take at what the value of the move block to slow it down.
Great, now the goal sprite moves.
Program the goal sprite's position to reset
when the game begins.
Drive the goal sprite to where it should start,
then add a go to XY block and place it at
the top of its stack.
Add a one flight quick block to start this code.
Click the flag to test it.
Great, it works!
But it could be better.
The player says, "you win", when the goal sprite touches it.
That no longer fits how the game works.
Select the player sprite and change the text
in the say block to something like, "you got caught."
Notice that the goal sprite bounces back and forth
really fast when it touches the player sprite.
That's because the goal sprite is still trying to move
toward the player over and over.
Since the player isn't moving, the goal sprite just bounces.
The goal sprite should move until it touches
the player sprite, not forever.
A repeat until block will repeat the actions inside it
until the condition is met.
In this case, it will make the goal keep moving
and pointing toward the player
until it touches it.
Select the goal sprite, replace the forever block
with a repeat until block from the control menu.
From the sensing menu, adding touching block
as a condition.
From the drop down, select the name of the player sprite.
Now this reads, repeat moving until
touching a player sprite.
Click the flag to test.
Great, it works.
Now it's your turn, make the goal sprite chase the player
using point towards, move and forever blocks.
Change the message at the end of the game.
Stop the goal sprite from moving by
replacing the forever block with
repeat until and touching blocks.