PASO 11: Agreguemos nuevamente el controlador de eventos para nuestra nueva función de colisión.

Los controladores de eventos determinan cuándo debe pasar una función a un sprite o al escenario.

  • Cambie el nombre de la función collision() a head_ball() .
  • Ir a y arrastre Collision Event Handler a la última línea de la función principal.
  • Cambia el sprite a player y, dentro de los paréntesis, cambia collision a head_ball .

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, -155) 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 collision(sprite, hit_sprite): sprite.go_to(0, 0) hit_sprite.hide() # add any other actions... def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() add_ball() main()
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)