STEP 16: We need the ball to bounce off the soccer player's head when ball and player collide.

Indents in Python are important. If commands aren't indented correctly, your program will throw an error.

  • First, DELETE this line sprite.go_to(0,·0) and then DELETE this line hit_sprite.hide().
  • In , drag in Set y Speed INSIDE you collision event. It should be indented four spaces.
  • Click Run. Right now, nothing should happen when the ball collides with our soccer player.

microbit = codesters.Microbit() microbit.show_string("hello") stage.set_background("soccerfield") sprite = codesters.Sprite("athlete2") sprite.move_down(150) def button_a(): sprite.move_left(50) microbit.event_button_a(button_a) def button_b(): sprite.move_right(50) microbit.event_button_b(button_b) ball = codesters.Sprite("soccerball") ball.set_x_speed(5) ball.set_y_speed(5) def collision(sprite, hit_sprite): sprite.go_to(0, 0) hit_sprite.hide() # add any other actions... sprite.event_collision(collision)