ุงู†ุชู‚ู„ ู„ู„ู…ุญุชูˆู‰
Robo EgyptRobo Egypt
โ˜ฐ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the โ€œCatch Roboโ€ game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

๐Ÿ› ๏ธ Section project: control Robo

Section 4: EventsLesson 4.3 ยท โฑ 12 min

Make a character you control with the keyboard, like the start of any game.

๐ŸŽฏ Project goal
The four arrows move Robo in every direction, the space key makes him jump, and clicking him makes him say Hi!

Steps

  1. Make a flag script that puts Robo in the middle.
  2. Make 4 scripts for the arrows: change x or change y by 10 or -10.
  3. Make the space script: change y by 50, then a short wait, then change y by -50.
  4. Make the script for clicking the character.
๐Ÿงฉ Getting started
Blocks: when ๐Ÿšฉ clicked, go to x: (0) y: (0)
๐Ÿงฉ Up arrow
Blocks: when (up arrow) key pressed, change y by (10)
๐Ÿงฉ The jump
Blocks: when (space) key pressed, change y by (50), wait (0.3) seconds, change y by (-50)
๐Ÿ“Œ Note
Here every script starts with a different event, and they all work on the same character.

๐Ÿ“Œ Another example: Robo walks facing his way

Every arrow points Robo the way he moves, and switches his costume so he seems to walk.

Blocks: when ๐Ÿšฉ clicked, go to x: (0) y: (0)
Blocks: when (right arrow) key pressed, point in direction (90), move (10) steps, next costume
Blocks: when (left arrow) key pressed, point in direction (-90), move (10) steps, next costume
He walked 5 steps
He walked 5 steps
โœ๏ธ Practise
Build the whole control project here: the four arrows and the jump.
โœ๏ธ Practise here in the lessonor open the lab in a new page โ†—

๐ŸŽฏ Challenge yourself

Easy

Add the key 1 to bring Robo back to the middle (0, 0).

๐Ÿ‘€ Show the solution
Blocks: when (right arrow) key pressed, change x by (20)
Blocks: when (1) key pressed, go to x: (0) y: (0)
Blocks: when ๐Ÿšฉ clicked, go to x: (0) y: (0)
Back in the middle
Back in the middle
Medium

Make the space jump higher (80), and switch the costume at the start of the jump.

๐Ÿ‘€ Show the solution
Blocks: when (space) key pressed, next costume, change y by (80), wait (0.3) seconds, change y by (-80)
After the jump
After the jump
Hard

Diagonal moves: the key d goes up-right, and the key a goes up-left (x and y together).

๐Ÿ‘€ Show the solution
Blocks: when ๐Ÿšฉ clicked, go to x: (0) y: (0)
Blocks: when (d) key pressed, change x by (10), change y by (10)
Blocks: when (a) key pressed, change x by (-10), change y by (10)
d three times, then a
d three times, then a
Finished the lesson? Mark it so your progress counts.