More results...

Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
post
page
Python IDE Dashboard

Space Invaders in Scratch

This step by step tutorial will demonstrate how to re-create “Space Invaders” using Scratch.

space-invaders-scratch

Step 1Step 2Step 3Step 4Step 5Step 6Step 7Extension

Setting up the stage


Start a new project in Scratch and change the stage backdrop to the backdrop called “Stars”.
scratch-add-backdrop
space-invaders-stars-backdrop

The Spaceship/Rocket Sprite


Next, we will delete the Cat sprite and create a new Rocket sprite:
scratch-remove-sprite-cat
space-invader-rocketship
We will also resize our Rocketship sprite to 35% of its original size:
space-invader-resize-rocketship

The rocketship sprite has 5 costumes but costume 5 is bigger than the other 4 costumes, so we will delete costume 5:
space-invader-remove-costume

Let’s start coding


Using the Rocketship sprite, let’s add some code.

First we will make sure the “Stars” backdrop is always displayed when the game starts:
scratch-switch-to-stars-backdrop

Now let’s animate the Rocketship sprite:
scratch-animate-rocket

Controlling the Rocket ship using the left and right arrow keys


The rocket ship is positioned at the bottom of the screen. The user should be able to slide the rocket ship horizontally to the left or the right using the arrow keys.
scratch-left-right-rocket

The Invader Sprite


Let’s add a new sprite using the “Gobo” sprite from the scratch library:
scratch-gobo-sprite
We will then resize our invader sprite to 40% of its original size:
scratch-resize-invader

Let’s add some code to our invader sprite to position and animate the sprite:
scratch-animate-gobo

Now let’s add some code to make the invader move across the screen. Everytime the sprite reach the edge, it should drop down closer to the rocket ship and change direction (left/right movement).
scratch-invader-movement

Adding a Game Over Screen


The games ends when an invader hits the rocket. To implement this we will first need design a Game Over screen/backdrop:
scratch-game-over-screen

Then we will add some code to our Invader sprite to detect when the invader is touching the rocket ship.
scratch-game-over-trigger

Adding a laser beam sprite


To add a laser beam, we will paint a new sprite:
scratch-paint-new-sprite
scratch-paint-laser-beam

Firing the laser beam


The following code will let the user fire a laser beam by pressing the space bar. The laser beam will always be launched from the rocket ship current position:
scratch-fire-laser-beam

Adding a score variable


Let’s make a new variable called score. We will use this variable to score 1 point when the laser beam hits an invader. To do so we will need to go to the variable section:
scratch-variables-section
Then you will click on the “Make a Variable button”.
scratch-make-variable
Give a name to your variable: score and tick the option “For all sprites”
scratch-ball-bouncing-code-complete
Make sure your variable is visible (Tick the checkbox next to the variable itself):
scratch-make-variable-visible
Using our Rocket ship sprite we will edit our code as follows to reset the score to 0 when the game starts:
scratch-reset-score-variable

Then we will add some code to our invader sprite:
scratch-laser-collide-invader

Let’s add some more invaders


We will duplicate our invader sprite 10 times:
scratch-duplicate-gobo-sprite

All we have to do now is re-position each invader sprite one at a time by changing their x and y coordinates in the code:
scratch-invaders-positions

We now have a fully working game!

space-invader-scratch

Extension Task


Add a “Level Complete!” screen that appears when the user scores 10 points (All invaders have been destroyed!).
Tagged with:

Flappy Bird using Scratch

This step by step tutorial will demonstrate how to re-create the game “Flappy Bird” using the online version of Scratch.

Step 1Step 2Step 3Step 4Step 5Extension

Setting up the stage


Start a new project in Scratch and change the stage backdrop to the backdrop called “Blue Sky”
scratch-add-backdrop
scratch-blue-sky-backdrop

The Parrot Sprite


Next, we will delete the Cat sprite and create a new Parrot sprite:
scratch-remove-sprite-cat
scratch-parrot-sprite
We will also resize our Parrot sprite to 25% of its original size:
scracth-parrot-size

Let’s start coding


Using the Parrot sprite, let’s add some code.

First we will make sure the “Blue Sky” backdrop is always displayed when the game starts:
scratch-switch-background

The let’s animate the parrot to make it flap its wings:
scratch-switch-costumes

Controlling the Parrot using the space bar


Every time the user presses the space bar, the parrot should fly upwards.
scratch-control-flappy-bird

Adding Gravity


The idea is that the parrot should constantly be pulled down by gravity.
scratch-gravity-algorithm

Adding a Game Over Screen


The games ends when the parrot hits the ground. To implement this we will first need design a Game Over screen/backdrop:
scratch-game-over-screen

Then we will add some code to our Parrot sprite to detect when the parrot is hitting the ground. (On our “blue sky” backdrop, the ground has a brown color, you will need to use the color picker to retrieve this color):
scratch-sprite-touching-colour
scratch-color-picker

Step 4: Adding a score variable


Let’s make a new variable called score. We will use this variable to score 1 point when the bird flies through as set of pipes. To do so we will need to go to the variable section:
scratch-variables-section
Then you will click on the “Make a Variable button”.
scratch-make-variable
Give a name to your variable: score and tick the option “For all sprites”
scratch-ball-bouncing-code-complete
Make sure your variable is visible (Tick the checkbox next to the variable itself):
scratch-make-variable-visible

