15 步:现在我们将使用碰撞事件来编程球击网的结果。

if 语句让我们根据之前发生的事情来改变程序。

  • 点击运行并测试您的程序并尝试制作一个篮子。你的精灵有没有说什么?

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

stage.set_background("halfcourt") sprite = codesters.Sprite("player1") sprite.go_to(-175, -150) net = codesters.Sprite("basketballnet") net.go_to(215, 175) stage.set_gravity(10) sprite.set_gravity_off() def click(sprite): ball = codesters.Sprite("basketball") ball.go_to(-175, -125) ball.set_x_speed(10) ball.set_y_speed(10) # add other actions... sprite.event_click(click) stage.disable_right_wall() def collision(net, hit_sprite): my_var = hit_sprite.get_image_name() if my_var == "codesters": sprite.say("I hit something!") # add any other actions... net.event_collision(collision)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)