PASO 17: ahora agregaremos newrise a bally para obtener la nueva coordenada y para el balón de fútbol.

  • En , arrastre Addition .
  • ¡Cambie my_var a end_y y reemplace 2 + 3 con newrise + bally !

Ahora tenemos una nueva coordenada y para nuestra pelota. Usaremos netx como nuestra coordenada x, ya que queremos que la pelota se mueva hacia la red, pero end_y como la coordenada y para que la pelota solo golpee la red si el usuario estaba en lo correcto.

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

stage.set_axis(100) stage.create_grid_overlay(10, "grey") stage.set_background("soccerfield") ballx = -80 bally = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) ball = codesters.Sprite("soccerball", ballx, bally) netx = 90 nety = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) net = codesters.Sprite("soccernet", netx, nety) net.flip_right_left() #sprite = codesters.Line(x-start, y-start, x-end, y-end, "color") line = codesters.Line(ballx, bally, netx, nety, "blue") slopeguess = float(line.ask("What is the slope of this line?")) rise = nety - bally run = netx - ballx slope = rise / run # sprite = codesters.Text("text", x, y) sprite = codesters.Text(slope, 0, 30) newrise = slopeguess*run
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)