Mada za sehemu hiiDesign simple computer programmesMada 1
- Develop simple games that use two shapes by using block-based programming language
Simple Games with Two Shapes in Scratch
A computer game is a program that responds to your actions and makes decisions. In this topic, you will learn how to create a simple game using two shapes by using Scratch, a block-based programming language. You will combine what you learned about sequences, repetition, decision structures, and drawing shapes to build an interactive game.
Before creating a game with two shapes, remember these programming concepts:
Sequence
Steps that run one after another in order. The computer reads your blocks from top to bottom.
Repetition
Repeating an action many times using loops. In Scratch, you can use:
- repeat ( ) — repeat a specific number of times
- repeat until ( ) — repeat until a condition is met
- forever — repeat without stopping
Decision Making
Using if ( ) then or if ( ) then else blocks to make choices based on conditions.
Variables
Containers that store information. You can create variables using the Variables block in Scratch.
Drawing Shapes
Use the Pen extension to draw shapes. Remember:
- A circle needs 360 repetitions with small turns
- For shapes with sides, you need to calculate the turn angle:

Game Idea: "Catch the Circle"
We will create a game where:
- A square moves left and right at the bottom of the screen
- A circle falls from the top
- The player uses arrow keys to move the square
- When the circle touches the square, the player scores a point
- The circle then resets to the top
Step-by-Step Instructions
Step 1: Prepare the Stage
- Open Scratch on the computer
- Delete the existing cat sprite
- Click "Choose a Sprite" and select a circle shape (or draw one)
- Rename this sprite to "Circle"
Step 2: Draw the Second Shape (Square)
- Click "Choose a Sprite" again
- Select "Paint" to create a new sprite
- Use the square tool to draw a small square
- Rename this sprite to "Square"
Step 3: Set Up the Square Sprite
- Select the Square sprite
- Add this code to make it respond to keyboard:
when green flag clicked
go to x: 0 y: -150
forever
if <key (left arrow) pressed?> then
change x by (-5)
end
if <key (right arrow) pressed?> then
change x by (5)
end
end
Step 4: Set Up the Circle Sprite
- Select the Circle sprite
- Create a variable called "Score" (from Variables block)
- Add this code:
when green flag clicked
set Score to 0
go to x: (pick random -200 to 200) y: 150
forever
change y by (-3)
if <y position < -150> then
go to x: (pick random -200 to 200) y: 150
end
if <touching (Square)?> then
change Score by (1)
go to x: (pick random -200 to 200) y: 150
say (Join "Score: " (Score)) for (1) seconds
end
end
Step 5: Test Your Game
- Click the green flag to start
- Use the left and right arrow keys to move the square
- Try to catch the falling circle
- Watch your score increase each time you catch it
Square Movement
- The forever block keeps checking for key presses
- change x by moves the sprite left or right
- This uses sequence (steps run in order) and decision (if key pressed, then move)
Circle Movement
- The circle falls by change y by (-3) repeated forever
- When the circle goes below the screen (y position < -150), it resets to the top at a random x position
- When the circle touches the square, the score increases and the circle resets
- This uses repetition (forever) and decision (if touching)
- Use sequence to organize your code steps in order
- Use repetition (forever, repeat) to make things move continuously
- Use decision (if/then/else) to check for collisions and conditions
- Use variables to keep track of scores and other changing values
- Drawing shapes requires the Pen extension
- For a game to be fun, it needs:
- Something that moves automatically
- Something the player controls
- A goal or score
- Feedback when something happens
- Forgetting to reset positions — Always send the falling shape back to the top after it is caught or goes off screen
- Using the wrong sprite — Make sure you select the correct sprite before adding code
- Not checking collisions properly — Use the touching block from Sensing to detect when sprites meet
In Tanzania, block-based programming skills are used in small businesses and schools. For example, a shop owner at a local market in Dar es Salaam could create a simple inventory game to teach young helpers how to count and match items. The game could show two shapes representing different products (like a circle for oranges and a square for mangoes), and the helper must select the correct one to practice counting skills. This same skill can be used to create educational games for younger children to learn basic mathematics using locally relevant examples like counting shillings or measuring rice and beans.
Swali
What does the sequence control structure do in a computer program?
Ingia ili kuwasilisha jibu lako na lihesabiwe katika umahiri wako.
Ingia ili kufanya mazoeziMwalimu
Umekwama? Niulize chochote kuhusu mada hii.
Ingia ili kumuuliza Mwalimu wa AI wa Sonza kuhusu swali hili.
Ingia ili kuuliza