How to Make a Pong Game in Scratch | Tutorial

Scratch Team
21 Mar 202210:55

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

00:00

🎮 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.

05:01

🏓 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.

10:02

🏟️ 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

Scratch es una plataforma de programación lúdica y educativa diseñada para enseñar a los niños a programar de una manera sencilla y visual. En el video, Scratch se utiliza para crear un juego de pong, que es un ejemplo práctico de cómo utilizar esta herramienta para la enseñanza y el aprendizaje del pensamiento computacional.

💡Pong

Pong es un clásico juego electrónico de arcade que simula un tenis de mesa. En el video, el tutor hace referencia a este juego para explicar cómo crear un juego similar en Scratch, donde el jugador controla una paleta para golpear una pelota y evitar que toque la parte inferior de la pantalla.

💡Sprite

Un Sprite en Scratch es un objeto gráfico que puede moverse o interactuar en la pantalla. Se utilizan para representar elementos del juego, como la pelota o la paleta. El video muestra cómo elegir y manipular sprites para hacer que el juego funcione.

💡Backdrop

El backdrop es el fondo visual en el que se desarrolla el juego en Scratch. Se puede personalizar para establecer el ambiente deseado para el juego. En el tutorial, el creador elige un backdrop de la tablilla para establecer el escenario del juego de pong.

💡Forever Loop

Un bucle 'Forever' o 'for ever' en Scratch es un bloque de control que permite que una serie de acciones se repitan indefinidamente. Se utiliza para hacer que la pelota se mueva continuamente en el juego, así como para que la paleta siga al mouse del jugador.

💡If on Edge Bounce

Este bloque de Scratch permite que un sprite rebote cuando choca con el borde de la pantalla. Es crucial para el funcionamiento del juego de pong, ya que permite que la pelota rebote en lugar de salirse de la pantalla.

💡Direction

La dirección en Scratch define la orientación en la que un sprite se mueve o apunta. El video muestra cómo cambiar la dirección de la pelota para que no solo se mueva en línea recta, sino también en ángulos, dándole un movimiento más dinámico al juego.

💡Mouse X

El bloque 'mouse X' en Scratch devuelve la posición horizontal actual del mouse del jugador. En el video, se utiliza para hacer que la paleta del juego siga el mouse del jugador, lo que permite al jugador controlar la paleta moviendo el mouse.

💡Touching

El bloque 'touching' en Scratch se utiliza para detectar si dos sprites están en contacto. En el contexto del juego de pong, se usa para determinar si la pelota toca la paleta, lo que desencadena la acción de rebotar la pelota.

💡Score

El puntaje es una variable en Scratch que se utiliza para rastrear el progreso del jugador en el juego. En el tutorial, el puntaje se incrementa cada vez que el jugador golpea la pelota con la paleta y se utiliza para desencadenar el cambio de nivel en el juego.

💡Levels

Los niveles son etapas o fases en un juego que ofrecen desafíos progresivos. En el video, se explica cómo agregar niveles al juego de pong en Scratch, lo que implica cambiar el backdrop y aumentar la dificultad o la complejidad del juego a medida que el jugador gana puntos.

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

play00:00

- Hi everyone, it's Zoë from the Scratch team,

play00:02

also known as Zinnea.

play00:05

Today I wanted to show you how to make a pong game

play00:08

in Scratch.

play00:09

This is a type of game where you have a paddle

play00:12

and you're trying to stop a certain object

play00:14

from hitting the bottom of the screen.

play00:16

And yeah, by the end of this tutorial

play00:18

you'll be able to make your own game like this

play00:21

and where you can design it however you want,

play00:22

and I'll show you how to add multiple levels and more.

play00:27

Let's get started.

play00:28

So first let's pick the object

play00:30

that's going to be bouncing around in your game.

play00:33

You can just click this button that says

play00:35

"Choose a Sprite" and click "choose."

play00:39

And you can pick any object that you want.

play00:42

It could be a heart,

play00:43

or a puffer fish,

play00:44

or a star,

play00:45

or really anything.

play00:47

You can also pick a ball.

play00:48

I'll do that.

play00:49

Oh, and let's choose a backdrop.

play00:52

You can hover over this button that says,

play00:54

"choose a backdrop" and click "choose"

play00:56

and pick absolutely anywhere

play00:58

that you would like your game to take place.

play01:00

I think maybe I'll pick the boardwalk.

play01:04

And now let's make this object move.

play01:07

In the motion category,

play01:08

you could drag out this block, move 10 steps,

play01:11

and by clicking on that,

play01:13

the object will move.

play01:15

Let's see what happens

play01:16

if we put this block inside a forever loop.

play01:20

So I'll go to the control category

play01:22

and drag out a forever loop,

play01:24

and now if I put the block in here,

