Close
Close full mode
logoMakeCode AP CSP

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:

  1. 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.
  2. Add another Boolean variable โ€œisBackgroundYellowโ€ = true.
  3. Add same code to On A button pressed to toggle that value.
  4. Add another If...Thenโ€ฆ Else statement to On Game Update to check the value of isBackgroundYellow and change the background color.
  5. 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:

  1. Create a sprite, move the sprite with buttons.
  2. Make a variable named isLeft and set it to false.
  3. In on game update, assign isLeft to a spriteโ€™s x position < 80 comparison.
  4. Use an If block to check if NOT(isLeft).
  5. If so, make your Sprite say โ€œRight!โ€ for 200ms
  6. Comment your code.

Shared project link:

C. Go to Activity: Boolean Statements and Expressions. Complete student tasks 3-4.

Boolean Statements and Expressions

Task 3

Pizza or Burger:

  1. Start a new project named pizzaBurger.
  2. Create a sprite.
  3. Create a new Boolean called pizza and set it to true.
  4. Make pizza alternate values when the player presses B.
  5. When the player presses A, if pizza is true, then fire a pizza projectile, otherwise fire a burger projectile.
  6. Comment your code.

Shared project link:

Task 4

Hello, Bye:

  1. Create a new project named helloGoodbye.
  2. Create a sprite, make it move with directional keys.
  3. 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.
  4. 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.
  5. 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

  1. What is a Boolean flag? Describe a case in which you might you want to use one?

  2. 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?
๐Ÿ“˜ Unit 5 - AAP Part 2 โ€” Previous
Complex Conditionals
Next โ€” ๐Ÿ“˜ Unit 5 - AAP Part 2
Student Tasks/Solutions