Let’s add the pipes


We will need to “paint” a new sprite for the pipe:
scratch-paint-new-sprite
scratch-paint-pipes

For our Parrot sprite we will edit our code as follows to reset the score to 0 when the game starts:
scratch-set-score-to-0

Now let’s add some code to our pipes sprite:
scratch-pipes-algorithm

Finally, we will duplicate our pipes sprite:
scratch-duplicate-sprite
And delay the second set of pipes by a few seconds:
scratch-delay-pipes
You can also edit the costume for the second set of pipes to have a different “gap”.

Extension Task


Add a “splash screen” with basic instructions on how to play the game. The splash screen should include a start button to start the game.

The “Game Over” screen should only be displayed for a few seconds and then switch back to the start screen to let the player play again. In this case the score should automatically be reset to 0.

Tagged with:

Breakout Game In Scratch

This blog post will guide you through the main steps needed to create a breakout game in scratch.

scratch-final-breakout-game

Step 1Step 2Step 3Step 4Step 5Step 6Step 7

Step 1: The Paddle

You will first need to delete the cat sprite that comes per default when you create a new Scratch project.

You will then create a new sprite and use the Paddle sprite from the scratch library.
scratch-paddle-sprite

You will then need to add the code required to control the paddle using both the left and right arrow keys:
scratch-paddle-code

Step 2: The Bouncing Ball


Add a new Ball sprite.
scratch-ball-sprite
You can resize this sprite to make it smaller:
scratch-ball-resize
Now let’s add the code to make this ball bounce around the edges of the screen:
scratch-ball-bouncing-code

Step 3: Bouncing off the Paddle


We need to add some code to the ball sprite to make it bounce when it hits the paddle.
scratch-ball-bouncing-code-complete

Step 4: Adding a score variable


Let’s make a new variable called score. We will use this variable to score 1 point per brick we break. To do so you will need to go to the variable section:
scratch-variables-section
Then you will click on the “Make a Variable button”.
scratch-make-variable
Give a name to your variable: score and tick the option “For all sprites”
scratch-ball-bouncing-code-complete
Make sure your variable is visible (Tick the checkbox next to the variable itself):
scratch-make-variable-visible
Let’s add the following code (for the paddle sprite) to initialise our score to 0 when the game starts:
scratch-set-score-0

Step 5: Adding bricks


We will now add a brick sprite:
scratch-button3-sprite
Let’s rename this sprite to brick and resize it to make it smaller (e.g. size: 50).
scratch-brick-sprite
Now let’s add the code to make the brick disappear when the ball hits it. We will also increment (add 1 point) our score when this happens:scratch-break-a-brick

We can now duplicate our sprites at least 10 times to create the brick wall:
scratch-duplicate-sprite
scratch-break-out-game

Step 6: Losing lives


Let’s create a new variable called Number Of Lives, available for all sprites.
scratch-number-of-lives-variable
Let’s update the code of the paddle sprite to initialise our variable to 3 lives when the game start:
scratch-initialise-number-of-lives-variable
Now let’s add a new line sprite:
scratch-line-sprite
Let’s make sure we position sprite just underneath the paddle:
scratch-line-sprite-position
Let’s add some code to the ball sprite that will check if the ball hits this “life line” and if it does the player will lose a life and the ball will bounce back.
scratch-number-of-lives-code

Step 7: Game Over Screen


When the number of lives reaches 0, the game will stop and display a Game Over Screen.
So let’s first create a new Game Over backdrop:
scratch-game-over-screen
Then let’s add some code on the ball sprite:
scratch-number-of-lives-final-code

The End.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area
Tagged with:

Padlock Code Challenge #9

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = The average of all prime numbers between 0 and 999 (rounded to the nearest value).

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #8

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = The largest 3-digit prime number.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #7

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = The largest 3-digit square number.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #6

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = Total number of 3-digit combinations where one digit is equal to the sum of the other two digits.

e.g. 134 and 909 count as valid combinations whereas 124 or 569 are invalid combinations.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #5

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = Total number of 3-digit combinations where at least two digits are equal.

e.g. 030 and 558 count as valid combinations whereas 123 or 468 are invalid combinations.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #4

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = Total number of 3-digit combinations where the sum of all three digits (digit1 + digit2 + digit3) is an odd number

e.g. 034 and 555 count as valid combinations whereas 123 or 468 are invalid combinations.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Padlock Code Challenge #3

padlock-lockedWelcome to our new series of padlock code breaking challenges.

For each of these challenges you will need to write a computer program to work out the padlock code (3-digit number). Your program will need to output the solution of the given hint. You will then be able to input this combination onto the padlock to see if it unlocks it!

Padlock Hint

code = Total number of 3-digit combinations where digit1, digit2 and digit3 are all even numbers

e.g. 024 and 886 count as valid combinations whereas 124 or 456 are invalid combinations.

 

Python Code


Use the trinket below to write a program to solve the above hint.

Padlock


Input the combination on the padlock below and click on “Unlock?” to test your combination.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area