STEP 12: Feeding time! We will create and drop food.

  • Click GRAPHICS then . Drag Circle INDENTED under the rand_x line in the interval event.
  • Make sure the .Circle() line of code is INDENTED! Remember, an indent is 4 spaces or 1 tab.
  • Change the variable name from sprite to food. Change the xy-coordinates from 0, 0 to rand_x, 260.
  • Change the circle's radius from 100 to 10 and the color from "blue" to "sienna".

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(): rand_x = random.randint(-250, 250) # 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)