第 8 步:是时候制作另一个函数了!让我们创建将球添加到舞台的函数。

  • add_player()main()之间拖动Define Function 。将此新函数重命名为add_ball()
  • 拖入Docstring使其成为add_ball()的第一行。
  • 此函数将向舞台添加一个球并设置其属性。编辑文档字符串来说明这一点。

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, -155) return player def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() main()
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)