Link to two person game: https://scratch.mit.edu/projects/140796982/
Link to one person game: https://scratch.mit.edu/projects/140385440/
Creating One Person Pin-Pong Game:
We created a ping pong, one person game to begin working with Scratch, where the ball will go off an object, in this case a trampoline, and then bounce off. I had to first add two sprites, or objects, in order to work with a ball and trampoline. I clicked on the trampoline and was able to code it using the command to start when the green flag is clicked, which is how all codes are started. Then I used a forever loop, or known as a void loop in other programs, in order to have a continuous command to the trampoline until I stop the code. I placed inside the code, the command to set x to mouse x, which are under the categories motion and sensing in the program. Now the trampoline will be able to move side to side where ever my mouse goes. Then I created the code for the ball. Then I programmed the ball by using the same staring command as the trampoline and adding the motion of pointing in direction 180, therefore the ball will go down. Then I added a forever loop, and used an if then loop within the forever loop, therefore it wouldn't be happening always, but only if that situation occurred. I used the sensing category to say if touching the trampoline, and then I used the motion category to say then the ball would point in direction zero and turn 15 degrees, so it would rotate and be slightly harder to bounce the ball off the trampoline. Then outside the if then loop, I said move 10 steps and if on edge bounce, because therefore the ball could stay on the screen and keep moving.
Adding Features to One Person Ping-Pong Game:
Then, I added a dead zone to my game. This means that if the ball misses the trampoline, It will fall and restart. I kept the same coding for the trampoline and added some more sprites to make the dead zone, but I did have to change the coding on the ball. I used the same starting command, but then added the command show because the ball needs to show up after it disappears at the end and when the game restarts. Then I used the motion command go to x 21 and y 23, for coordinates for the ball to start and then added point in direction 180, so the ball would go down. Then I created a forever loop and added an if then loop inside of it, addressing if it touched the trampoline, then it would point in direction zero and turn fifteen degrees, just like when I first created the game. The outside of the if then loop I kept the commands move 10 steps and if on edge bounce, but then I added another if then loop in order to address what the ball would do if it hit the dead zone. It said if touching, the paddle, which was the name of the sprite I used to create the dead zone, then it would hide, which is a command from the look category, then it would wait 2 seconds, then show, then go back to the original starting coordinates of x 21 y 23. I repeated this code for every sprit I used to make the dead zone. This allowed the ball to disappear every time the ball missed the trampoline, but then show up again after 2 seconds, making it a more complex code. Then I was able to add score by creating a variable and having the score set to zero at the beginning and adding another if then loop to say if the ball was touching the trampoline the score would change by one, therefore now I can keep score with how many times I have touched the trampoline.
Creating Two Player Ping-Pong Game:
I created a two player ping pong game as well. I began by creating a ball sprit and two random sprites. I turned the two random sprits into rectangles by using the costume tab at the top of the coding categories and used the draw tool to create a rectangle for each sprite. I also had to rename my sprites to make it easier to understand which one is which. I named then paddle left and paddle right. Then I had to code the ball to begin with. I used the starting command the makes me have to click the green flag before the code beings. Then I used the command show, the go to the coordinates x 212 and y -11, which are numbers to make the ball appear and start at, and then the command point in direction -90, so the paddle would go to the left to begin, instead of going 180 which would make the ball drop down. Then, I used a forever loop and added a if then loop inside of it theta addresses if the ball was touching the left paddle, then point in direction 90, in order to go right to the right paddle, and then turn 15 degrees, to make the ball on a less straight path. Then I created the same if then loop for if the ball was touching the right paddle, but instead of pointing in the direction 90, point in direction -90, so it would go left instead of right. Then at the end of the code, I put move 10 steps and if on edge bounce, inside the forever loop, but not in an if then loop. Then I created the code for the paddles. For paddle left, I used the same starting command as always, then I created a forever loop, and created an if then loop inside the forever loop saying if key up arrow is pressed, then change y by 10, which means that when the up arrow is pressed, the left paddle will move up. Then I created another if then loop, that said if key down arrow is pressed, then change y by -10, which means that when the down arrow is pressed, the left paddle will move down. For the right paddle I created a very similar code except for instead of the up arrow, I used when key 1 is pressed the right paddle will change y by 10, or move up. Also, instead of the down arrow, I used when the 2 key is pressed, then change y by -10, or move down. I used different keys, so the paddles are won't move at the exact same time, but depending on when the person presses the keys. I also added on to my two player ping pong game by adding score and a dead zone and changing the ball speed. I began by improving my game by placing the command under the operations category, to point in the direction random 90 to -90 instead of just -90, in order to make the ball move or rotate a little more.
Adding and Adjusting Two Player Ping-Pong Game:
I added a command from the operations category for if touching the right paddle to turn pick random 20 to -25, to make the game harder because it is rotating more, instead of just turn 15 degrees, and also changed the command for when the ball toughs the left paddle to turn pick random 30 to -30 degrees instead of 15. Also, after the beginning of the code where the commas says point in direction pick random 90 to -90, I created two variables that addressed the score right and score left and placed the command to set both scores to zero to start the game. Then, another command I added after if on edge bounce was, I created an if then loop to address if it touched the dead zone on the sides of the screen. It said if touching convertible 1, then hide, wait 2 seconds, go to x 23 y -11, then show, and also set score right and left to zero, therefore when the ball touches the dead zones, the score will reset and the game will start over. I used the same code for the other side of the dead zone as well, but said if touching convertible two instead of one. Then I created another if then loop that said if touching paddle left, then change score left by one. I also added another if then loop that said if touching paddle right then change score right by one, so the corresponding side that touches the paddle will receive a point. Then I decided to add another feature to my game to make it harder as the score increased. I increased the speed of the ball after every time the ball hits a paddle. I created another variable called ball speed and then under the beginning coding part, before the forever loop, I added the code to set the ball speed to 12 at the beginning of the game. Then instead of move ten steps in the code, I used the variable ball speed instead of ten, in order for it to say move ball speed steps. Then in the if then statements for the dead zone, I added the variable to set the ball speed back to 12 under setting the scores back to zero, so it will be like the game completely starting over. Then under the if then statements for the paddles to change their score by one, I added to change the ball speed by one underneath the score commands. Therefore, the ball speed will get faster and faster, making the game harder and harder as the score increases.