A2 · Episode 4 · 5:05

Moving the Monkey with Keyboard Arrows

This episode teaches how to program a monkey sprite to move up, down, left, and right using keyboard arrow keys. It explains the relationship between movement direction and the X (horizontal) and Y (vertical) coordinate axes, and how positive or negative values affect motion.

Source:ericgrisperez / tube-numerique-educatif.apps.education.fr · License:CC BY 4.0

Transcript

  1. Voyons maintenant comment déplacer le singe sur l'écran.

    Now let's see how to move the monkey on the screen.

  2. Je vais donc ici te proposer un défi avec des blocs que j'ai préparés,

    So here, I’ll offer you a challenge

  3. à toi de les remettre dans le bon ordre.

    using blocks I’ve prepared—you need to arrange them in the correct order.

  4. Tu peux mettre pause sur la vidéo et ensuite remettre lecture une fois que tu as

    You can pause the video

  5. terminé ton programme pour vérifier la correction.

    and then resume playback once you’ve finished your program to check your answer.

  6. Je te propose donc les blocs suivants quand la touche espace est pressée,

    Here are the blocks I’m giving you: when the space key is pressed,

  7. donc ici en quatre fois,

    so four times in total,

  8. ajouter dix à x présent deux fois et ajouter dix à y présent deux fois.

    add 10 to x twice, and add 10 to y twice.

  9. Tu peux ici venir changer les valeurs en appuyant sur les menus déroulants pour voir

    You can click the dropdown menus here to change values,

  10. apparaître l'ensemble des touches de ton clavier,

    to see all the keys on your keyboard appear,

  11. et tu peux venir saisir dans les champs en blanc ici des valeurs.

    and you can type values directly into these white input fields.

  12. Il suffit simplement d'appuyer dessus et de saisir

    Just click it,

  13. un nouveau nombre.

    then type a new number.

  14. Ton défi consistera à ce que le singe puisse se déplacer en haut,

    Your challenge is to make the monkey move upward,

  15. en bas, à droite et à gauche en utilisant les flèches de ton clavier.

    downward, rightward, and leftward using your keyboard arrow keys.

  16. À toi de jouer!

    It’s your turn now!

  17. Voyons maintenant la correction.

    Now let’s look at the solution.

  18. Pour commencer, ici tu peux voir que le bloc d'événement qui commencera le programme

    To begin, here you can see that the event block which starts the program

  19. est en fait une touche qui doit être pressée.

    is actually a key that must be pressed.

  20. Donc c'est le fait d'appuyer sur la touche qui déclenchera l'instruction à suivre,

    So pressing this key triggers the following instruction,

  21. ce qui déclenchera la réaction de ton lutin.

    which in turn triggers your sprite’s reaction.

  22. Donc ici, le défi que je t'ai lancé consistait à déplacer le singe en haut,

    So the challenge I gave you was to move the monkey upward,

  23. en bas, à gauche, à droite en utilisant les flèches du clavier.

    downward, leftward, and rightward using the arrow keys.

  24. Donc ici, les touches qui vont m'intéresser seront les touches haut,

    So the keys I’ll use are the up, down, left, and right arrow keys on my keyboard.

  25. bas, gauche et droite de mon clavier.

    That is, the up, down, left, and right arrow keys.

  26. Je vais simplement aller les chercher, donc flèche haut, flèche bas,

    I’ll simply go get them, so the up arrow, the down arrow,

  27. la flèche gauche et enfin la flèche droite.

    the left arrow, and finally the right arrow.

  28. À chaque fois qu'une touche sera appuyée,

    Each time a key is pressed,

  29. le singe devra réagir en répondant à une instruction.

    the monkey must respond to an instruction.

  30. Instruction que j'ai ici avec les blocs de mouvement bleus, ajouter.

    The instruction I have here uses these blue movement blocks—specifically, the ‘add’ command.

  31. Ajouter, nous retrouvons bien ici notre verbe d'action qui correspond bien à une

    ‘Add’—we indeed see here our action verb,

  32. instruction. Donc la première chose que je veux faire,

    which clearly corresponds to an instruction. So the first thing I want to do is:

  33. c'est que le singe se dirige vers le haut.

    make the monkey move upward.

  34. Donc pour aller vers le haut, il faut que je me pose la question sur quel axe le

    To move upward, I need to ask myself: on which axis should the monkey move?

  35. singe doit travailler.

    On which axis should the monkey move?

  36. Est- ce qu'il doit travailler sur l'axe X, ici, l'axe des abscisses,

    Should it move along the X-axis—the horizontal axis—

  37. ou sur l'axe des ordonnées, qui est vertical?

    or along the vertical axis—the Y-axis?

  38. La bonne réponse est effectivement l'axe des ordonnées Y, ici en

    The correct answer is indeed the Y-axis—the vertical axis—

  39. bleu, pour travailler de haut en bas.

    shown here in blue, used for moving up and down.

  40. Donc le premier bloc qui va m'intéresser pour aller vers le haut,

    So the first block I’ll need to move the monkey upward is:

  41. il me faudra un de ces deux blocs.

    either of these two blocks.

  42. Ici, ils sont identiques.

    Here, they’re identical.

  43. Mon singe doit se diriger vers le haut, donc je dois ajouter une valeur positive.

    My monkey must move upward, so I need to add a positive value.

  44. On se souvient que la partie en haut de l'écran, dans ces deux cases ici,

    Recall that the top part of the screen—in these two boxes here—

  45. correspond à une ordonnée positive.

    corresponds to a positive Y-coordinate.

  46. Donc ici, quand la touche flèche haut est pressée, je vais ajouter 10 à y.

    So when the up-arrow key is pressed, I’ll add 10 to y.

  47. Je peux tester mon programme immédiatement, j'appuie sur la touche haut.

    I can test my program right away—I press the up arrow key.

  48. Et ici, je vois bien effectivement que mon singe se déplace lorsque j'appuie sur mon

    And here, I clearly see that my monkey moves when I press a key on my keyboard.

  49. clavier. Ensuite, je voudrais faire redescendre mon singe,

    Next, I’d like to make my monkey move back down,

  50. je vais donc m'intéresser à la flèche bas.

    so I’ll focus on the down arrow key.

  51. Ici, je vais ajouter également quelque chose à y, mais cette fois- ci,

    Here, I’ll also add something to y, but this time,

  52. ce sera une valeur négative.

    it will be a negative value.

  53. Donc devant mon 10 pixels, je vais ajouter- 10, ce qui

    So before my 10 pixels, I’ll add -10, which

  54. va permettre en ajoutant mon bloc souffle flèche bas d'avoir un singe qui descend à

    will make the monkey move downward again when I add the ‘down arrow’ block.

  55. nouveau. Alors que se passe- t- il si on change la valeur de 10 par exemple par 100?

    So what happens if I change 10 to, say, 100?

  56. Ici j'ai mis 100 sur la flèche haut, et lorsque j'appuie,

    Here I’ve set 100 for the up arrow, and when I press it,

  57. mon singe augmente à chaque fois de 100.

    the monkey rises by 100 each time.

  58. C'est ce qui va me permettre d'aller plus ou moins vite.

    This lets me control how fast or slow it moves.

  59. Si je mets une valeur de 2 sur Y, je vais faire la même chose ici, - 2.

    If I set Y to 2, I’ll set it to -2 here as well.

  60. Lorsque j'appuie, mon singe mettra beaucoup plus de temps.

    When I press it, the monkey will take much longer to move.

  61. Il faudra que j'appuie beaucoup plus de fois pour le faire descendre.

    I’ll need to press it many more times to make it go down.

  62. Nous allons ici laisser la valeur de 10 pixels

    We’ll keep the value of 10 pixels for both directions,

  63. pour les deux.

    that is, up and down.

  64. voyons maintenant pour la flèche gauche et la flèche droite donc ici je dois me

    Now let’s look at the left and right arrows: for the first one, I need to move the sprite

  65. déplacer pour la première flèche vers la gauche

    to the left,

  66. Donc pour aller vers la gauche, je vais aller de ce côté- là.

    so moving left means going in this direction.

  67. Je m'aperçois sur l'axe des abscisses que les valeurs sont négatives,

    I notice that values on the x-axis are negative,

  68. donc si je veux aller vers la gauche,

    so if I want to go left,

  69. il faudra bien que j'ajoute une valeur négative, donc de moins dix pixels.

    I must add a negative value—specifically, -10 pixels.

  70. Je viens mettre mon bloc en dessous, voilà qui est fait.

    I place the block below—done.

  71. Je peux tester.

    I can test it.

  72. Pour l'instant, tout fonctionne.

    So far, everything works.

  73. Ne me manque que la flèche droite.

    Only the right arrow remains to be set up.

  74. Si je veux aller sur la droite,

    If I want to go right,

  75. je vois que je me dirige vers des valeurs positives,

    I see I’m moving toward positive values,

  76. donc j'ajoute une valeur positive sur l'axe des abscisses.

    so I’ll add a positive value on the x-axis.

  77. Ici, mon programme est prêt, donc j'appuie sur le drapeau vert,

    Here, my program is ready, so I click the green flag.

  78. mon singe se met à sa place, je vais vers le haut, je me déplace.

    My monkey immediately goes to its position and moves upward.

  79. etc. Je n'ai plus qu'à aller chercher un arrière- plan pour commencer mon jeu.

    And so on. I just need to pick a background to start my game.