Back to Set 2

Code Challenge: Traffic Light

Difficulty  

divider

The Brief

What they asked for
Build me a working traffic light. Red, then green, then
amber, then round again, on its own, at a sensible speed.

Write your requirements list before you write any code. What the player does, what happens on screen, and every question the brief did not answer.


Notes

  • You drew this at session 2. Now one of the three is lit and the other two are dark.
  • Something has to remember which light is on, and something has to count time. Both live above love.draw.
  • A timer is a variable that dt is added to. When it passes a threshold, act and reset it — reset it, do not set it to zero and forget.
  • Amber is shorter than the other two. The brief does not say how much. Decide.

What Success Looks Like

  • The three lights cycle on their own with no key presses
  • Exactly one is lit at any moment
  • The cycle repeats forever without drifting or sticking
  • Changing one variable changes how fast the whole thing runs

Test it by leaving it running for two minutes. A timer that is reset wrongly drifts, and two minutes is enough to see it.


Submit

Your requirements list and your program folder, named cc-traffic-light.

Commence Challenge