PASO 13: Cuando la pelota golpea la cabeza del jugador, ¡queremos que rebote! Una velocidad y negativa hace que la pelota caiga, ¡así que una velocidad positiva la hará rebotar! En cada rebote, negemos y aumentemos ligeramente la velocidad de la pelota.

  • Ir a y arrastre Set y Speed a la última línea de la función head_ball() .
  • Cambia el sprite a hit_sprite . ¡En esta colisión, el hit_sprite es la pelota!
  • Reemplace el 5 entre paréntesis con la ecuación (- my_var + 1 ) . ¡Asegúrate de que my_var sea negativo!

To navigate the page using the TAB key, first press ESC to exit the code editor.

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()
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)