Scratch - Ping Pong Game

Scratch - Ping Pong Game


This is a video tutorial that will show you how to create the original pong game. It's a pretty simple implementation. Watch the video in HD so that you can see easily.
Closed Caption:

ok so today we learned how to make pong
we're gonna start off by deleting the
cat and creating a new sprite and we're
going to start off by drawing the panel
so i'm going to draw a black rectangle
it's going to be tall but skinny and
i'll say okay and there's my first panel
that's what each player uses to bounce
the ball now one cool thing about
scratches all we have to do is make one
panel that works really well and then we
can copy it and I just modified slightly
so we want to have an event-driven we
wanted to move up and down with the up
and down arrows
so I'm going to go into controls and say
when up arrow is pressed
I let's see let's have it moved by 10 no
that's moving it button right so that's
wrong
what I want to do is just like in math I
want to move up and down the y-axis so
what I want to do is say change
why by and chat is probably good so yeah
that works
so let's make the down arrow work so
when the down arrow is pressed
I wanted to move down the y axis which
is the same thing as moving it a
negative number so i just changed the 10
to a negative 10
so now our panel will move up and down
the next thing we want to do is make it
so that it doesn't go through the bottom
and top so you can see right now it will
just continue off the page
we don't want that so I'm just going to
throw a little if on edge bounced in
there and so it will never let it go
through the top or bottom
ok next we want our panels to start off
in a specific location and the flag the
green flag whenever it's pushed means
that we're starting off the game or
we're starting the program so let's have
it moved to a specific X Y position when
the game starts
so you can see if I
I have when the flag is pressed go to
and then I have an X a Y value so it
will always go to that spot when it
starts
so this is perfect perfect panel
everything works well i'm going to name
it let's call it panel
- because it's on the right hand side
that's usually where player 2 would be
and then all we need to do is duplicate
it and then modify it so we have our
second player one panel so we'll call
this one panel one and move it to the
left side of the screen
that's where player one should be and
then I'm gonna have to change a few
things in in the script now to make it
work so let's start off by putting these
numbers two negatives and that should
basically started at the opposite side
to the other one and now of course we
can't have them both up and down arrow
so on the left side we're going to use W
for up and ask for down which are some
standard keys in a lot of video games
for up and down
so let's say he does it work yep
our panels both move up down perfect
that's great
so the next thing we're going to do is
we're going to create the ball so i'm
going to draw a red circle and it should
be pretty small
you can run into a few problems if you
make it too big so i'll push okay
there's the ball and one thing you
should check before you start
programming is go back in and edit the
script and there's a button there at the
bottom left to set the center just make
sure that the crosshairs go through the
middle of the ball or you might want to
run into some problems later
ok so we are going to start creating the
script so we want when we start the game
we want the ball to start moving so i'm
going to use a forever loop and habit
forever
move 10 steps actually let's make it
five ten might be too big it might not
work properly so for every move five
steps let's see
boo ok
not very interesting flies off to the
right and in a straight line usually in
pawn the no you should start at zero
zero so that it always starts in the
middle and probably what we want is to
have it . in a diagonal direction to
start off with instead of a straight
line
that's boring game of palm so let's try
- 45 see what happens there there we go
let's do it better but you know it
didn't bounce off the wall
so we're just going to throw in if on
edge bounced in there and let's see what
it does now
ok so it's behaving more like an actual
pong game which is great
so what else do we need we are going to
say if it runs into one of the panels we
wanted to bounce
so let's say if it's touching the color
black because that's the color of the
panel then we're going to want to bounce
but there is no balance operator so
we're just going to have it rotate by 90
degrees
so if it's touching the black panel
rotate by 90 degrees and it bounced off
the panel c going
will it work yes it works perfect
ok so it's bouncing off the panels and
it's bouncing off all of the walls which
is great
now
we want to track points so when the ball
goes off the left side
the person on the right you get a point
and on and the opposite is true so we're
going to create two variables player 1
points and player 2 . so i just got into
the variable section and make i push the
makeup variable button
i'm calling it player one . player two
points a player 1 points on the left and
player two points on the right and it
so what we want is we are going to use
colors and color sensing here and what
I'll do is I'll draw a green wall on the
left hand side and that the ball will
know if it touches the green that it
goes that player 1 get the point
and I'm going to put an orange on the
other side and blue at the top
ok blue at the top is just so that i can
put the points up there at the top and
so will have to make the ball bounced
off the blue as well
ok so let's get it started you know the
ball bounces through the green and
through the blue we wanted bouncing off
the blue so I go back into my ball
script and we're going to add that if
it's touching the color green or the
color blue or the color orange it's
going to do something so let's start
with the color blue
so if touching color blue
we wanted to basically the same thing it
does when it hits the panel we wanted to
turn 90 degrees
so let's throw that in there turn 90
degrees and let's see does it work
let's test the note and it makes it a
bit there but it's at
I think that's because the ball is too
big I've seen this happen before
let's just make the ball of it smaller
does it still get the flakes out so
we're going to go into the ball
we're gonna hit costumes we're going to
hit edit and up to the top there's just
that little button that makes it smaller
let's just push it once and say okay and
see if it works now it does okay so
great
the ball was a little too big so if this
happens to you you can just make your
ball bit smaller but it bounces off the
panel's it bounces off the blue but
you'll notice nothing happened when it
hit the green so that's the next thing
we need to start counting points
when it hits the green or the yellow so
we're going to say if touching the color
green lights bro that and there and i
use the dropper to select the color
green
I want what to change player choose
points by one so that means basically i
want to increase player two points by
one when it touches and you'll notice we
just got a bazillion points there
so player 2 and that's because we didn't
tell the script to stop
so the ball just kept on moving in the
green so the person kept getting . so
now we have thrown in a stop script
there so when it hits the green next
time it will stop and the personal get
one . we can duplicate that whole block
now and just choose them
the color orange there we go
so if touching the color orange player 1
gets a point and then the script stop so
there you see a player to get another .
but only one . and then it stopped just
like that one . and it stops one . and
it stops
excellent so that works its counting
points but you'll notice that when i
start the game player to already has a
bazillion points so we need to make it
so that the person starts at only one
point
ok the last thing we want to do here is
make it so that the game goes to five
points and then ends
so what we're going to do is we're gonna
start off by waiting one second after
the ball hits the wall and we're gonna
get rid of the stop script thing because
we don't actually want to stop
what we wanted to do is we want the ball
to go back to the middle and and free to
keep playing right now we have
everything wrapped in forever loop and
that's great except where we only wanted
to go to five points
so we're going to do instead is create a
repeat until loop and we want to repeat
until either player 1 or player 2 has
five points so basically i'm setting up
a few operators here so we'll say player
1 equals 5 or player two equals five so
if either of those things happen then
the loop will stop repeating it will
only repeat until either of those things
are true
so I just pick up the rest of that block
and throw it in there and I can throw
away the forever loop i don't need that
anymore
throw it in now it will only go to five
points but as you can see my my ball
every second keeps jumping so what I
need to do is have it moved back 200
before it starts playing again so i'll
just throw that in
so if touching color green give a . wait
a second and then move the ball back to
zero and of course I need to do that for
if it's touching the orange zone as well
so it's touching orange player 1 gets a
point wait one second and move the ball
back 200 so let's see does it work now
yes that works on the green side and the
orange size of players are getting
points
it's working perfectly okay the last
thing we're going to do is end the game
off
we're going to check to see which player
1 and announced that
so after the repeat until loop runs will
have a check to see if player 1 has five
points which would mean that they won
then we'll say have the ball say that
player 1 wins
and then below that it just says else
so if player one doesn't win we don't
have to check to see a player two wins
we know player to with so if player 1
has five points straight wins and
otherwise player two must have one so we
just throw in a player two wins and
that's it that's the game

