In this Scratch tutorial you will learn how to create a pong game part 1/2.
Tags:How to Create a Pong Game Part 1/2- Scratch,adobe software tutorials,adobenicnacs,create games in scratch,create pong game,digital manipulation,scratch,scratch tutorial
Grab video code:
Transcript
Hi I’m Daniel from Dominiqueask.tk. and in this tutorial, I’m going to be showing you go to make a basic pong game in scratch. So if I just run the game here you seen what our running results are now it’s not as jumpy as this when you actually play it. It is set in my screen recorder and as you can see, I move my mouse and the paddle moves and the ball bounces off. If I don’t hit the ball you lose. Okay so I’m going to open up a new project I’m going to start from scratch and so I’m not going to save this first of all we’re going to get rid of this cat so we don’t need it so we can right click on the little sprite down here and press delete.
Next, I’m going to click this button here which is paint new sprite. I’m going to paint paddle, so I’m just going to grab my rectangle tool, choose a bright red. I’ve zoomed out by the way by clicking the zoom out button. And I’m just going to draw out a paddle and press ok. Now very important thing we need to do now is name the sprite. So up here towards the top can see it says sprite1, click on this and just rename it to paddle. This is very important with any scratch project that you name you sprites. Okay. now I’m just going to drag down where I want it there and then, I just need to have one simple script so I’m going to grab this block here when the green flags click. So when the green flag is clicked it’s going to do whatever I wanted to, and what I wanted to do is repeat forever. And when I wanted to forever throughout the whole document is set is X to mouse X. so whenever my mouse is X position is so you can see it down here will be what the paddles X position is okay. So if we run this you could see the paddle follows my mouse. And that’s was very easy to do so I’m going too stop it now.
Now we’re going to paint ball sprite in. So I’m just going to grab my circle, I’ve zoomed out again to full screen and I’m going to leave it black and I’m going to hold my shift key and drag out to draw a perfect circle and I’m going to press ok. And the first thing we need to do is like the last time, grab a when a green flag is clicked and the first thing I wanted to do is set it’s direction. Now the moment it’s pointing right as you can see some means when run into a document its going to move right instead of downwards which is not what we want. So set the direction set it is a 170 which is slightly diagonal so if I double click this block you’ll see a preview and you can see its pointing diagonal. Because it’s rotated It’s sort of bit sharper it got rough edges so I can stop this all reduce it’s by pressing this button here so it’ doesn’t rotate. That looks a bit nicer okay then the next block we need to have it’s a forever block so whatever side is going to run for the rest of my document. Not to point in direction 170 but whatever it’s side here.
Now first, we want to do is move steps and the steps you want to move is five so this every time we come into this block, it is going to move it five steps forward, an forward will be whatever direction is pointing. Then we need to put this block in here, if on edge, bounce. Now this is a really good block to use if you need to bounce of the edges of your document or game window area. So basically what happens is if the ball is coming to this angle it would automatically bounce off that angle and then that angle and it doesn’t all for you which is very useful.
Next what we need to do is add an if statement so I’m going to drag in my, If statement block here and now for the condition. I’m going to say and this is my sensing part touching paddle so it’s going to check if the ball it’s touching the paddle. And if it is touching the paddle this is what we wanted to do, you want it to point in that direction. And now I’m going to grab out one of my math blocks here. It’s going to be 180-direction now this is an easy way to make something bounce of a horizontal surface. If you want it to bounce of a vertical surface its 360-direction. And for diagonal it can get bit more complex.
Okay now we got this part instead of if we just run it here you can always bounces at same angle and to catch the ball and after it bounces in the same angle. So it’s very boring so we’re going to add one, more block in this script to make it more interesting. So I’m going o grab the turn direction 70 degrees and we can use the random block in the number section here. And we’re going to pick random minus-20 to 20 degrees; so this will rotate it either left because it’s minus so rotate it left so as you can see up here it could either go this way or this way. And then after that as the whole script is finished it goes back to the beginning and it will move five steps. And then it will do this and back to the beginning forever. So if we press that green flag, this is a bit more interesting I mean as far as pong goes. Okay the next thing what we need to do is reset it.
So if we would make it go down here stop the project press green it’s going to start down there but what we wanted to start here every time so we is we go to our motion block. We drag on this go to block and I’m just going to put it on the very top here. And we need to give an XY so I’m going to give in X of 0 and a Y, of 120. Press the green flag and that’s means wherever we stop it, it will appear there which is brilliant.
And one of the things I need to do is name this sprite here boom. The last thing we need to do is add a dead area where if the ball hits the game will end. So I’m going to paint enough of this sprite and I’m going to zoom out and I’m just going to grab a darker red here. And I’m just going to draw out a rectangle stretching across the whole screen. And I’m just going to position it at the bottom here. And I will call it dead_area and then the simple sript we do here is we’re going to do a separate one to make it easier. When the green flag, is clicked forever if touching dead areas this will block as we’ve seen a minute ago. Now we could use in the look section, the say block but not say for so many seconds just say. And we’re going to say “you lose” and in that control we’re going to use stop all and this is the equivalent of pressing the stop button. Now if we run it as you can see we can play pong and when it hits the ground, it’s say you lose and the game stops.
Okay that’s our, pong game I hope you enjoy this tutorial in the next tutorial I’m going to build a pong game and we’re going to make it a little more interesting. But until then if you like my tutorials or you like using scratch or some of the adobe products. Check out my site it’s www.dominiquematch.tk. And once again thanks for watching.
Comments