STEP 10: We'll use this interval event to make fish food fall from the top of the screen every few seconds.

Remember, an indent is 4 spaces or 1 tab. Commands must be indented in an event in order to run.

  • Find and delete this line in the interval event: ····sprite.turn_left(15)¬
  • In LOGIC, go to and drag out Random Integer. Drop it INDENTED inside of the interval event.

We are going to use this random number to control where the food appears.

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) def interval(): sprite.turn_left(15) # add any other actions... stage.event_interval(interval, 2)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)