Presentation is loading. Please wait.

Presentation is loading. Please wait.

How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high. -240 240 180 -180 x increasesx decreases.

Similar presentations


Presentation on theme: "How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high. -240 240 180 -180 x increasesx decreases."— Presentation transcript:

1 How to create a basic game in Scratch

2 The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high. -240 240 180 -180 x increasesx decreases y increases y decreases You need to know this information to move your sprite to a random location somewhere within the pixels of the stage.

3 Getting Started Start Scratch Step 1 You will need 3 sprites. Go to the choose a sprite folder and choose the cat, some food, and a ball. (Do not use the gravity balls!)

4 Resize Your Sprite! If you need to you can make your sprite larger or smaller by using the “grow sprite” or “shrink sprite” icons. You click on one of these icons, then click on your sprite until it is the size you’d like.

5 How to Choose a costume Click on costumes The cat sprite comes with 2 costumes.

6 How to Import Costume We don’t need to for this game but: 1.To import a costume 2.Click import 3.Select the folder

7 1.Choose your sprite

8 Copying & editing a costume Click on costumes again. Notice the cat is facing right. You can go back and forth between these costumes to make the cat looking like it is walking to the right. We need to create a costume to walk left. Click on the copy button on costume 1 and then click on the copy button for costume 2.

9 Edit a costume Click the edit button. On costume 3. It will take you to a paint screen.

10 Click on the rotation button to flip the cat to the left and press ok.

11 Your costume3 should be facing left now. Repeat for costume 4.

12 Choose Your Background! Click on the Stage at the bottom right: Now, select the “Backgrounds” tab!

13 Change The Background! From this screen, you can choose one of the category folders, and select a background that you like by double clicking on it!

14 Scripts for the cat This script will make the cat walk to the right when the right arrow key is pressed and left when the left arrow key is pressed. Program code: Control block: When right arrow key is pressed Condition: Forever if right arrow key is pressed sequential switch to costume catright1 Change x by 10 Switch to costume catright2 Click on the cat in the lower right of the screen. Click on scripts

15 Try it out Use your arrow keys to make the cat walk around.

16 Creating a Variable We want the cat to die when it is hit by a falling object but reappear until it dies 3 times. So we need to create a variable to hold the number of lives. A variable is a placeholder for informationA variable is a placeholder for information. Instructions on next slide.

17 Creating a Variable Click on variable. Click on make a variable Type lives as the variable name and click OK.

18 Creating variables To explain how variables work: This variable will let us set the number of lives and change it by a certain number. When lives reaches a certain number you can do something.

19 Scratch is Event Driven Sprite will only do something when some event happens. The events are: –such as a key is pressed –the green flag is clicked on –a message is received Sprites can send messages to each other by sending messages. The sprite receiving the message will do something after receiving the message. We are going to program the cat sprite to broadcast a message after lives = 0 so the Game Over background will appear.

20 Random Movement When the cat dies we want it to appear again in a random location. Remember the dimensions of the stage: -240 180 x increasesx decreases y increases y decreases -180 240 This will make a sprite go to a random x location and a random y location in the world. It is located in the operations NOW WE ARE READY TO PUT IT TOGETHER!

21 Type the following code This code will give the cat 3 lives Forever if lives = 0 –broadcast game over –Wait.05 seconds –Stop all If touching (falling object sprite) –Change lives by -1 –Hide –Reappear at a random location in the world –Wait 1 second –show We are finished with the cat!!

22 Program the food to disappear and reappear Click on the food sprite to write the program code. We want the food to appear in a random location and disappear when the cat eats it. The score will increase when the cat eats the food. It will then reappear in some random location until the sprite dies.

23 Creat another Variable We need to create a scorekeeper. We do this by creating a variable to hold the score. See if you remember how to create a variable called score.

24 CHOOSE THE FOOD SPRITE TYPE THE FOLLOWING CODE UNDER THE SCRIPT TAB This code will: When clicked: Set score to 0 –Send the food to a random location& show it Forever if touching the cat –Change score by 1 –Hide –Go to another random location –Wait –Show agian TEST THE FOOD SPRITE!

25 Falling Objects Click on the ball sprite at the bottom and click on script to add code What we want it to do: We want something (a ball) to fall from the sky and disappear when it reaches the bottom (the edge) reappear in some random location at the top again. If it hits the cat, the cat will die and lose a life.

26 To make it fall To make it fall from the top it will have to start at the same y location but at a different X location each time.

27 Type the following code: We need to add a conditional: If the sprite is touching the edge: –hide –go to another random location at the same y but a random X –Wait and show TEST THE FALLING OBJECT!!! Add the if statement

28 BACKGROUNDS Click on the stage Click on backgrounds Click on paint Create a background that says Game Over

29 Backgrounds Click on scripts You need to have the following scripts for your backgrounds. Background you created.

30 Make 2 additions to your game OPEN SCRATCH PROJECT -- GAME YOU CREATED -- I WILL CHECK IT Possibilities: Make the background change when the score reaches a certain amount (maybe 10) Make two balls fall when the score reaches a certain amount (maybe 10) Write the algorithm before you code it. List the steps in order 1 to _______. Example: Forever if score > 10 broadcast message ____change Stage would receive the message and change background to something different. Under the second Ball sprite it would hide at the beginning of the program. When I receive message change show start doing the same code the first ball is doing.


Download ppt "How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high. -240 240 180 -180 x increasesx decreases."

Similar presentations


Ads by Google