A2 · Episode 12 · 4:25

Building a Shooting Game with Scratch

This episode teaches how to create bullet clones in Scratch, control their movement until they hit the edge or a character, hide them upon impact, add randomness to firing intervals, and trigger game-over effects when the witch is hit.

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

Transcript

  1. Tout de suite, quand on clique sur le bouton vert, on cache.

    Right away, when we click the green button, we hide it.

  2. Mais ici, si je lance le jeu, du coup, les clones, ils sont cachés aussi.

    But here, if I start the game, the clones get hidden too.

  3. Donc ce qu'on va faire, c'est quand on commence par un clone,

    So what we’ll do is: when starting from a clone,

  4. on montre. Voilà, là je vois.

    we show it. There—we can see it now.

  5. tout de suite apparaître les tirs.

    Right away, the shots appear.

  6. Alors maintenant, au lieu de répéter indéfiniment avancer de 10.

    Now, instead of repeating ‘move 10 steps’ endlessly,

  7. On va le répéter jusqu'à ce que le bord de l'écran soit touché.

    we’ll repeat it until the edge of the screen is touched.

  8. Donc ici, on va répéter jusqu'à.

    So here, we’ll repeat until…

  9. Et on va aller dans les capteurs et on a

    We’ll go into the Sensors category, and there’s

  10. ici le bord touché.

    ‘touching edge’ here.

  11. Donc on va répéter jusqu'à ce que le bord soit touché.

    So we’ll repeat until the edge is touched.

  12. Donc on va relancer.

    So let’s run it again.

  13. avec le nouveau script jusqu'à ce que le bord soit touché.

    Run the new script until the edge is touched.

  14. Donc ici, ce que je vois, c'est que les tirs restent visibles.

    Here, I notice the shots remain visible.

  15. Donc une fois que le bord est touché, on va cacher les tirs.

    So once the edge is touched, we’ll hide the shots.

  16. Donc ici, les nouveaux tirs vont disparaître.

    So these new shots will disappear.

  17. Comme ceci. Mais dans le jeu, je veux pas que les tirs passent à travers la

    Like this. But in the game, I don’t want shots to pass through the witch,

  18. sorcière, je veux que si la sorcière est touchée,

    I want them to disappear as soon as the witch is touched,

  19. alors ça disparaît ici.

    and vanish right here.

  20. Donc je vais rajouter une condition.

    So I’ll add a condition.

  21. Donc on a déjà le bord touché, si la sorcière est touchée aussi.

    We already have ‘touching edge’—now we’ll also add ‘touching witch’.

  22. Donc on va répéter jusqu'à bord touché ou sorcière touchée.

    So we’ll repeat until either the edge is touched or the witch is touched.

  23. Alors dans les opérateurs,

    In the Operators category,

  24. je vais prendre la fonction ou,

    I’ll select the ‘or’ operator,

  25. et d'un côté, donc je mets la sorcière touchée, de l'autre côté,

    putting ‘touching witch’ on one side, and on the other side,

  26. je mets le bord touché.

    ‘touching edge’.

  27. Donc ici, je vois tout de suite, si la sorcière est touchée,

    So here, I can immediately see that if the witch is hit,

  28. les tirs s'arrêtent.

    the shots stop.

  29. Alors pour faire disparaître ceux qui sont restés tout à l'heure,

    To remove the bullets remaining just now,

  30. donc soit ça s'arrête quand le bord est touché,

    they stop either when hitting the edge,

  31. soit ça s'arrête quand la sorcière est touchée.

    or when hitting the witch.

  32. Alors là, j'ai un script qui doit être complet pour le tir.

    Here, I need a complete script for shooting.

  33. Donc j'ai le script du lutin initial.

    This is the script for the initial sprite.

  34. Donc il est caché, on a réduit la taille, ça c'est son initialisation,

    It’s hidden and resized—this is its initialization,

  35. et il est collé sur le vaisseau.

    and it’s attached to the spaceship.

  36. Ensuite, toutes les secondes, on crée un

    Then, every second, we create a

  37. Et ce clone se dirige vers la sorcière.

    clone that moves toward the witch.

  38. Donc ce clone, il est montré, il se dirige vers la sorcière.

    This clone appears and heads toward the witch.

  39. Il avance tant qu'il n'a pas touché la sorcière ou le bord,

    It keeps moving until it hits either the witch or the edge,

  40. et une fois qu'il a touché l'un ou l'autre, il est caché.

    and once it hits either one, it disappears.

  41. On peut juste rajouter quelque chose pour le jeu, au lieu d'attendre une seconde,

    We can add a small variation to the game: instead of waiting exactly one second,

  42. on va attendre par exemple entre une et trois secondes,

    we’ll wait randomly between one and three seconds,

  43. ou entre zéro et trois secondes,

    or even between zero and three seconds,

  44. comme ça on ne peut pas prévoir

    so players can’t predict

  45. quand le tir va être fait.

    when the shot will fire.

  46. Donc ici, là le jeu est un petit peu modifié.

    So here, the game has been slightly modified.

  47. Et on va rajouter un script sur la sorcière.

    Next, we’ll add a script to the witch.

  48. Maintenant, on va pouvoir dire que ce script que j'ai ici.

    Now, we can use this script here.

  49. On va le rajouter dans le répéter indéfiniment.

    We’ll place it inside the ‘forever’ loop.

  50. Ce script va être fait lorsque le tir est touché.

    This script runs when the bullet gets hit.

  51. Donc ici, dans contrôle, on va

    So, in the ‘Control’ category, we will

  52. attendre que le tir soit touché.

    wait for the moment the bullet is hit.

  53. Donc je vais rajouter

    So, I’ll add

  54. une condition, si, pardon.

    a condition: if… sorry.

  55. Si le tir est touché, s'il veut bien se rajouter,

    If the bullet is hit and it’s willing to re-add itself,

  56. je sais pas pourquoi il se rajoute pas au bon endroit.

    I don’t know why it isn’t added to the right spot.

  57. Si le tir est touché, donc ici on va rajouter, c'est pas pointeur,

    If the bullet is hit, then here we’ll add not ‘pointer’,

  58. c'est tiré touché, alors la sorcière.

    but ‘bullet-hit’, then the witch.

  59. Voilà ce qui s'est passé à l'écran, et je

    This is what happens on screen, and I

  60. stoppe tout, le jeu s'arrête.

    immediately stop everything—the game ends.

  61. Donc je recommence le jeu, cette fois j'ai terminé l'écriture de mes scripts.

    Now I restart the game—I’ve just finished writing all my scripts.

  62. Donc si la sorcière est touchée, il y a une pixellisation et le jeu s'arrête.

    So, once the witch is hit, the screen pixellates and the game stops.

  63. Voilà, donc gardez ce script ici qui est

    Here it is—this script about using clones

  64. très important sur l'utilisation des clones.

    is very important—please keep it.

  65. Dès qu'il y a un jeu de tir, on a besoin d'utiliser des clones,

    Whenever there’s a shooting game, we must use clones;

  66. sinon il faudrait une infinité de lutins, ce qui n'est pas du tout gérable.

    otherwise we’d need infinite sprites—which is totally unmanageable.

  67. On peut juste rajouter une chose d'ailleurs que j'ai pas mis.

    By the way, we can actually add one more small feature—I didn’t include it earlier.

  68. On peut changer de costume ici, le tir il a plein de costumes différents.

    For example, we can switch the bullet’s costume here—it has many different ones.

  69. Donc ce que j'avais mis dans la vidéo

    In the earlier video intro, I mentioned that

  70. de départ tout à l'heure, c'est que j'allais au costume suivant avant de créer

    I’d switch to the next costume before creating a clone.

  71. un clone. Comme ça, chaque tir a une couleur différente.

    That way, each bullet has a different color.

  72. Donc on peut rajouter évidemment toujours des choses sur un jeu.

    Of course, we can always add more features to the game.

  73. Voilà, ici on va changer de couleur à chaque fois le tir,

    See? Here, the bullet changes color each time it’s fired,

  74. et c'est donc la fin de ce script.

    and that concludes this script.

  75. Cet épisode est terminé, ne manquez pas le prochain épisode dans lequel nous allons

    This episode is over—don’t miss the next one, where we’ll

  76. voir comment faire sauter un lutin.

    learn how to make a sprite jump!

  77. À bientôt!

    See you soon!