我们将使用 left_countdown_count 的值来控制投球的距离。

  • 点击 ,将 Set x Speed 拖动到 space_bar() 事件内部。确保带有 ····
  • .set_x_speed() 指令中的数字替换为 left_count
  • 将指令前面的名称更改为 ball

现在,ball 的 x 速度设置为按下向左键的次数(left_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) global down_count down_count += 1 # add other actions... stage.event_key("down", down_key) def space_bar(): ball.set_gravity_on() # add other actions... stage.event_key("space", space_bar)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)