play01:28

the ball just goes forward,

play01:30

you know, infinitely until it hits the wall

play01:32

and it gets stuck.

play01:33

So to make it not get stuck on the wall,

play01:36

you can go to the motion category

play01:38

and there's this block "if on edge bounce."

play01:42

So if you put this block in the forever loop,

play01:46

the ball when it hits the wall,

play01:49

it realizes, oh, I hit an edge so it bounces.

play01:52

So we've got it bouncing back and forth.

play01:55

But how can we make it bounce all over the screen

play01:58

so it's not just in this one line?

play02:01

In the motion category

play02:03

there's this block "point in direction"

play02:05

and you can use it to set the direction

play02:08

that a Sprite is pointing in.

play02:11

And right now the Sprite is pointing in direction 90

play02:15

and that's sort of straight this way.

play02:18

Let's try putting in another number like 45.

play02:22

So now the ball is pointed at a 45 degree angle

play02:26

and now it's really bouncing around everywhere.

play02:29

And I'll put a "when green flag clicked block on top"

play02:33

so that we can make it start by clicking the green flag.

play02:36

You can also try putting a different number in here like 15.

play02:40

So now we've got our object bouncing around,

play02:43

let's add a paddle.

play02:44

So you can click on "choose a Sprite" again,

play02:47

and pick any object you want.

play02:49

It will be a little bit easier

play02:51

if that object has a flat-ish top of some kind,

play02:54

but you can still pick anything.

play02:55

We also do have this paddle Sprite that you can use

play02:58

and I'll use that one.

play03:00

So let's make it so that

play03:02

when the player moves the mouse left and right,

play03:06

the paddle moves with it.

play03:07

How can we make the paddle go to a certain position

play03:11

between the left side of the screen

play03:12

and the right side of the screen?

play03:14

Well, in Scratch, you might already know this,

play03:17

but X, this number,

play03:20

represents how far a Sprite is

play03:21

from this side of the screen to that side.

play03:24

And if you go to the motion category

play03:26

and drag out this block, "set X,"

play03:31

you can put in a number here

play03:32

and that will control where the Sprite goes.

play03:35

So if you set X to 100,

play03:38

the Sprite goes all the way over here.

play03:40

If you set it to zero,

play03:42

the Sprite goes right into the middle.

play03:44

And if you set it to a negative number, like negative 100,

play03:47

the Sprite goes over here.

play03:49

Now we want the paddle to move left and right

play03:53

when the player moves the mouse left and right.

play03:55

And here's how we can do that.

play03:57

If you go to the sensing category,

play04:00

there's this block "mouse X"

play04:03

and this block will tell you what is the current X position

play04:07

of the player's mouse at that moment?

play04:09

So you can drag this block into the set X block.

play04:14

And now this will set the X of the paddle

play04:19

to be wherever the X of the mouse is.

play04:22

To show you it, let's put it in a forever loop.

play04:25

So I'll put that inside a forever loop,

play04:28

and I'll put a "when green flag clicked block on top"

play04:32

so that we can make it start by clicking the green flag.

play04:35

And there you go.

play04:36

When the player moves the mouse left and right,

play04:40

the paddle moves left and right with it

play04:42

because we're always setting the X position of the paddle

play04:47

to be the X position of the mouse.

play04:49

Okay, nice.

play04:49

We have the object bouncing around,

play04:51

we can move the paddle

play04:52

but right now the object

play04:54

just passes right through the paddle if we hit it.

play04:57

So let's make it actually

play04:58

so that the object bounces off the paddle.

play05:01

Here's how you can do that.

play05:02

Let's go to the control category and drag out an "if" block

play05:07

because we want the object to bounce if it hits the paddle.

play05:11

So how could we tell if the object hit the paddle?

play05:14

Well, in the sensing category

play05:17

there's this block that can check

play05:19

if one Sprite is touching another Sprite.

play05:22

So we can drag this block

play05:25

and click and choose paddle from the menu.

play05:29

And now if the object connects with the paddle,

play05:32

what do we want it to do?

play05:33

What code should we put in here?

play05:36

Well, we want it to bounce.

play05:38

And before there was that "if on edge bounce" block

play05:41

but there's no "if on paddle bounce block,"

play05:44

but what is bouncing?

play05:46

It's basically turning in the opposite direction,

play05:49

and then moving in that direction.

play05:51

So here's what you can do.

play05:53

You can go to the motion category

play05:55

and pick out this "turn" block

play05:58

and have it turn 180 degrees,

play06:02

because 180 degrees is half of a circle.

play06:05

So if you turn that many degrees,

play06:08

you'll go in the opposite direction

play06:09

from where you were going.

play06:11

And then after it turns,

play06:13

let's have it move a bit in this new direction it's going.

