Create your own exciting Geometry Dash game with this step-by-step tutorial!
The geometry dash game is a 2D game that involves escaping geometric-shaped obstacles via different levels that you can complete.
Playing geometry dash is pretty easy. The game can be played with a touchscreen, keyboard, mouse, or controller depending upon the platform.
The objective of the game is to complete a level by reaching its end. Press the space key to make your player jump in order to avoid obstacles. If the player crashes into an obstacle, the game will restart.
Typically a geometry dash game will have multiple levels. But today, to keep it simple, we're not going to add levels. Let's get started! Head on over to the MIT Scratch website and login.
The first thing we need to do is to create your backdrop, because by default there is a blank backdrop. To choose/design your own backdrop, click on the round mountain icon on the right side of the screen that allows you to choose your backdrop.
Go ahead and choose a backdrop. Or if you want to design your own backdrop then click on the paintbrush.
Here we have designed two backdrops. One is a plain colored backdrop with a yellow colored pathway on it. The second one is for the Game Over state.
Now that you have your backdrops ready, we need to draw our sprites. The round blue color cat icon on the right bottom corner allows you to draw a new sprite. Go ahead and select the paintbrush option to draw your sprites.
For this game, we are drawing 2 sprites:
Go to Variable blocks and create one variable named score, to save the scores.
Now that we have everything ready, let's begin to code! We will fix the player (sprite) position at the beginning. And then when we press the space key the player should jump in order to avoid the spikes.
Select your player sprite and let's start our code with the When flag clicked block from Event blocks and then pull out the Show block from Looks blocks. Underneath, get the Point in direction 90 block and goto x: -152 and y: -104 block from Motion blocks.
To make your player jump every time when you press the space key, add a Forever block, and inside forever place the IF block from Control blocks. Inside the IF condition, place the key space pressed block from Sensing blocks.
Inside the IF block, place two Repeat 10 blocks one after another from Control blocks. In the first Repeat block, place the turn clockwise 10 degrees block and the change y by 10 block from Motion blocks. In the second Repeat block, add the turn clockwise 10 degrees block and change y by -10 block from Motion blocks.
After the Repeat blocks add one point in direction 90 block from Motion blocks.
To initiate the score, we need to set the score variable to 0 and start creating clones of the spikes sprite every second.
In order to do this, click on your spike sprite, and start your code stack with the When flag clicked block from Event blocks. Then, add the set score to 0 block from Variable blocks. Underneath add a hide block from Looks blocks to hide the original sprite.
Now, add a Forever block. Inside Forever add create clone of myself block and wait 1 seconds block from Control blocks.
To move the spikes on the pathway, start your code with the When I start as a clone block from Control blocks and add a Show block from Looks blocks. Underneath add the go to x: 170 y: -108 block from Motion blocks to fix the starting position of the spikes. Now add the switch costumes to costume 1 block from Looks blocks. In place of costume1, add a pick random 1 to 3 block from the Operator blocks. To glide our spikes from left to right we will add glide 1 sec to x:-280 y:y position block from Motion blocks.
Once it reaches its designated position, the sprite clone should disappear. To delete the clones, add delete the clone block from Control blocks at the end of the stack.
As soon as the game starts, players will start scoring points. The player will get points until the player touches the spikes.
So for our code, we will start the stack with the When flag clicked block from Event blocks. Underneath add a Forever block and Repeat until block from Control blocks. In the repeat until condition, we will add a Touching players block from Sensing blocks.
Inside the repeat until block just add a change score by 1 block from Variable blocks.
The game ends when the player touches the spikes. But before that, we need to switch the backdrop and stop all the scripts.
Click on the player sprite and start your code stack with the When flag clicked block from Event blocks. Add a forever and If block from Control blocks. Inside the if condition add a touching spikes block from Sensing blocks.
Inside if, add switch backdrop to backdrop2/game over block from Looks blocks and a stop all block from Control blocks.
When the game ends we need to hide our player sprite. For that, we need to start our stack with the When backdrop switches to backdrop 2 block from Event blocks. Underneath that, add a hide block from Looks blocks and a play sound ____ until done block from Sound blocks.
Issue: The player sprite does not jump or the jump is not smooth.
Solution: Ensure that the "when space key pressed" block is placed inside the "forever" loop and is properly nested within the "if" condition. Double-check that you have two "repeat 10" blocks inside the "if" condition, and that each "repeat" block contains both the "turn clockwise 10 degrees" and "change y by" blocks. Also, ensure that the "point in direction 90" block is correctly positioned after the "repeat" blocks.
Issue: The spikes do not appear on the screen or do not move across the pathway.
Solution: Verify that the "when I start as a clone" block is correctly set up for the spike sprite. Ensure the initial position of the spike sprite is set with the "go to x: 170 y: -108" block. Make sure the "show" block is placed after the initial position block to make the spike visible. Check that the "glide 1 sec to x: -280 y: y position" block is correctly positioned to move the spike across the screen, and that the "delete this clone" block is at the end of the stack to remove the spike once it reaches the end.
Issue: The score does not update as the player avoids spikes.
Solution: Ensure that the score variable is properly initialized to 0 at the start of the game with the "set score to 0" block. Verify that the "change score by 1" block is inside the "repeat until" block and that the condition for the "repeat until" block is correctly set to check for touching the player sprite. Make sure the "forever" loop surrounds the "repeat until" block to continuously check and update the score.
Issue: The game does not end when the player sprite touches the spikes.
Solution: Check that the "touching spikes" block is correctly placed inside the "if" condition within the "forever" loop for the player sprite. Ensure the "switch backdrop to backdrop2/game over" block and the "stop all" block are correctly positioned inside the "if" condition to switch to the game over backdrop and stop all scripts when the player touches the spikes.
Issue: The player sprite does not hide when the game ends.
Solution: Verify that the "when backdrop switches to backdrop2" block is set up correctly for the player sprite. Ensure the "hide" block is placed immediately after this event block to hide the player sprite. Additionally, check that the "play sound ____ until done" block is correctly positioned to play a sound when the game ends.
Issue: The spikes overlap or do not disappear after reaching the end of the path.
Solution: Ensure the timing and positioning for the spikes are correctly set up. Check that the "create clone of myself" block is inside the "forever" loop with an appropriate "wait 1 second" block to prevent spikes from overlapping. Verify that the "delete this clone" block is correctly placed at the end of the spike's movement script to remove spikes once they reach the end of the path.
Sprites are the characters or objects in your Scratch project that you can control and animate. Each sprite can have multiple costumes and scripts associated with it.
Backdrops are the backgrounds of your Scratch project. They set the scene for your game and can change to reflect different states or levels.
Variables are used to store data that your project can use and modify. They can hold numbers, text, or other types of information.
Events are actions that trigger specific scripts to run. Examples include starting the game with the green flag or pressing keys to control sprites.
Control blocks manage the flow of your project's scripts. They include loops, conditional statements, and event handlers.
Motion blocks control the movement of sprites. They can change a sprite's position, direction, and speed.
Looks blocks control the appearance of sprites and backdrops. They can change costumes, switch backdrops, show or hide sprites, and more.
Sensing blocks detect various conditions and interactions in your project. They can sense touch, colors, distances, and other conditions.
Operators perform arithmetic operations, logical comparisons, and manipulate data in various ways.
Cloning allows you to create copies of a sprite that can act independently of the original. Each clone can have its own scripts and behaviors.
The geometry dash game we've made here is very basic. Generally, these games are never ending games - including tons of levels to play. To make your game more interesting you can add:
Now you've created a fun geometry dash game using Scratch coding. Play your game, and see how far you can get. In this tutorial, you learned to use basic blocks to create amazing things. There is so much you can create using Scratch!
Don't forget to: