More results...

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

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

Padlock Code Challenge #2

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 < digit3

e.g. 123 and 358 count as valid combinations whereas 321 or 011 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 #1

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 = 1 + 2 + 3 + 4 + … + 38 + 39 + 40

 

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