EXTEND 1: Let's experiment with making small changes to the game!

  • Find and change the number in the .set_gravity() command from 4 to any other number.
  • Find stage.event_interval(interval,·2)¬. Change 2 to a greater number to drop food less frequently.
  • Find your indented .move_left(20) and .move_right(20) commands. Change 20 to any other number.

You've changed how fast food drops, how often it drops, and how fast the fish swims! What else can we change?

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) # sprite = codesters.Circle(x, y, diameter, "color") food = codesters.Circle(rand_x, 260, 10, "sienna") # add any other actions... stage.event_interval(interval, 2) def collision(sprite, hit_sprite): stage.remove_sprite(hit_sprite) global score score += 1 score_board.update(score) # add any other actions... sprite.event_collision(collision)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)