A2 · Episode 11 · 4:34

Creating Shooting Mechanics with Clones in Scratch

This episode teaches how to implement automatic shooting in Scratch using clones—creating multiple identical projectiles from a single sprite, rather than managing countless separate sprites, and covers basic clone behavior, positioning, and movement toward a target.

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

Transcript

  1. Coder un jeu avec Scratch, dixième épisode dans lequel nous allons voir comment

    Coding a game with Scratch—this is episode ten, in which we’ll learn how to

  2. créer un tir en utilisant les clones.

    create shots using clones.

  3. Alors dans un jeu de tir, en général,

    In a shooting game, generally,

  4. on veut qu'il y ait autant de tirs que possible.

    we want as many shots as possible.

  5. Alors si on devait avoir un lutin par tir,

    So if we used one sprite per shot,

  6. nous aurions quelque chose de tout à fait ingérable parce que nous aurions une

    we’d end up with something completely unmanageable—since we’d have

  7. quantité énorme de lutins à gérer.

    a huge number of sprites to manage.

  8. Donc ici, nous utilisons les clones,

    So here, we use clones—

  9. c'est- à- dire que nous avons un seul lutin et à chaque fois que l'on tire,

    that is, we use just one sprite, and each time we shoot,

  10. donc ici à chaque fois que le vaisseau spatial tire par exemple,

    for example, each time the spaceship fires,

  11. on crée un clone du lutin qui sert de tir.

    we create a clone of that sprite to serve as the shot.

  12. Voilà, donc c'est ce que nous allons apprendre à faire avec Scratch et nous y allons

    That’s it—this is what we’ll learn to do with Scratch, and we’ll get started right away!

  13. tout de suite.

    Let’s go!

  14. Alors nous y voici, donc j'ai mes deux lutins,

    Here we are—so I have my two sprites:

  15. le vaisseau spatial et la sorcière,

    the spaceship and the witch.

  16. les scripts sont ceux que nous avons déjà écrits dans un épisode précédent.

    The scripts are the ones we already wrote in a previous episode.

  17. Donc pour la sorcière ici, j'ai l'initialisation ainsi que les déplacements avec les

    For the witch, I have an initialization script, plus movement scripts

  18. touches du clavier.

    controlled by keyboard keys.

  19. J'ai rajouté un petit script qui pour le moment ne commence pas parce qu'on n'a pas

    I’ve also added a small script—it doesn’t start yet, since we don’t need it yet—but

  20. encore. nécessaire, mais il s'agit d'un effet graphique,

    it’s a visual effect.

  21. je peux le lancer pour voir ce que ça donne,

    I can run it now to see what it does:

  22. donc juste une pixelisation pour faire disparaître la sorcière lorsqu'elle aura été

    It’s just pixelation to make the witch disappear

  23. touchée par les tirs du vaisseau.

    when she’s hit by the spaceship’s shots.

  24. Et pour le vaisseau, un script tout simple,

    And for the spaceship, there’s a very simple script:

  25. une initialisation et puis il s'oriente en permanence vers la sorcière.

    an initialization, then it constantly rotates to face the witch.

  26. Donc si je lance le jeu, voilà ce qui se passe,

    So, if I launch the game, this is what happens:

  27. il n'y a pas de tir pour le moment. Alors pour le tir,

    There’s no shooting yet. So, for shooting,

  28. nous avons un seul lutin et c'est ça la difficulté et ça va être ça la force de

    we use just one sprite—and that’s the challenge.

  29. Scratch, c'est qu'on peut utiliser un seul lutin pour faire tous les tirs,

    Yet this is also Scratch’s strength:

  30. on n'a pas un lutin par tir, sinon il faudrait une infinité de lutins si on veut que

    we can use a single sprite for all shots.

  31. le jeu puisse ne jamais s'arrêter.

    We don’t need a separate sprite for each shot—otherwise, to let the game run forever, we’d need infinitely many sprites.

  32. Donc ce que nous allons faire, c'est que déjà on va commencer un script,

    So here’s what we’ll do: first, create a script

  33. quand le drapeau est cliqué, ce lutin nous allons le réduire,

    that runs when the green flag is clicked—let’s shrink this sprite,

  34. déjà il est un petit peu trop gros ici,

    since it’s currently a bit too large,

  35. on va le montrer déjà.

    and let’s show it right away.

  36. Pour voir où il est.

    to see where it is.

  37. Donc le lutin ici, il n'est pas à sa taille réelle,

    Here, this sprite isn’t at its original size,

  38. là je l'ai déjà réduit auparavant.

    I’ve already shrunk it earlier.

  39. Donc on va le mettre à 50% de sa taille initiale,

    So we’ll set it to 50% of its original size,

  40. et on va le faire aller

    then move it

  41. sur le vaisseau.

    onto the spaceship.

  42. Donc les tirs partent du vaisseau, donc voyons,

    Since shots fire from the spaceship, let’s see:

  43. on peut aller au pointeur de la souris, mais on peut aller aussi vers les lutins,

    We could move it toward the mouse pointer,

  44. on le fait aller sur le vaisseau.

    but we can also move it toward another sprite—so let’s move it onto the spaceship.

  45. Donc là, quand je clique, hop, le lutin, il est sur le vaisseau,

    See? When I click, the sprite instantly lands on the spaceship,

  46. ça va être le point de départ

    making this the starting point for shots.

  47. des tirs. Alors le tir, il va être

    The shooting will be automatic—

  48. automatique, ce n'est pas un tir, on peut le déclencher au clavier,

    it won’t be triggered by keyboard input,

  49. par exemple, dans un jeu de tir.

    as in some shooting games.

  50. Ici, le tir va se faire automatiquement.

    Here, shooting happens automatically.

  51. Donc ce que l'on va faire, c'est qu'on va répéter indéfiniment.

    So, what we’ll do is repeat the following actions indefinitely.

  52. créer, on va attendre une seconde, on va attendre

    Create an object, then wait one second, then wait—

  53. toutes les secondes pour faire un tir, donc on va attendre une seconde,

    one second each time to fire a bullet, so we’ll wait one second,

  54. et on va ici créer un clone.

    and then create a clone here.

  55. Donc ici dans les contrôles,

    In the ‘Control’ category,

  56. je peux créer un clone de moi- même.

    I can create a clone of myself.

  57. Alors un clone, ça va être un lutin identique qui va avoir un mouvement qui lui est

    A clone is an identical sprite,

  58. propre. Donc on va créer un clone

    with its own independent movement. So we’ll create a clone of the bullet.

  59. de la balle. Et ce clone, il va avoir un script pour lui.

    And this clone will have its own script.

  60. Et ce script, il commence par l'événement" Quand je commence par un clone".

    This script starts with the event ‘When I start as a clone’.

  61. Donc on crée le clone et le script de ce clone,

    We create the clone, and its script,

  62. il va être à part du script pour la balle ici.

    will be entirely separate from the bullet’s original script here.

  63. Donc quand je commence par un clone,

    So, when starting as a clone,

  64. comme un clone pardon, on va s'orienter vers la sorcière

    sorry—‘when starting as a clone’—we’ll face the witch,

  65. et on va avancer.

    and then move forward.

  66. Donc on se dirige vers la sorcière

    We face the witch,

  67. et on va avancer, on va répéter indéfiniment.

    and move forward, repeating indefinitely.

  68. Avancer. Donc on va voir ce que ça donne.

    Move forward! Let’s see how it works.

  69. Donc quand je clique ici,

    When I click here,

  70. voilà, j'ai un clone qui est créé et qui se dirige vers la sorcière,

    there it is—a clone is created and moves toward the witch,

  71. puisqu'il est orienté vers la sorcière au moment où il est lancé.

    since it’s already facing the witch at the moment it’s launched.

  72. Alors plusieurs choses à corriger, ici on a encore beaucoup de choses à faire.

    But several things still need fixing.

  73. Alors déjà quand il touche la sorcière, il se passe rien.

    First, nothing happens when it touches the witch.

  74. Donc on rajoutera ça après sur le script de la sorcière.

    We’ll add that later in the witch’s script.

  75. Mais voyez, les tirs restent là contre le bord.

    But notice—the bullets remain stuck against the edge of the screen.

  76. Donc on va arrêter ça et on va rajouter quelque chose.

    So we’ll stop this and add something.

  77. Déjà, la balle qui reste toujours sur le vaisseau ici, ça on va la cacher.

    First, the ball that always stays on the spaceship here—we’ll hide it.

  78. Donc dans Apparence, on va cacher.

    So in Appearance, we’ll choose Hide.