How to make a basketball game on Scratch

How to make a basketball game on Scratch

How to make a basketball game on Scratch

Content Protection by DMCA.com

Creating a basketball game using Scratch is not difficult. Below is a step-by-step guide on how to create a basketball game on Scratch.

Overall, command block “wait () seconds” will take care of the timing for custom transitions and passing. Block “go to x and y” will handle the position of the ball, and the command blocks “switch custom to” will handle the overall appearance, gestures, and body language of the player characters. And just like in a real basketball game, strategizing your next move is important. Hence, the blocks “broadcast message” and “when I receive message” will help determine whose turn it is to play.

Step 1: Choose sprite – character and size

Select the three basketball player images (Andie, Jamal and Dorian) along with the basketball image and manually adjust the size to 70% for the three players and 40% for the ball.

Choose character

Step 2: Choose a background

Click “Choose a backdrop” in the lower right corner of the screen. You can search for wallpapers in the search box or click on the sports category to select Basketball 2 wallpapers.

Select backdrop

Step 3: Customize the character – remove shadow

In the outfit tab of each character image, remove the ball from their outfit. To delete the ball, simply click on it and press the Backspace key or the trash can icon to delete. You can always click the undo arrow if you want to fix it again.

Read More  Instructions to add music to the Scratch project

Customize your character

Step 4: Customize sprite – copy and edit

Copy Dorian’s outfit by selecting dorian-c From the left menu, right click and select “duplicate” from options. Then, move the character’s arm up so we can use that outfit to animate the character’s excitement when the team scores. To rotate the arm, click it and look for the curved double arrow below the selection box.

Customize your character in Scratch

Step 5: Initial position of the ball

Now it’s time to start programming. Start with the ball image, but first click on Dorian’s outfit and place the ball in Dorian’s hand. Do this by clicking and dragging the basketball to the desired location. Then set the ball’s position (x and y points) to always be there when the green flag is clicked. Use command blocks “go to x: _ and y: _” to do this. For example, the ball needs to be there for about a second and a half before Dorian passes it to Andie. Here we will use command blocks “wait 1 second” to do this. Change it to 1.5 seconds instead of just 1 second.

Initial position of the ball

Step 6: Next position of the ball

Change Andie’s outfit to andie-a, and position the ball so it’s in Andie’s right hand by clicking and dragging it. This programming operation causes the ball to pass (glide) from Dorian to Andie. Here, the command block glide _ secs to x: _ y:_ is used. If you move the ball before getting the code, the x and y values ​​will automatically match the ball’s new position!

Next ball location

Step 7: Make Andie change hands

The next step is for Andie to show off her skills by transferring the ball from one hand to the other. We will use broadcast notifications and wait blocks.

Be a ball passing character

Step 8: Send the first notification

Now we need to program Andie to do two things:

  • Transfer the ball to your left hand
  • Pass the ball to Jamal.
Read More  How to make a maze game in Scratch

This can be done as soon as Andie receives it “message1” from the previous step. Furthermore, we will broadcast another message (called message 2), which will trigger the transfer of the ball from Andie’s right hand to her left hand.

Send the first notification

Step 9: Send second notification

Try running your game. You’ll see Andie has now raised her left hand. Move the ball to his hand by clicking and dragging. Then use the command glide _ secs to x:_ y:_ to move the ball to the coordinates x:_ y:_. Remember, if you move the ball before choosing the order, it will automatically have the correct numbers! Then the only thing left to do is for Andie to pass the ball to Jamal.

Second announcement

Step 10: Second notification works

It’s time for Jamal to catch the ball. According to Jamal’s position, choose jamal-a so you can place the ball in his hand position. The waiting time will increase by 0.5 seconds as well as the sliding block so the ball can slide into Jamal’s hand. We also need to prepare Jamal for message 2 – he will get into the catching position, which is the jamal-a position.

Duties of the second announcement

Create actions for characters

Step 11: Message2, more steps added

Use the jamal-c outfit to throw the ball, but first fix his arms. Make the arms look closer together. The example did this for Dorian in Step 4. Additionally, we need Jamal to switch to this outfit at the right time, so a wait block in the middle is added.

Add more steps to step 2

Game codes

Step 12: Prepare to score

We will continue to add to the programming series for the basketball. In this step, we need to place the ball between Jamal’s hands and add a wait block, and a movement block. “go to” (go to).

Prepare to score

Step 13: Scoring steps

You need to make Jamal look like he’s shooting the ball into the basket. Place the ball above the basket, then add a glide block to the programming sequence. Next, place the ball below the basket, and add another slide block. At that point, we need to broadcast another message that will trigger all three images of the player character celebrating by raising their arms in the air and jumping up and down. This message is: message3.

Read More  Tips for playing Capybara Go for beginners

Programming code

Step 14: Prepare to create exciting motion effects

Jamal, Dorian and Andie will change outfits when they receive message 3, but you also need to animate Jamal and Dorian when they jump up and down. To do this, use the same concept as we did with the ball – we’ll move the sprites up and down manually to get the x and y positions in the sliding block. Again, be sure to move them first and then place the sliding block so you don’t have to manually enter the x and y positions!

The only thing that needs to be different is the time the sprites slide. One second is too long, to make the jumping look a little more realistic you will repeat this process 10 times for both Jamal and Dorian. To repeat 10 times, use the repeat 10 loop from the control category.

Create motion effects

Step 15: Keep the outfit stable

It seems like the final steps of the custom conversion remain the same, right? This somehow affects the way the sprites work when you want to see them pass the ball, etc. It doesn’t seem right. This is an easy error to fix.

For each sprite, use events “when the green flag is clicked” to assign appropriate outfits to them to create smoother transitions.

Keep your outfit steady

Step 16: Broadcast the 3rd and final message

This activity requires costume adjustments as each sprite receives a message. Do this for all sprites under each broadcast message.

Final message

Step 17: Add score variable

Now all that’s missing is the basketball score. Click Variables > Make a Variable. Name it Score and leave the button selected for all sprites.

Add a score recording variable

Step 18: Program the score using conditions and mathematical operators

Add two points when the ball touches the floor. Do this by changing the score variable to 2. This code is placed after the last “glide” block we used for the basketball. In this example, that’s x=-81 and y=-144. Use if/then conditional blocks as well as ‘=’ and ‘and’ operation blocks.

Basketball game code on Scratch

Step 19: Reset score

When you test the basketball game you just created, you may notice that the scores keep adding up no matter how many times you restart the game. This is very easy to fix. Reset the score to zero at the beginning of the game, i.e. when the green flag is clicked. This is good practice for all the variables you will use in the program.

Reset scores

You should set a value to a variable before using it. In this program, you can do this with any object, but we should focus on the ball because points are added when the ball is on the ground.

GameHov is group of expert in gaming industry that cover all gaming news from e-sport to casual video entertainment.

Post Comment