Back to Set 2

Code Challenge: Click Target

Difficulty  

divider

The Brief

What they asked for
Put a target on screen. When I click it, it jumps somewhere
else and my score goes up. If I miss, nothing happens except
that I feel bad.

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

  • Session 13 gives you the click and where it happened. Working out whether that point is inside the target is the actual challenge.
  • A point is inside a circle when its distance from the center is less than the radius. math.sqrt exists; so does comparing squares if you would rather not use it.
  • A rectangle target is an easier and completely acceptable answer. Say in your list which you chose and why.
  • Somewhere else should not be the same place twice, and should not be half off the screen. math.random needs bounds.
  • Call math.randomseed(os.time()) once at the top, or every run is identical.

What Success Looks Like

  • The target moves only when it is actually clicked
  • Clicking the background does nothing at all
  • The score is correct after ten clicks and ten misses
  • The target never appears partly outside the window

Click just outside the edge of the target. That is where a hit test is wrong if it is wrong.


Submit

Your requirements list and your program folder, named cc-click-target.

Commence Challenge