How to Make a Simple Scratch Game

by taylor.fournel in Living > Toys & Games

569 Views, 2 Favorites, 0 Comments

How to Make a Simple Scratch Game

FC6A11CF-0105-4262-BB2D-E5E4781BCA37.jpeg
I will show you how to make a simple Scratch game that will have enemies constantly spawning, where you either have to doge the enemies or shoot them.

Supplies

All that you need is a device to go to scratch, and characters if you don’t want to use the ones scratch already had like I did for the demonstration.

Set Up Variables

26A1CF3B-2D0A-44B3-8E7A-8B6CB7CCA634.jpeg
Before we start you will want to make three variables under the variables tab. You can call them whatever you want, however I called them, score, spawn timer, and up/down. Score will be used to scale the enemies, and show the player how well they are doing. Spawn timer will be used to set how long it takes for the enemy to spawn. Finally up/down will be used to move up and down, there will be no side to side movement in my game.

Set Up Messages

1303C8D3-BBE6-4F24-AA3A-489E5F05DD13.jpeg
First to be able to set up messages you will have to either get a “broadcast” block or a “when I receive” block. You only want to create two new messages. One for when the player hits an enemy, and one for when the player is hit.

Making the Player

BEC2376E-B8B7-4A6F-A241-9D7718C81331.jpeg
In this step we will be making the controls, and the character that the player plays as. First you want to get a when flag clicked button to start the code.(It might be there already)

After you get the when flag clicked block then you need to make the score, and up/down zero so you don’t start off moving, or start with a high score. You do this by adding to set variable blocks, then changing the variables to Score, and Up/Down, it should already be set to zero but you should check. Next you want to add the “move to X: Y: “ in this block you want the X to be -150 and the Y to be zero.

For the movement you want to make a Forever block, and inside that forever block you want to put an “if” block and inside the “if” block add a “not” block, and in the “not” block add Up/Down = 0. This will make it so that the character will only move if Up/Down is not zero. Then add a “glide” block and make it so that the character can move based on the “y-position + Up/Down x 10”. Once that is done we need to make it so that we can change the Up/Down variable. Add two “if _____ button is pressed” make them the up, and down keys - your choice. Then add two “change Up/Down by ____” blocks and add a wait block in the middle, do this for each one of the “if _____ button pressed” blocks. Then change the one before the wait to 1, for up, and -1 for down. After that add the put the opposite on the one below each of the wait blocks. Set the wait block to something vey low like 0.1 or 0.25.

Making the Projectile

74A785E3-F0E4-4B00-BCC6-2988DE866DCA.jpeg
To start with the projectile you want to copy the when Flag clicked part of code from the player over to the projectile. You then want to add a “hide block” after the “Flag clicked” block.

Next you want to add a “if ____ button is pressed” block(you can set the buttons to whatever you want the shoot button to be). Under that block you want to add a “create clone” block, and a “wait 1 second” block.

Finally you want to add two “when I start as a clone” blocks. Under one you want to add a “show” block, a “glide to” block in this blocks you want X = 180 and Y = y-position. Finally add a delete this clone block under that. Under the second “start as clone” block you want to add a “forever” block, and in that block add an “if” block. For the “if” block you want to add a “touching color _____” block and set the color to that of the enemy you will be facing(make sure that the color is not the same as your background). Then inside the “If” block add a “broadcast message” block, and make it broadcast the message you want for when an enemy is hit. Next, add a “change score by 1” block, and finally a “delete this clone” block.

Making the Enemy

828ADBF0-F2F4-45CC-AF82-355366D9D0A5.jpeg
First you want to add a copy of the “flag pressed” code from the projectile to the enemy, and remove what is inside the “forever” block. You also want to change the variable from Up/Down to Spawn Timer, and make it equal 5. In the “forever” block you want to add a “wait” block and make it wait for spawn timer. Next you want to put a “move to” block, and make the X = 180, and the Y = “pick randomly between 150, and -150”. After that add a “create new clone of myself” block.

Next, you want to copy the code from the projectile for the first short “when I start as a clone” block, and change the gliding part of the code to 5 seconds, and make the X negative.

Then, add a “when I receive” block and change the message to hit. Then add a delete this clone block.

Next add a “when I start as a clone” block, and then a “Forever” block. Inside the “Forever” block you need to put a “If _____ Then” for every big color of your character. Then inside the “If _____ Then” put the “touching color” block, and change the color to the colors of your Player. Inside the “IF then” you need to add the “send message” block and change the message to the message for when the player gets hit.

For now we will skip scaling difficulty for later as an optional step.

Game Over

8C46D3EB-D826-49E8-912F-1E942650822C.jpeg
The Game Over screen is very simple, to begin you need a “When Flag clicked” block, then add a “hide” block, and a “move to X:0 Y:0) block and you want to keep everything like it is.

Then you want to add a “When I receive message” block and change the message to when the player gets hit. Then add a “show” and “Stop all” block.

If Your Game Does Not Work

02ECE17C-9707-47A7-A637-14A7E3FC4F5E.jpeg
If your game does not work go back through and make sure everything is correct, and make sure the color of your player, and enemy are not in the background.

Scaling Difficulty (Optional)

6B8AC219-8EEF-425D-AB8B-8C2ABD2A7CE0.jpeg
For the scaling difficulty you need to add a “when Flag clicked” block in the enemy’s code. Under this you want to add a “forever” block. For the scaling difficulty add a “if, then, else” block and for every one of the “if, then, Else” block you add a “if ____ > _____” block. In the first blank add score, and in the second the amount that you want to change at minus 1. Finally inside the “If, then, else” add a “set _____ to ______” and set the variable to Spawn timer, and the empty spot to how long you want to be in between spawns of the enemy.