Skip to main content

Soccer Game on Scratch Program

 We're going to make an example of making a Soccer game with Scratch. We add 1 ball, 2 paddle lines (to meet the ball), 2 thin paddle lines (they will act as a goal) from the scratch library in order to make a mutual soccer game in Scratch. You can also add any decor you want to the backdrops. To keep the score, we create 2 data named player-1 and player-2.

Soccer Game on Scratch Program

First of all, we will move the green paddles lines that will act as a castle. These lines will only move up and down. In order for these lines to move when the green flag is clicked, we first add the "Forever" code under the Control codes. If we do not add this, how many steps will move when we press the button we will move will remain there. In order to avoid this situation, we must add a forever movement code. After adding the forever code, we check with the "If" code whether the key to be moved is pressed or not.

Game Making with Scratch

Scratch games

If the W key is pressed, move the green bar. While moving up and down, the movement will take place in the y coordinate. So increase y positively as you move up. As we move down we will increase y negatively so that it moves down. One last check we will make is to prevent the green bars from going out of the screen. For this, we will use the "if" "and" commands nested together. If the W key is pressed and touches the edge, the green bar moves to x=-200 and y=105. These coordinates are the coordinates where the stick touches the edge. In other words, as the bar touches the edge, we prevent the bar from going out of the screen by ensuring that it goes to the coordinates of where it is. We do this so that it goes out of the screen from the down side.

Below are the codes we will write inside the Top.


Scratch examples


When the green flag is clicked, we reset the scores if the game has been played before. We reset the player-1 and 2 variables. We use the "Forever" command to keep the ball moving. Let the ball go 10 steps continuously. If it touches the edges of the screen, let it go back. When the ball touches the green bars, it goes to the opposite side at a random angle. For this, if you touch the green color, we apply the command rotate randomly between 0-90 degrees. Thus, the ball does not go to the opposite side at the same angle. Scoring, that is, the change of score is as follows. The ball must pass the green bars and touch the red and yellow thin bars behind the bars. Its control is as follows: If the ball touches the red color, increase the player-2 score by 1. Because player-2 scores and that point wins. Then we want it to go to x=0 and y=0 coordinates. If we do not do this, sometimes the ball may touch the red or yellow lines too much. More than 1 number can be written on the digit. For this, as soon as these colors are worth it, we make the ball move to the 0 coordinate after waiting for 1 second. If we want the game to end at a certain score, we need to check the scores of the players. If the score of player-1 is 5, we say that player -2 won and we stop the movement of everything with the command to stop all and end the match.


To download the source code of the program CLICK HERE

To see the running version of the program CLICK HERE


Similar Topics

For All Scratch Examples CLICK HERE

For Mblock With Arduino Examples CLICK HERE

Comments

Popular posts from this blog

Pacman Game on Scratch Program

 We will make an example of pacman game making with Scratch. Before starting the Pacman Game example that we will do with Scratch, we download the background for the pacman game from the internet and add it to the backdrop part in Scratch. When the background I downloaded was dark, I painted the dark colors with white. I made the borders thicker. After adding our background to our work, it came to creating the pacman character. I drew a full circle in yellow for the Pacman character. After that, I drew two lines towards the center using the line tool. I erased the remaining part with an eraser. If you want, you can use the erase background tool to erase between two black lines. Thus, our pacman character took his place with his mouth open. I created a guide dot right in front of the pacman character. This will keep us moving. I created a red dot. It's a little obvious, you can make this red dot smaller if you want, you can give it another color and make it more invisible. After cre...

How To Make Bubble Shooter Game on Scratch Program

 We will make a bubble shooter game example with Scratch. I am adding 3 balloons and a target picture for the bubble shooter game we will make with Scratch. (You can increase the number of balloons). Now I come to the codes to be written inside balloon1. Let the number of balloons popped when the green flag is clicked is 0. Thus, the remaining numbers from the previous game are reset. Let the balloons be hidden at first. Then, it will appear in a random place between the coordinates we have determined at a random time between 1-5 seconds, wait for 2 seconds, then hide. X: The coordinates between -218/144 are the coordinates of the far left and the right of the screen, Y:134/-235 are the coordinates of the top and bottom of the screen. It will appear randomly in these ranges If our balloon is aimed and hit by the target; Balloon shot news is released. When this news reaches our balloon, the balloon will be hidden. Copy and paste the same code above.   Then we say duplicate...

Apple Picking Game with Potentiometer- Mblock with Arduino

 Before moving on to this application, we had done the LEDLighting with the Potentiometer. You can learn the installation of the potentiometer and the necessary materials here.   Let's write our codes in the Mblock program. First of all, find a background from the internet, we change the background from the scene section. I add 3 apples (you can increase the number of apples) and 1 basket from the new puppet part.   Here are the codes in Apples: Since the green flag is clicked, we add the code to get our variable number of apples 0, which we created from the data section. If we do not add this, the number of apples collected will continue from where it left off if the game was played before. We take the code that generates random numbers from the operations menu and add the code that generates random numbers into the code to go to the x and y point that we added from the movement menu so that the apples come out randomly in a horizontal place. Here, we write the start...