In this video, you will
control how your sprite moves
by pressing keyboard keys.
In the project you made today,
the sprite always moves towards the mouse-pointer.
This add on will make the sprite easier to control by
making it move when the arrow keys are pressed.
First, remove the point towards
mouse-pointer block, and set it aside.
Removing this block means that the sprite
will move constantly, you just need to
make it point in the right direction.
Go to the motion menu, and pull out the
point in direction block.
If you click on the value box,
you'll see some of the values are,
90 degrees right, negative 90 degrees, left,
zero degrees, up, and 180 degrees, down.
You will match those directions with keyboard keys.
Go to the events menu, pull out the when key pressed block,
and attach it to the point in direction block.
Next, choose the keys that will control your sprite.
Typically you use the arrow keys,
but those are being used to change the speed.
Other keys you might use include A, S, W and D.
Now, match each direction with a key.
Select W for the key press, and match it with up
in your point in direction block.
Test it to see if the sprite moves up when you press W.
To make the other keys function,
right click on the stack and click duplicate.
This creates a new stack that you can match.
For example, choose A and point
in direction, negative 90 left.
Test it to see if the sprite moves left.
Duplicate the stack again, and match S with down.
Duplicate the stack for the final time,
and match D with right.
At any time, test the code to see if it works.
You should have four new stacks that
allow you to control where the sprite moves
by pressing the A, S, W and D keys.
When you're finished, add new instructions
to the project page.
Under instructions, let the user know
to move the sprite using W, A, S and D keys.
Now it's your turn.
Make Tera stop following the mouse by
removing the point towards mouse-pointer
block from the stack.
Create key press movements by making
four new block stacks using when key pressed blocks
and point in direction blocks.
Then finally, add instructions to the project page.
Change the the character sprite’s looks based on the mouse pointer’s position.
Add background music to the project.
Use arrow keys to make Tera grow and shrink on command.
Make the sprite move using the keyboard instead of the mouse.
Create another sprite that can collide with your character sprite.
Add your own costume to your sprite.
Sign in to track your progress and earn badges