STEP 8: Now it's time to make the time count down using the interval event!

  • From drop Subtract Value indented on the next line of the interval event.
  • Change my_var to time. The time will now decrease by 1 every time the interval event runs.
  • Drag out Update Display. Change my_display to time_display and my_var to time.
  • Run your code and watch the display. The time is counting down too slowly! We'll fix that next.

To navigate the page using the TAB key, first press ESC to exit the code editor.

stage.set_background("moon") sprite = codesters.Sprite("hedgehog", 0, -210) score = 0 #my_display = codesters.Display(my_var, x, y) score_display = codesters.Display(score, -210, -210) time = 60 #my_display = codesters.Display(my_var, x, y) time_display = codesters.Display(time, 210, -210) def left_key(): rotation = sprite.get_rotation() print(rotation) sprite.set_rotation(rotation+3) # add other actions... stage.event_key("left", left_key) def right_key(): rotation = sprite.get_rotation() print(rotation) sprite.set_rotation(rotation-3) # add other actions... stage.event_key("right", right_key) def interval(): global time stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)