Boolean Statements and Expressions
Activity
A. We worked on Task 1 together in class. Add the link to your project here
Task 1
Mod the Hungry Game:
- When the A button is pressed, instead of setting the value of isHungry to True, set it to be the opposite of what it currently is.
- Add another Boolean variable โisBackgroundYellowโ = true.
- Add same code to On A button pressed to toggle that value.
- Add another If...Thenโฆ Else statement to On Game Update to check the value of isBackgroundYellow and change the background color.
- Comment your code.
Shared project link:
B. You and a partner worked on Task 2 together in class. Add the link to your project here
Task 2 Section B
NOT Left is Right:
- Create a sprite, move the sprite with buttons.
- Make a variable named isLeft and set it to false.
- In on game update, assign isLeft to a spriteโs x position < 80 comparison.
- Use an If block to check if NOT(isLeft).
- If so, make your Sprite say โRight!โ for 200ms
- Comment your code.
Shared project link:
C. Go to Activity: Boolean Statements and Expressions. Complete student tasks 3-4.
Task 3
Pizza or Burger:
- Start a new project named pizzaBurger.
- Create a sprite.
- Create a new Boolean called pizza and set it to true.
- Make pizza alternate values when the player presses B.
- When the player presses A, if pizza is true, then fire a pizza projectile, otherwise fire a burger projectile.
- Comment your code.
Shared project link:
Task 4
Hello, Bye:
- Create a new project named helloGoodbye.
- Create a sprite, make it move with directional keys.
- In on game update, make the sprite say โhelloโ for 200 ms when the sprite x value is less than 30 and sprite y is less than 30.
- Add another if statement and make the sprite say โbyeโ for 200 ms when the sprite x is greater than 80 or the sprite y is greater than 80.
- Comment your code.
Shared project link:
Task 4 Challenge
Create the same behavior while using one or more not blocks. Add comments to your code.
Extension 1
Use functions and parameters with this project.
Shared project link:
Extension 2
Recreate the project in JavaScript or Python.
Shared project link:
Reflection/Homework
What is a Boolean flag? Describe a case in which you might you want to use one?
What is the difference between an and block and an or block?
- In what cases will they both evaluate to true?
- In what cases will they both evaluate to false?
- In what cases will they evaluate differently?