Video Length: 12:17
Uploaded By: MrMattperreault
View Count: 371,613

Related Software Products
Pong Project
Pong Project

Published By:
Digital Liquid

Description:
Pong Project V1.1 is a 4 player pong game you and your friends will love. Amazing 2v2 or 1v1v1v1 battles! Extra effort was put into the game to allow for as much control over the game rules as possible, from global to individual player settings. It includes an awesome feature allowing 1 to 3 of your friends to actually play the ball! With the special ball influence option you can allow multiple players to influence the ball simultaneously after they are out of the game! You can play 2 v 2 with ...


Related Videos
Beer Pong 101
Beer Pong 101

A final project created for Film Studies about the wonderful sport of Beer Pong. Starring Britt, JJ, and Steve.
Video Length: 06:21
Uploaded By: sandrich2396
View Count: 812,755

PONG PROJECT
PONG PROJECT

This is a real physical version and a homage to the first videogame ever Team: Daniel Perdomo Alvaro Salsamendi Constantino Voulgaris Music by AKUFEN https://www.youtube.com/watch?v=H8yVb... Facebook fan page: https://www.facebook.com/TABLEPONGPRO... Official: tablepongproject.com We are looking for a hardware incubator to make it a reality. If you want to help us you are welcome. br ...
Video Length: 04:51
Uploaded By: Daniel Perdomo
View Count: 408,617

