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
Tout de suite, quand on clique sur le bouton vert, on cache.
Right away, when we click the green button, we hide it.
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.
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,
on montre. Voilà, là je vois.
we show it. There—we can see it now.
tout de suite apparaître les tirs.
Right away, the shots appear.
Alors maintenant, au lieu de répéter indéfiniment avancer de 10.
Now, instead of repeating ‘move 10 steps’ endlessly,
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.
Donc ici, on va répéter jusqu'à.
So here, we’ll repeat until…
Et on va aller dans les capteurs et on a
We’ll go into the Sensors category, and there’s
ici le bord touché.
‘touching edge’ here.
Donc on va répéter jusqu'à ce que le bord soit touché.
So we’ll repeat until the edge is touched.
Donc on va relancer.
So let’s run it again.
avec le nouveau script jusqu'à ce que le bord soit touché.
Run the new script until the edge is touched.
Donc ici, ce que je vois, c'est que les tirs restent visibles.
Here, I notice the shots remain visible.
Donc une fois que le bord est touché, on va cacher les tirs.
So once the edge is touched, we’ll hide the shots.
Donc ici, les nouveaux tirs vont disparaître.
So these new shots will disappear.
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,
sorcière, je veux que si la sorcière est touchée,
I want them to disappear as soon as the witch is touched,
alors ça disparaît ici.
and vanish right here.
Donc je vais rajouter une condition.
So I’ll add a condition.
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’.
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.
Alors dans les opérateurs,
In the Operators category,
je vais prendre la fonction ou,
I’ll select the ‘or’ operator,
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,
je mets le bord touché.
‘touching edge’.
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,
les tirs s'arrêtent.
the shots stop.
Alors pour faire disparaître ceux qui sont restés tout à l'heure,
To remove the bullets remaining just now,
donc soit ça s'arrête quand le bord est touché,
they stop either when hitting the edge,
soit ça s'arrête quand la sorcière est touchée.
or when hitting the witch.
Alors là, j'ai un script qui doit être complet pour le tir.
Here, I need a complete script for shooting.
Donc j'ai le script du lutin initial.
This is the script for the initial sprite.
Donc il est caché, on a réduit la taille, ça c'est son initialisation,
It’s hidden and resized—this is its initialization,
et il est collé sur le vaisseau.
and it’s attached to the spaceship.
Ensuite, toutes les secondes, on crée un
Then, every second, we create a
Et ce clone se dirige vers la sorcière.
clone that moves toward the witch.
Donc ce clone, il est montré, il se dirige vers la sorcière.
This clone appears and heads toward the witch.
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,
et une fois qu'il a touché l'un ou l'autre, il est caché.
and once it hits either one, it disappears.
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,
on va attendre par exemple entre une et trois secondes,
we’ll wait randomly between one and three seconds,
ou entre zéro et trois secondes,
or even between zero and three seconds,
comme ça on ne peut pas prévoir
so players can’t predict
quand le tir va être fait.
when the shot will fire.
Donc ici, là le jeu est un petit peu modifié.
So here, the game has been slightly modified.
Et on va rajouter un script sur la sorcière.
Next, we’ll add a script to the witch.
Maintenant, on va pouvoir dire que ce script que j'ai ici.
Now, we can use this script here.
On va le rajouter dans le répéter indéfiniment.
We’ll place it inside the ‘forever’ loop.
Ce script va être fait lorsque le tir est touché.
This script runs when the bullet gets hit.
Donc ici, dans contrôle, on va
So, in the ‘Control’ category, we will
attendre que le tir soit touché.
wait for the moment the bullet is hit.
Donc je vais rajouter
So, I’ll add
une condition, si, pardon.
a condition: if… sorry.
Si le tir est touché, s'il veut bien se rajouter,
If the bullet is hit and it’s willing to re-add itself,
je sais pas pourquoi il se rajoute pas au bon endroit.
I don’t know why it isn’t added to the right spot.
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’,
c'est tiré touché, alors la sorcière.
but ‘bullet-hit’, then the witch.
Voilà ce qui s'est passé à l'écran, et je
This is what happens on screen, and I
stoppe tout, le jeu s'arrête.
immediately stop everything—the game ends.
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.
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.
Voilà, donc gardez ce script ici qui est
Here it is—this script about using clones
très important sur l'utilisation des clones.
is very important—please keep it.
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;
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.
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.
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.
Donc ce que j'avais mis dans la vidéo
In the earlier video intro, I mentioned that
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.
un clone. Comme ça, chaque tir a une couleur différente.
That way, each bullet has a different color.
Donc on peut rajouter évidemment toujours des choses sur un jeu.
Of course, we can always add more features to the game.
Voilà, ici on va changer de couleur à chaque fois le tir,
See? Here, the bullet changes color each time it’s fired,
et c'est donc la fin de ce script.
and that concludes this script.
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
voir comment faire sauter un lutin.
learn how to make a sprite jump!
À bientôt!
See you soon!