STEP 9: Let's use an interval event to make fish food fall from the top of the screen every few seconds.

Interval events run once every time a certain number of seconds have passed. The number in the event handler controls the length of the interval. By default, interval events in Codesters run every 2 seconds.

  • Click GRAPHICS, then . Drag out an Interval Event to the very bottom of the program.
  • Click Run and watch the stage to see what this interval event does.

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

stage.set_background("underwater") sprite = codesters.Sprite("fish") sprite.go_to(-100, -220) stage.disable_floor() stage.set_gravity(4) sprite.set_gravity_off() def right_key(): sprite.move_right(20) # add other actions... stage.event_key("right", right_key) def left_key(): sprite.move_left(20) # add other actions... stage.event_key("left", left_key) score = 0 #my_display = codesters.Display(my_var, x, y) score_board = codesters.Display(score, -200, 200)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)