Ping Pong Paddle Boat with Popsicle Stick Paddles - SonicDad Project #42
Ping Pong Paddle Boat with Popsicle Stick Paddles - SonicDad Project #42

Build a self propelled paddle boat made from ping pong balls, popsicle sticks, and an unexpected motor that will make those paddles spin! Download PDF Instructions Today: http://www.sonicdad.com/project-detai... http://youtu.be/TXGDl9CPB5I
Video Length: 02:02
Uploaded By: SonicDadDotCom
View Count: 310,962

How to Build a Ping Pong Table | Craftsman
How to Build a Ping Pong Table | Craftsman

John Volpe shows you how to build a convertible ping pong table. It's the ideal kids table for your child's room or playroom, and can be folded up when they're not playing table tennis. It's the perfect woodworking project that will keep your kids happy for years to come! Join Craftsman Club to get the latest projects and exclusive deals: http://bit.ly/1MYp03B Check out more DIY table projects: https://www.youtube.com/watch?v=41zrT... We upload new videos every week. ...
Video Length: 07:59
Uploaded By: Craftsman
View Count: 82,394

Pong - HTML5 Game Programming Tutorial [javascript]
Pong - HTML5 Game Programming Tutorial [javascript]

Hi, I'm back with a second tutorial video where we hack together a simple Pong game using javascript and html5. In this one do I use a bigger fontsize, so that the video better can be viewed on mobile devices. Let me know in the comments if I should use the settings in the previous video, use the fontsize in this video or use an even bigger font :) (btw. the font I use in the video are Anonymous Pro, http://www.marksimonson.com/fonts/vie...). :: Annotated Source ::br ...
Video Length: 25:54
Uploaded By: Max Wihlborg
View Count: 81,387

32x16 RGB LED Matrix Ping Pong Ball - Plasma Wall
32x16 RGB LED Matrix Ping Pong Ball - Plasma Wall

This is our latest project. A 32x16 RGB LED matrix with Ping Pong Balls as diffusors. The matrix is build modular in sections of 8x8 LEDs so it's enlargeable without limitations. However, for the moment we spend more than enough time in soldering and wiring :-) The main challenge for this project was to control 1536 individual LED's (512xRGB) with one single ATMEGA 328. Not enough we also claimed to have PWM one each individual LED separately. What we achieved is a system ...
Video Length: 03:41
Uploaded By: rheller1981
View Count: 71,575

Build a ping pong ball launcher
Build a ping pong ball launcher

This project shows you how to build and test an adjustable ping pong ball launcher. hr / bClosed Caption:/b OK, so today we're going to show you how to make a projectile launcher. This launcher was originally designed by Dave Berggren's class in High Tech High in San Diego. He's an engineering teacher there and was a mentor of mine when I worked there. So there are a number ofbr ...
Video Length: 10:27
Uploaded By: Khan Academy - Projects
View Count: 60,143

Beer Pong Capstone Project at CU
Beer Pong Capstone Project at CU

This was a project that some seniors at the Electrical and Computer Engineering wing demonstrated for Spring Capstone 2010. University of Colorado Boulder. hr / bClosed Caption:/b yep yep up here said yep good Rep earth yes paired over actually ships lodged awaits Egypt by dubbed vision solved up his hooked on earth we consolidate way up you lord by ...
Video Length: 02:32
Uploaded By: mightymax1983
View Count: 52,944

Copyright © 2025, Ivertech. All rights reserved.