PASO 16: Ahora, hagamos seguimiento al número de veces que el usuario presiona la tecla de abajo.

  • Elige la pestaña LOGIC. Ve a y arrastra Global Variable dentro del evento down_key().
  • Cambia la variable que viene después de la palabra clave global a down_count.
  • Desde , arrastra Add Value dentro del evento down_key().
  • Cambia la variable a down_count.


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

stage.set_background("halfcourt") sprite = codesters.Sprite("player4") sprite.go_to(215, -175) net = codesters.Sprite("basketballnet") net.go_to(215, 175) ball = codesters.Sprite("basketball") x = random.randint(-100, 150) ball.go_to(x, -25) stage.set_gravity(10) stage.set_bounce(.8) ball.set_gravity_off() net.set_gravity_off() left_count = 0 down_count = 0 def left_key(): ball.move_left(10) global left_count left_count += 1 # add other actions... stage.event_key("left", left_key) def down_key(): ball.move_down(10) # add other actions... stage.event_key("down", down_key)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)