STEP 10: We want to create a new star every other second. We'll do that with some math!

  • From drag out if. Add it indented once ····¬ inside the interval event.
  • Change choice to time % 2. Change "yes" to 0. This tests if time is divisible by 2.
  • From drag out Random Integer. It should be indented twice, like this: ········¬
  • Change my_var to x and the range to (-230, 230). Every other second, we pick a random x-coordinate!

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 time -=1 time_display.update(time) stage.event_interval(interval, 1)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)