EXTEND 2: Right now, the food always drops at the same speed. Let's change that too!

  • At the top of your code, find and delete the .set_gravity() and .set_gravity_off() lines.
  • Look for the indented line that creates the food inside the interval hint (hint: it starts food = )
  • From add Random Integer indented just below the line that creates food.
  • Change my_var to rand_drop, and 1, 10 to -15, -5. Next, let's make the food drop again!

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(0, -220) stage.disable_floor() stage.set_gravity(8) sprite.set_gravity_off() score = 0 #my_display = codesters.Display(my_var, x, y) score_board = codesters.Display(score, -200, 150) def right_key(): sprite.move_right(30) # add other actions... stage.event_key("right", right_key) def left_key(): sprite.move_left(30) # add other actions... stage.event_key("left", left_key) def interval(): x = random.randint(-250, 250) # sprite = codesters.Circle(x, y, diameter, "color") food = codesters.Circle(x, 260, 10, "sienna") # add any other actions... stage.event_interval(interval, 1) def collision(sprite, hit_sprite): global score stage.remove_sprite(hit_sprite) score += 1 score_board.update(score) # add any other actions... sprite.event_collision(collision)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)