How to Make a Pong Game in Scratch | Tutorial
Summary
TLDREn este tutorial, Zoë del equipo de Scratch, también conocida como Zinnea, muestra cómo crear un juego de pong en Scratch. El juego consiste en controlar una paleta para evitar que un objeto toque la parte inferior de la pantalla. A lo largo del tutorial, Zoë guía a los espectadores para que puedan diseñar su propio juego con múltiples niveles y características personalizadas. Se explica cómo elegir un objeto, establecer el fondo, hacer que el objeto se mueva y rebote, añadir una paleta que se mueva con el mouse, y cómo hacer que el objeto rebote de la paleta. Además, se incluye cómo hacer que el juego termine si el objeto alcanza la parte inferior de la pantalla, y cómo agregar niveles y puntuación. El código completo del proyecto se encuentra en la descripción del video para que los usuarios puedan remixarlo y crear sus propios juegos.
Takeaways
- 🎮 Crea un juego de pong en Scratch, donde el objetivo es golpear un objeto para evitar que toque la parte inferior de la pantalla.
- 🏓 Selecciona un objeto para ser el que rebota, eligiendo entre una variedad de opciones como un corazón, un pez globo o una pelota.
- 🌊 Elige un fondo para tu juego, como la tablilla, para darle ambiente.
- 🔁 Utiliza un bucle 'siempre' para hacer que el objeto se mueva continuamente.
- 🔄 Agrega un bloque 'si en el borde, rebotar' para que el objeto rebote cuando choque con una pared.
- 🧭 Utiliza 'apuntar en dirección' para hacer que el objeto rebote en diferentes ángulos.
- 🕹️ Crea un mando para el paddle (pala) que se mueva con el mouse, utilizando la posición X del mouse para controlar la posición del paddle.
- 🏐 Agrega un bloque 'si' para hacer que el objeto rebote si choca con el paddle.
- 🔢 Utiliza una variable para llevar el puntaje y actualiza el puntaje cada vez que el jugador golpea el objeto.
- 🔄 Encierra el bloque de rebote en un bucle 'siempre' para que el objeto siempre verifique si choca con el paddle.
- 🚫 Agrega un evento que detenga el juego si el objeto toca la parte inferior de la pantalla.
- 📈 Crea niveles adicionales en tu juego, esperando que el puntaje alcance un cierto número antes de cambiar de fondo.
Q & A
¿Qué es un juego de pong en Scratch?
-Un juego de pong en Scratch es un tipo de juego en el que se tiene una paleta y se trata de evitar que un objeto específico toque la parte inferior de la pantalla.
¿Cómo se selecciona el objeto que se usará en el juego de pong?
-Para seleccionar el objeto, se hace clic en el botón que dice 'Choose a Sprite' y luego se elige el objeto deseado, que puede ser un corazón, un pez globo, una estrella o cualquier otro.
¿Cómo se establece el fondo de la pantalla para el juego?
-Para elegir un fondo, se pasa el cursor sobre el botón que dice 'choose a backdrop' y se hace clic en 'choose' para seleccionar el lugar deseado para el juego, como la tablilla de la playa.
¿Cómo hacer que el objeto se mueva en el juego de pong?
-Para hacer que el objeto se mueva, se arrastra el bloque 'move 10 steps' de la categoría motion y se coloca dentro de un bucle 'forever' para que el objeto se mueva continuamente.
¿Cómo evitar que el objeto se atasque en la pared?
-Para evitar que el objeto se atasque, se utiliza el bloque 'if on edge bounce' de la categoría motion, que hace que el objeto rebote al chocar con el borde.
¿Cómo hacer que el objeto rebote en diferentes direcciones en la pantalla?
-Se utiliza el bloque 'point in direction' de la categoría motion para establecer la dirección en la que apunta el objeto, lo que permite que el objeto rebote en diferentes direcciones.
¿Cómo se inicia el juego de pong en Scratch?
-Para iniciar el juego, se coloca un bloque 'when green flag clicked' en la parte superior del código para que el juego comience al hacer clic en la bandera verde.
¿Cómo se agrega una paleta al juego y cómo se hace que se mueva con el mouse?
-Se selecciona un nuevo Sprite para la paleta, y se utiliza el bloque 'mouse X' de la categoría sensing para hacer que la paleta se mueva a la posición X del mouse del jugador.
¿Cómo se logra que el objeto rebote cuando choca con la paleta?
-Se utiliza un bloque 'if' de la categoría control junto con un bloque de la categoría sensing que verifica si un Sprite toca otro Sprite para hacer que el objeto rebote si choca con la paleta.
¿Cómo se implementa el reinicio del juego si el objeto toca la parte inferior de la pantalla?
-Se agrega un Sprite de línea a la parte inferior de la pantalla y se utiliza un bloque 'stop all' de la categoría control para detener el juego si el objeto toca la línea.
¿Cómo se agregan niveles adicionales al juego de pong?
-Se crea una variable 'score' para hacer un seguimiento de la puntuación del jugador y se utiliza un bloque 'wait until' para avanzar a otro nivel cuando se alcance una cierta puntuación, cambiando el fondo a uno designado para el siguiente nivel.
¿Dónde puedo encontrar el código para este proyecto de juego de pong en Scratch?
-El código para este proyecto se encuentra en la descripción del video, donde se puede remix para personalizarlo o aprender cómo funciona.
Outlines
🎮 Creación de un juego de Pong en Scratch
Zoë de Scratch muestra cómo crear un juego de Pong. En este juego, el jugador controla una paleta para evitar que un objeto toque la parte inferior de la pantalla. Al final del tutorial, los espectadores podrán diseñar su propio juego con múltiples niveles y características. Se comienza eligiendo un objeto para el juego y un fondo, y luego se le da movimiento al objeto utilizando un bucle 'para siempre'. Se implementa la mecánica de rebote contra las paredes y se le da dirección al objeto para que rebote en distintas direcciones. Además, se explica cómo hacer que el objeto comience a moverse cuando se haga clic en la bandera verde.
🏓 Añadiendo una paleta y reacciones al golpear
Seguidamente, Zoë demuestra cómo añadir una paleta al juego y hacer que se mueva en función del movimiento del ratón del jugador. Utiliza el valor de la posición X del ratón para controlar la posición de la paleta en la pantalla. Luego, se implementa la interacción entre la paleta y el objeto, de modo que este último rebote cuando choque con la paleta. Esto se logra con un bucle 'para siempre' que verifica si el objeto está tocando la paleta y, en caso afirmativo, le da la vuelta 180 grados y se mueve en la nueva dirección. Además, se agrega un bloque 'esperar' para añadir un poco de aleatoriedad al rebote. Finalmente, se establece que, si el objeto alcanza la parte inferior de la pantalla, el juego termina.
🏟️ Adición de niveles y puntuación
Por último, Zoë explica cómo agregar niveles adicionales al juego. Primero, se crea una variable para llevar la puntuación y se actualiza cada vez que el jugador golpea la pelota. Luego, se configura un sistema para que, una vez que la puntuación alcanza un cierto umbral (por ejemplo, cinco puntos), el juego cambia al siguiente nivel, que se representa con un fondo diferente. Además, se proporciona el código del proyecto en la descripción del video para que los espectadores puedan modificarlo y crear sus propios juegos de Pong.
Mindmap
Keywords
💡Scratch
💡Pong
💡Sprite
💡Backdrop
💡Forever Loop
💡If on Edge Bounce
💡Direction
💡Mouse X
💡Touching
💡Score
💡Levels
Highlights
Tutorial de creación de un juego de pong en Scratch
Elegir un objeto para que rebote en el juego
Seleccionar un fondo de juego
Hacer que el objeto se mueva con un bucle infinito
Agregar un bloque 'si en borde, rebotar' para evitar que el objeto se atasque
Usar el bloque 'apuntar en dirección' para hacer que el objeto rebote en todas las direcciones
Iniciar el juego con un bloque 'cuando bandera verde es clicada'
Añadir una paleta al juego y hacer que se mueva con el ratón
Usar el bloque 'mouse X' para sincronizar la posición de la paleta con el ratón
Hacer que el objeto rebote cuando choque con la paleta
Agregar un bloque 'esperar' para añadir aleatoriedad al rebote del objeto
Terminar el juego si el objeto toca la parte inferior de la pantalla
Crear niveles adicionales y puntuación en el juego
Reiniciar el juego y resetear la puntuación al comenzar
Cambiar de nivel cuando se alcance una cierta puntuación
El código del proyecto se encuentra en la descripción del video para remixarlo
Invitación a los espectadores a crear sus propios juegos de pong
Transcripts
- Hi everyone, it's Zoë from the Scratch team,
also known as Zinnea.
Today I wanted to show you how to make a pong game
in Scratch.
This is a type of game where you have a paddle
and you're trying to stop a certain object
from hitting the bottom of the screen.
And yeah, by the end of this tutorial
you'll be able to make your own game like this
and where you can design it however you want,
and I'll show you how to add multiple levels and more.
Let's get started.
So first let's pick the object
that's going to be bouncing around in your game.
You can just click this button that says
"Choose a Sprite" and click "choose."
And you can pick any object that you want.
It could be a heart,
or a puffer fish,
or a star,
or really anything.
You can also pick a ball.
I'll do that.
Oh, and let's choose a backdrop.
You can hover over this button that says,
"choose a backdrop" and click "choose"
and pick absolutely anywhere
that you would like your game to take place.
I think maybe I'll pick the boardwalk.
And now let's make this object move.
In the motion category,
you could drag out this block, move 10 steps,
and by clicking on that,
the object will move.
Let's see what happens
if we put this block inside a forever loop.
So I'll go to the control category
and drag out a forever loop,
and now if I put the block in here,
the ball just goes forward,
you know, infinitely until it hits the wall
and it gets stuck.
So to make it not get stuck on the wall,
you can go to the motion category
and there's this block "if on edge bounce."
So if you put this block in the forever loop,
the ball when it hits the wall,
it realizes, oh, I hit an edge so it bounces.
So we've got it bouncing back and forth.
But how can we make it bounce all over the screen
so it's not just in this one line?
In the motion category
there's this block "point in direction"
and you can use it to set the direction
that a Sprite is pointing in.
And right now the Sprite is pointing in direction 90
and that's sort of straight this way.
Let's try putting in another number like 45.
So now the ball is pointed at a 45 degree angle
and now it's really bouncing around everywhere.
And I'll put a "when green flag clicked block on top"
so that we can make it start by clicking the green flag.
You can also try putting a different number in here like 15.
So now we've got our object bouncing around,
let's add a paddle.
So you can click on "choose a Sprite" again,
and pick any object you want.
It will be a little bit easier
if that object has a flat-ish top of some kind,
but you can still pick anything.
We also do have this paddle Sprite that you can use
and I'll use that one.
So let's make it so that
when the player moves the mouse left and right,
the paddle moves with it.
How can we make the paddle go to a certain position
between the left side of the screen
and the right side of the screen?
Well, in Scratch, you might already know this,
but X, this number,
represents how far a Sprite is
from this side of the screen to that side.
And if you go to the motion category
and drag out this block, "set X,"
you can put in a number here
and that will control where the Sprite goes.
So if you set X to 100,
the Sprite goes all the way over here.
If you set it to zero,
the Sprite goes right into the middle.
And if you set it to a negative number, like negative 100,
the Sprite goes over here.
Now we want the paddle to move left and right
when the player moves the mouse left and right.
And here's how we can do that.
If you go to the sensing category,
there's this block "mouse X"
and this block will tell you what is the current X position
of the player's mouse at that moment?
So you can drag this block into the set X block.
And now this will set the X of the paddle
to be wherever the X of the mouse is.
To show you it, let's put it in a forever loop.
So I'll put that inside a forever loop,
and I'll put a "when green flag clicked block on top"
so that we can make it start by clicking the green flag.
And there you go.
When the player moves the mouse left and right,
the paddle moves left and right with it
because we're always setting the X position of the paddle
to be the X position of the mouse.
Okay, nice.
We have the object bouncing around,
we can move the paddle
but right now the object
just passes right through the paddle if we hit it.
So let's make it actually
so that the object bounces off the paddle.
Here's how you can do that.
Let's go to the control category and drag out an "if" block
because we want the object to bounce if it hits the paddle.
So how could we tell if the object hit the paddle?
Well, in the sensing category
there's this block that can check
if one Sprite is touching another Sprite.
So we can drag this block
and click and choose paddle from the menu.
And now if the object connects with the paddle,
what do we want it to do?
What code should we put in here?
Well, we want it to bounce.
And before there was that "if on edge bounce" block
but there's no "if on paddle bounce block,"
but what is bouncing?
It's basically turning in the opposite direction,
and then moving in that direction.
So here's what you can do.
You can go to the motion category
and pick out this "turn" block
and have it turn 180 degrees,
because 180 degrees is half of a circle.
So if you turn that many degrees,
you'll go in the opposite direction
from where you were going.
And then after it turns,
let's have it move a bit in this new direction it's going.
So you can drag out a move block,
maybe we'll have it move 15 steps,
so the ball moves a little bit away from the paddle
after it's been bounced.
Now let's put a green flag block on top and see if it works.
Okay, so I hit the ball with the paddle
but it didn't bounce.
And here is why it's not working.
We need to put this if block inside a forever loop
so that the ball is always checking every second.
Did I hit the paddle, did I hit the paddle?
Because right now,
if it doesn't have a forever loop around it
when the green flag is clicked it checks one time,
am I hitting the paddle right now?
Nope, okay, I don't need to do this code anymore.
So let's put this inside a forever loop,
and now there we go,
we can actually bounce the ball with the paddle.
And one other little thing I'll add,
I'm gonna put a "wait 0.5 seconds" block in here
after it moves so that we'll have it wait
and let it move away from the paddle a bit.
Also, if you want to add some randomness
to the way it bounces,
you can go to the operator's category
and drag out this block, "pick random."
And instead of having the ball turn 180 degrees every time
it could turn somewhere between 170 to 190 degrees,
and now it'll be a little different
each time it hits the wall.
Okay, so we can hit the ball with the paddle,
but nothing bad happens to us right now
if we don't hit the ball
and it just goes to the bottom of the screen.
Let's make it so that the game ends
if the ball hits the bottom of the screen.
Here's how you can do that.
We have this line Sprite in the Sprite library.
So if you click and add that to your project,
you can drag it to the bottom of the screen
and now let's make it so that
if the ball ever touches this line
that's under the paddle.
Then the game ends.
Let's say, if the line Sprite makes contact with
whatever your object is,
so I'll pick the ball from the menu,
have it stop all.
There's this block in the control category
and that will stop everything in your game.
So let's put that in here.
And just like before,
we need to put a forever loop around this
so that the line is always checking
if it connected with the object.
And let's make this also start
when the green flag is clicked,
and let's test it out.
So, you know, if I'm playing the game
and I don't manage to catch the ball,
it stops the game.
There we go, and you can restart it to try again.
Now, let me show you how to add multiple levels
to your game.
And first to do that, let's add a score.
We can make a variable,
and a variable in Scratch
just keeps track of a certain number in your game.
So we can name this variable score.
And every time the player hits the ball,
let's change the score by one so they get a point.
There you go, pretty nice.
And when the green flag is clicked,
let's reset the score back to zero
every time you start the game again.
Now here's how you can add another level.
After you set the score to zero,
you can use this block and wait until
the score is greater than let's say five.
So this block will make the project
wait until this thing happens
before it does the next block you put under it.
And to make it go to another level,
let's go to the next backdrop.
And you can add another backdrop
to be where the second level is.
You can have the second level be anywhere you want.
And now when you get five points,
it goes to the next backdrop to the next level.
And also let's add a block up here and switch the backdrop
to the first backdrop we want it to start at.
So I'll switch it to boardwalk
and that will sort of set your beginning level.
And yeah, there you go,
that's how you can make a pong game.
Now, there are so many things you could add to this
and also the code for this project
is in the description below
so you could remix that if you want to.
Yeah, I am so excited to see the games you make.
I'll see you next time
and Scratch on.
(upbeat music)
5.0 / 5 (0 votes)