STEP 13: When the ball hits the player's head, we want it to bounce up! A negative y-speed makes the ball fall, so a positive speed will make it bounce up! On each bounce, let's negate and slightly increase the speed of the ball.

  • Go to and drag Set y Speed onto the last line of the head_ball() function.
  • Change sprite to hit_sprite. In this collision, the hit_sprite is the ball!
  • Replace the 5 in parentheses with the equation (-my_var + 1). Make sure my_var is negative!

def set_stage(): """ Sets up the stage for the game """ stage.set_background("soccerfield") stage.disable_floor() def add_player(): """ Adds a player to the stage for the user to control """ player = codesters.Sprite("player1") player.go_to(0, -180) player.set_size(0.75) return player def add_ball(): """ Adds a ball to the stage and sets its attributes """ ball = codesters.Sprite("soccerball") ball.set_y_speed(-8) def head_ball(sprite, hit_sprite): """ Detects collisions between the player and ball """ my_var = hit_sprite.get_y_speed() def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() add_ball() player.event_collision(head_ball) main()