16 步:当球和球员发生碰撞时,我们需要将球从足球运动员的头部弹回。

Python 中的缩进很重要。如果命令没有正确缩进,你的程序会抛出一个错误。

  • 首先,删除这条线精灵go_to( 0 , · 0 )然后删除这一行hit_sprite隐藏()
  • ,在碰撞事件中拖动Set y Speed 。应该缩进 空格。
  • 点击运行。现在,当球与我们的足球运动员相撞时,什么都不会发生。

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

microbit = codesters.Microbit() microbit.show_string("hello") stage.set_background("soccerfield") sprite = codesters.Sprite("athlete2") sprite.move_down(150) def button_a(): sprite.move_left(50) microbit.event_button_a(button_a) def button_b(): sprite.move_right(50) microbit.event_button_b(button_b) ball = codesters.Sprite("soccerball") ball.set_x_speed(5) ball.set_y_speed(5) def collision(sprite, hit_sprite): sprite.go_to(0, 0) hit_sprite.hide() # add any other actions... sprite.event_collision(collision)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)