how to make basketball game on scratch

Mastering Scratch: Create Your Own Basketball Game

By Nicole Martinez
AD

Ready to dive into the exciting world of coding and create your very own basketball game? Scratch, a visual programming platform, is the perfect place to start, especially for beginners. With its user-friendly interface and drag-and-drop blocks, you can bring your game to life with ease. Let's explore how to make a basketball game on Scratch, step by step.

Before we begin, ensure you have a Scratch account if you don't have one already. Once you're set, let's start by understanding the basics of our game: a basketball hoop that detects when the ball is thrown in, increasing the score. Sounds simple? It is! Let's break it down.

Designing the Sprites

The first step is to create our game's characters or 'sprites.' We'll need a basketball, a hoop, and a scoreboard.

AD
How To Make A Basketball Game On Scratch
How To Make A Basketball Game On Scratch
Tap Tap Shots Game: Free Online Basketball Bounce Shooting Video Game for Kids
Tap Tap Shots Game: Free Online Basketball Bounce Shooting Video Game for Kids
Coding for Kids - Shootin' Hoops - Scratch Project | K-5 Technology Lab
Coding for Kids - Shootin' Hoops - Scratch Project | K-5 Technology Lab

Start by clicking on the 'Development' mode in Scratch. Then, click on the 'Choose a Sprite' dropdown and select ' Basketball' for your ball. Rename it to 'Basketball' in the sprite's properties panel. Do the same for the 'hoop' sprite and the 'scoreboard' sprite.

Setting Up the Stage

Now, let's set up our stage. Click on the 'Stage' in the sprite list and then on the 'Background' dropdown. Select 'basketballbg' for our game's background.

Scratch 3 0 + Makey Makey = Simon Says Game Part 1: Sprites
Scratch 3 0 + Makey Makey = Simon Says Game Part 1: Sprites
How to Make Mini Basketball Game from Cardboard
How to Make Mini Basketball Game from Cardboard

Position your 'Hoop' sprite at the top of the stage and the 'Scoreboard' sprite at the bottom. Make sure the 'Basketball' sprite starts somewhere near the middle of the stage.

Making the Basketball Move

Next, let's make the basketball move. Select the 'Basketball' sprite and click on the 'Events' block. Drag the 'when green flag clicked' block into the scripting area. Now, click on the 'Control' block and drag the 'repeat' block into the script.

AD

Inside the 'repeat' block, add a 'change x by 10' block (you can find it under the 'Motion' category). This will move the basketball horizontally by 10 pixels each time the loop runs. Experiment with this value to change the speed of the ball.

Detecting the Hoop

Now, let's make the basketball disappear when it reaches the hoop. Under the 'Control' category, drag another 'if' block into the script. Then, click on the 'Sensing' category and add a ' toucheing edge?' block. Change the drop-down menu to 'bottom'.

Inside the 'if' block, add the 'hide' block under the 'Looks' category. Your script should now look like this: 'when green flag clicked, repeat, change x by 10, if touching edge? (bottom) hide'.

AD

Scoring a Point

We've set up our basketball to detect when it reaches the hoop, but we need to increase the score when this happens too.

First, add a 'when the basketball sprite is dragged over the hoop sprite' event to the hoop. You can find this under the 'Events' category. Inside this event, add the 'change score by 1' block from the 'Data' category. Make sure your score variable is set to 0 in the variable panel for this to work.

Displaying the Score

Lastly, we need to display the score on our scoreboard sprite. Click on the 'Scoreboard' sprite and add a 'when green flag clicked' event. Then, under the 'Looks' category, add a 'say at bottom [score]' block.

AD

Now, when you click the green flag, the basketball should move horizontally, disappear when it hits the bottom edge of the stage (the hoop), and the score should increase by 1 each time. That's your basketball game on Scratch!

You can now experiment with different backgrounds, add more features like power-ups or multiple levels, or even create an entire basketball tournament. The possibilities are endless, so keep exploring and happy coding!

AD