play06:15

So you can drag out a move block,

play06:18

maybe we'll have it move 15 steps,

play06:20

so the ball moves a little bit away from the paddle

play06:23

after it's been bounced.

play06:25

Now let's put a green flag block on top and see if it works.

play06:31

Okay, so I hit the ball with the paddle

play06:33

but it didn't bounce.

play06:35

And here is why it's not working.

play06:39

We need to put this if block inside a forever loop

play06:43

so that the ball is always checking every second.

play06:46

Did I hit the paddle, did I hit the paddle?

play06:48

Because right now,

play06:49

if it doesn't have a forever loop around it

play06:51

when the green flag is clicked it checks one time,

play06:54

am I hitting the paddle right now?

play06:56

Nope, okay, I don't need to do this code anymore.

play06:58

So let's put this inside a forever loop,

play07:01

and now there we go,

play07:03

we can actually bounce the ball with the paddle.

play07:07

And one other little thing I'll add,

play07:09

I'm gonna put a "wait 0.5 seconds" block in here

play07:12

after it moves so that we'll have it wait

play07:15

and let it move away from the paddle a bit.

play07:17

Also, if you want to add some randomness

play07:19

to the way it bounces,

play07:21

you can go to the operator's category

play07:23

and drag out this block, "pick random."

play07:25

And instead of having the ball turn 180 degrees every time

play07:29

it could turn somewhere between 170 to 190 degrees,

play07:33

and now it'll be a little different

play07:35

each time it hits the wall.

play07:36

Okay, so we can hit the ball with the paddle,

play07:39

but nothing bad happens to us right now

play07:42

if we don't hit the ball

play07:44

and it just goes to the bottom of the screen.

play07:45

Let's make it so that the game ends

play07:48

if the ball hits the bottom of the screen.

play07:50

Here's how you can do that.

play07:52

We have this line Sprite in the Sprite library.

play07:56

So if you click and add that to your project,

play08:00

you can drag it to the bottom of the screen

play08:02

and now let's make it so that

play08:05

if the ball ever touches this line

play08:08

that's under the paddle.

play08:10

Then the game ends.

play08:11

Let's say, if the line Sprite makes contact with

play08:16

whatever your object is,

play08:17

so I'll pick the ball from the menu,

play08:20

have it stop all.

play08:22

There's this block in the control category

play08:24

and that will stop everything in your game.

play08:27

So let's put that in here.

play08:29

And just like before,

play08:30

we need to put a forever loop around this

play08:32

so that the line is always checking

play08:34

if it connected with the object.

play08:36

And let's make this also start

play08:37

when the green flag is clicked,

play08:40

and let's test it out.

play08:41

So, you know, if I'm playing the game

play08:44

and I don't manage to catch the ball,

play08:47

it stops the game.

play08:49

There we go, and you can restart it to try again.

play08:51

Now, let me show you how to add multiple levels

play08:54

to your game.

play08:55

And first to do that, let's add a score.

play08:59

We can make a variable,

play09:01

and a variable in Scratch

play09:03

just keeps track of a certain number in your game.

play09:06

So we can name this variable score.

play09:10

And every time the player hits the ball,

play09:13

let's change the score by one so they get a point.

play09:20

There you go, pretty nice.

play09:21

And when the green flag is clicked,

play09:24

let's reset the score back to zero

play09:26

every time you start the game again.

play09:29

Now here's how you can add another level.

play09:32

After you set the score to zero,

play09:35

you can use this block and wait until

play09:40

the score is greater than let's say five.

play09:46

So this block will make the project

play09:48

wait until this thing happens

play09:50

before it does the next block you put under it.

play09:53

And to make it go to another level,

play09:55

let's go to the next backdrop.

play09:59

And you can add another backdrop

play10:01

to be where the second level is.

play10:03

You can have the second level be anywhere you want.

play10:05

And now when you get five points,

play10:09

it goes to the next backdrop to the next level.

play10:12

And also let's add a block up here and switch the backdrop

play10:17

to the first backdrop we want it to start at.

play10:19

So I'll switch it to boardwalk

play10:22

and that will sort of set your beginning level.

play10:25

And yeah, there you go,

play10:26

that's how you can make a pong game.

play10:28

Now, there are so many things you could add to this

play10:31

and also the code for this project

play10:34

is in the description below

play10:35

so you could remix that if you want to.

play10:38

Yeah, I am so excited to see the games you make.

play10:42

I'll see you next time

play10:43

and Scratch on.

play10:47

(upbeat music)

Rate This

5.0 / 5 (0 votes)

Связанные теги
Creación de juegosScratchTutorialMovimientoColisionesNivelesPuntuaciónProgramaciónEducativoEntretenimientoCódigoInteractivo
Вам нужно краткое изложение на английском?