In this video, you will create
another sprite that can collide with your character sprite.
This will introduce a new
computer science concept: conditional statements.
For two sprites to bump into each other,
you first need to add a second sprite.
Click on the New Sprite icon and choose a sprite
from the library.
This add-on uses the Pico sprite,
but you can choose any sprite.
To get your new sprite to move like your character sprite
click on the sprite, in this case Terra,
and drag its code stack over to the new sprite.
When you click on the new sprite,
it should have the exact same code as your original sprite.
Remove the points towards mouse pointer block
so your new sprite won't follow the mouse pointer.
When you test it, the new sprite should move back and forth.
Change its direction by adding a turn 15 degrees block
to the stack before the forever loop.
Test the project.
You should have two sprites that stamp repeatedly.
The new sprite should always move around the screen.
To make something happen when the sprites collide,
pull out a if then block from the control menu,
and place it inside the forever loop.
Then go to the sensing menu.
Pull out the touching block and add it to the if block.
Change the value in the touching block
to the name of your character sprite.
You just created a conditional statement
that tells the computer if something happens,
then perform this action.
This condition reads: if the new sprite touches Tera,
then do something.
Make something happen by adding blocks
to the then portion of the if and then block.
You can program any action,
but this project uses a say block
with the words Hey!
I'm walking here.
When the project is tested, if the new sprite
touches Tera, it says something.
There are many possible things you could add,
like a next costume block, or a sound.
You can also add another if statement
to your character sprite to make it
react to the collision, as well.
Tinker with possibilities and have fun creating.
Now it's your turn.
Create a new sprite
and copy your original sprite's code to it.
Remove the point towards mouse pointer block.
Finally, add an if statement,
a touching sprite condition, and other blocks
to make something surprising happen.