Buttons
Purpose
| Learning: | understand boolean expressions and event handlers |
|---|---|
| Making ADR: | create interactive buttons that respond to game state |
Sandbox
- Open the Buttons Distro Code.
- 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
- Browse these slides. (push the arrows to make sure you don’t miss any)
- Grab the vocab walkthrough paper from the classroom.
- Copy the terms and definitions on your paper, along with at least one simple example and non-example for each.
- Add an observation in the
Patternsboxes 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
- Duplicate this Buttons Distro Code.
- Make these small changes to test your understanding:
- Change the initial
woodvalue 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
- Change the initial
Before continuing:
Rename the sketch
Get Woodand save it.Then write that name in your sprint notes.
New Theme
Proficient
- Duplicate your
Get Woodsketch. - Pick a theme (space station, kitchen, garden, etc.)
- 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 Themeand save it.Then write that name in your sprint notes.
New Button
Distinguished
- Duplicate your
New Themesketch. - 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
- Add a new resource variable that fits your theme
- 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 Buttonand save it.Then write that name in your sprint notes.
🌟 5,000 Fake Bonus Points! 🌟
Done early? Try these challenges:
-
Color Master
- Change button colors based on resource levels
- Add visual feedback when resources are low
-
Message Quest
- Write a story that unfolds through panel messages
- Make buttons reveal different parts of the story
-
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.