第 12 步:好的,当球员和球发生碰撞时发生了一些事情,但不是我们想要的。让我们修复结果!

  • 删除所有在head_ball()中缩进的代码。
  • 单击逻辑。去并拖入Docstring ,使其缩进到head_ball().编辑它以描述功能。
  • 在图形和,在head_ball()中拖动Get y Speed 。将sprite更改为hit_sprite

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

def set_stage(): """ Sets up the stage for the game """ stage.set_background("soccerfield") stage.disable_floor() def add_player(): """ Adds a player to the stage for the user to control """ player = codesters.Sprite("player1") player.go_to(0, -180) player.set_size(0.75) return player def add_ball(): """ Adds a ball to the stage and sets its attributes """ ball = codesters.Sprite("soccerball") ball.set_y_speed(-8) def head_ball(sprite, hit_sprite): sprite.go_to(0, 0) hit_sprite.hide() # add any other actions... def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() add_ball() player.event_collision(head_ball) main()
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)