0% found this document useful (0 votes)
9 views

Block Code

The document provides various block-based coding examples that illustrate fundamental programming concepts, such as moving characters, bouncing balls, changing colors, and counting points. It includes both simple and expanded versions of these examples, incorporating additional elements like boundaries, point systems, timers, and animations. The examples are designed to be engaging and demonstrate interactive programming techniques suitable for platforms like Scratch.

Uploaded by

May Thu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Block Code

The document provides various block-based coding examples that illustrate fundamental programming concepts, such as moving characters, bouncing balls, changing colors, and counting points. It includes both simple and expanded versions of these examples, incorporating additional elements like boundaries, point systems, timers, and animations. The examples are designed to be engaging and demonstrate interactive programming techniques suitable for platforms like Scratch.

Uploaded by

May Thu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sure!

Here are a few simple block-based coding examples that demonstrate


fundamental concepts in programming. These examples use blocks similar to those
found in platforms like Scratch:

1. Moving a Character This example moves a character to the right when you press the
"right arrow" key.

• Event Block: "When [right arrow key] is pressed"

• Action Block: "Move [10] steps"

• Condition: None (triggered by the event)

2. Bounce a Ball This example makes a ball bounce back when it hits the edge of the
screen.

• Event Block: "When [green flag] is clicked"

• Forever Block: "Repeat forever"

o Action Block: "Move [5] steps"

o Condition Block: "If on edge, bounce"

3. Changing Colors This example changes the character's color every time you click on
it.

• Event Block: "When [sprite] is clicked"

• Action Block: "Change color effect by [25]"

4. Counting Points This example increases the score by 1 when the player touches an
object.

• Event Block: "When [sprite] is clicked"

• Variable Block: "Set [score] to [0]"

• Condition Block: "If touching [object]"

o Action Block: "Change [score] by [1]"

5. Create a Simple Loop This example shows how to repeat an action multiple times
(e.g., making a character spin).

• Event Block: "When [green flag] is clicked"

• Repeat Block: "Repeat [10] times"


o Action Block: "Turn [15] degrees"

Here are expanded versions of the block-based coding examples, including additional
elements and interactions to make them more engaging:

1. Moving a Character with Boundaries

This example moves a character in different directions when arrow keys are pressed
and ensures it stays within screen boundaries.

• Event Blocks:

o "When [right arrow key] is pressed"

o "When [left arrow key] is pressed"

o "When [up arrow key] is pressed"

o "When [down arrow key] is pressed"

• Action Blocks:

o "Change x by [10]" (for moving right)

o "Change x by [-10]" (for moving left)

o "Change y by [10]" (for moving up)

o "Change y by [-10]" (for moving down)

• Condition Block: "If touching edge, stop moving"

2. Bounce a Ball with Point System

Make the ball bounce around the screen and collect points when it touches certain
objects.

• Event Block: "When [green flag] is clicked"

• Forever Block:

o "Move [5] steps"

o "If touching [object], change [score] by [1]"

o "If on edge, bounce"

• Variable Block: "Set [score] to [0]"

3. Changing Colors and Playing Sounds


Change the character's color and play a sound every time you click on it.

• Event Block: "When [sprite] is clicked"

• Action Blocks:

o "Change color effect by [25]"

o "Play sound [meow] until done"

4. Counting Points and Timer

Add a point system with a timer for a more competitive game experience.

• Event Block: "When [green flag] is clicked"

• Variable Blocks:

o "Set [score] to [0]"

o "Set [timer] to [30]"

• Forever Block:

o "If touching [object], change [score] by [1]"

o "Wait [1] second, change [timer] by [-1]"

• Condition Block: "If [timer] = [0], stop game"

5. Create a Simple Animation

Animate a character walking across the screen.

• Event Block: "When [green flag] is clicked"

• Forever Block:

o "Move [5] steps"

o "Wait [0.5] seconds, switch costume to [walking pose 1]"

o "Wait [0.5] seconds, switch costume to [walking pose 2]"

o "If on edge, bounce"

6. Game: Catch Falling Objects

Create a simple game where a basket catches falling apples.

• Event Block: "When [green flag] is clicked"


• Variable Blocks:

o "Set [score] to [0]"

• Forever Block: (For apples)

o "Move [down 5 steps]"

o "If touching [basket], change [score] by [1], reset position"

• Forever Block: (For basket)

o "If [arrow keys] pressed, move basket [left/right]"

7. Clone Characters for Complexity

Add multiple enemies to a game using cloning.

• Event Block: "When [green flag] is clicked"

• Action Block: "Create clone of [enemy sprite] every [2] seconds"

• Event Block for Clone: "When I start as clone"

• Action Blocks:

o "Move [random number] steps"

o "If touching [hero sprite], end clone"

You might also like