第 11 步:让我们创建一个函数,让球员和球可以互动!

编码器实际上是特殊功能!一个重要的区别是事件需要事件处理程序来决定何时调用函数。

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 add_ball(): """ Adds a ball to the stage and sets its attributes """ ball = codesters.Sprite("soccerball") ball.set_y_speed(-8) def main(): """ Sets up the program and calls other functions """ set_stage() player = add_player() add_ball() main()
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)