Let’s dive back into your exciting video game project! Last time, you made the target and danger characters move across the screen. But there was a little problem—they disappeared and never came back! Today, we’re going to learn how to use something called Booleans to make them return and keep moving across the screen.
Booleans are like little switches in a computer program that can be either true or false. They help us make decisions in our code. For example, if a Boolean is true, we might tell a character to keep moving. If it’s false, we might tell it to do something else, like turn around.
In a previous lesson, you learned how to keep Sam the Bat from flying out of his backyard. You used Booleans to check if Sam was “Safe Left” and “Safe Right.” Now, we’re going to use a similar idea in your video game.
Every time your target and danger characters move, the game will check their x coordinates—these are numbers that tell us where they are on the screen from left to right. The game will use a special function called Onscreen to see if the characters are still visible. If Onscreen says false, it means the character has gone off the screen, and the game will move it back to the other side.
First, you’ll need to create the Safe Left and Safe Right functions for your characters, just like you did for Sam the Bat. These functions will help you figure out if a character is about to leave the screen on the left or right side.
Once you have those functions ready, you can combine them into the Onscreen function. This will check both sides and keep your characters moving back and forth across the screen, making your game more fun and challenging!
Did you know that Booleans are named after a mathematician named George Boole? He invented a whole new way of thinking about logic that computers use all the time!
Now you’re ready to make your game even better by using Booleans to keep your characters in action. Have fun coding!
Imagine you are a game designer! Draw a storyboard showing how Booleans help your characters stay on the screen. Use arrows and labels to show when a character should turn around. Share your storyboard with a classmate and explain how Booleans work in your game.
Let’s solve a puzzle! Create a simple maze on paper. Use Booleans to decide if a character can move left, right, up, or down. Write down the Boolean conditions for each move. Can you guide your character to the end of the maze?
Use a coding platform to create a race between two characters. Use Booleans to check if they are still on the screen. If a character goes off-screen, use a Boolean to bring it back to the starting line. See which character wins the race!
In pairs, act out a scene where one of you is a character moving across a screen. The other person uses Booleans to decide if the character should keep moving or turn around. Switch roles and see how Booleans control the action!
Create a quiz for your classmates with questions about Booleans. Include true or false questions and scenarios where they have to decide what a Boolean would do. Test your classmates and see who knows the most about Booleans!
Here’s a sanitized version of the provided YouTube transcript:
—
Let’s take another look at your big game. Last time, you animated the target and danger sprites to move across the screen. However, when they left the screen, they never returned! We’re going to use Booleans to bring them back so they move across the screen repeatedly.
In the last stage, you learned how to keep Sam the Bat from leaving his backyard by using a Boolean to check if he was Safe Left and Safe Right. Now, you’ll add the same functionality to your video game. Each time your target and danger move, the game engine will send their x coordinates to the Onscreen function. If Onscreen returns false, that means the sprite has gone off the screen, and the engine will reset it to the opposite side.
Just like you did with Sam the Bat, you’ll want to first complete the Safe Left and Safe Right functions before combining them both in Onscreen.
—
This version maintains the original meaning while ensuring clarity and professionalism.
Booleans – Booleans are a type of data in coding that can only be true or false. – In our game, we use booleans to check if the player has won or lost.
Code – Code is a set of instructions written in a programming language that a computer can understand and execute. – We wrote code to make the robot move forward and backward.
Characters – Characters are letters, numbers, or symbols that are used in coding and text. – The password must include at least eight characters, including one number.
Game – A game is a program designed for entertainment, often involving challenges or puzzles. – We created a simple game where you catch falling stars by moving a basket.
Onscreen – Onscreen refers to anything that appears on the computer or device display. – The instructions for the game appeared onscreen as soon as we started it.
Safe – In computing, safe means that something is protected from harm or danger, such as viruses or hackers. – It’s important to keep your computer safe by using strong passwords and antivirus software.
Left – Left is a direction or position on the computer screen or in a program, opposite of right. – To move the character left, press the left arrow key on your keyboard.
Right – Right is a direction or position on the computer screen or in a program, opposite of left. – The player moved right to avoid the obstacles in the game.
Coordinates – Coordinates are numbers that determine the position of a point on a grid or screen. – We used coordinates to place the treasure chest at the correct spot in the game.
True – True is a boolean value that indicates something is correct or has happened. – The condition is true if the player collects all the coins in the level.