PASO 11: ¡Creemos una función para que el jugador y la pelota puedan interactuar!

codificadores son en realidad funciones especiales! Una diferencia importante es que los eventos requieren controladores de eventos que deciden cuándo llamar a la función.

  • Crea líneas en blanco entre add_ball() y main() . Ir a y arrastre Collision aquí.
  • Encuentre el controlador de eventos con este aspecto: sprite . event_collision( colisión ) ¬ ¡Borrar toda la línea!

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 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)