Buttons



Purpose

Learning: understand boolean expressions and event handlers
Making ADR: create interactive buttons that respond to game state



Sandbox

  1. Open the Buttons Distro Code.
  2. Run it and try these experiments.
    • Click each button several times
    • Wait for buttons to re-enable (watch the sweep animation)
    • Let your wood run out
    • Try clicking disabled buttons
    • Change the initial wood value in setup() to 1, then 20
    • Change the refresh time (last number) in addButton()

Write in your sprint notes:

  • What makes buttons become disabled?
  • How long does each button take to refresh?
  • When do messages appear in the panel?



Walkthrough

  1. Browse these slides. (push the arrows to make sure you don’t miss any)
  1. Grab the vocab walkthrough paper from the classroom.
  2. Copy the terms and definitions on your paper, along with at least one simple example and non-example for each.
  3. Add an observation in the Patterns boxes at the bottom of your paper.

Before continuing:

Make sure your name is on the paper, drop it in the INBOX, then check the box in your sprint notes.



Exercises

Get Wood

Approaching

  1. Duplicate this Buttons Distro Code.
  2. Make these small changes to test your understanding:
    • Change the initial wood value in setup to 100
    • Update the “get wood” button to give 2 wood
    • Change the “fire is burning” message to something else
    • Move the “get wood” button down by changing its y-position

Before continuing:

Rename the sketch Get Wood and save it.

Then write that name in your sprint notes.



New Theme

Proficient

  1. Duplicate your Get Wood sketch.
  2. Pick a theme (space station, kitchen, garden, etc.)
  3. Update the code to match your theme:
    • Rename the variables (e.g., ‘oxygen’ instead of ‘wood’)
    • Change button labels to fit your theme
    • Update the messages in addToPanel()
    • Change button positions if needed

Example themes:

  • Space: oxygen/fuel, “refill tanks”/”check systems”
  • Kitchen: ingredients/heat, “add ingredients”/”adjust temperature”
  • Garden: water/seeds, “water plants”/”plant seeds”

Before continuing:

Rename the sketch New Theme and save it.

Then write that name in your sprint notes.



New Button

Distinguished

  1. Duplicate your New Theme sketch.
  2. Add one new button that:
    • Has a different refresh time
    • Affects your resources in a new way
    • Shows themed messages
    • Gets disabled under certain conditions
  3. Add a new resource variable that fits your theme
  4. Update the draw() function to check your new conditions

Example features:

  • Space: radiation levels affect oxygen consumption
  • Kitchen: temperature affects ingredient quality
  • Garden: seasons change resource availability

Before continuing:

Rename the sketch New Button and save it.

Then write that name in your sprint notes.



🌟 5,000 Fake Bonus Points! 🌟

Done early? Try these challenges:

  1. Color Master

    • Change button colors based on resource levels
    • Add visual feedback when resources are low
  2. Message Quest

    • Write a story that unfolds through panel messages
    • Make buttons reveal different parts of the story
  3. Survival Mode

    • Add difficulty levels that change resource consumption
    • Create special “emergency” buttons that appear when resources are critical

Remember:

Make sure you save each exercise with an appropriate name.