这是今天你要制作的篮球游戏示例!

  • 点击 运行 以开始游戏。
  • 使用向左键和向下键设置你的投篮。使用空格键投出球。
  • 点击 运行 再次进行游戏。
  • 玩过游戏后,点击 提交 下一步 自己建立游戏!

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

stage.set_background("halfcourt") sprite = codesters.Sprite("player4") sprite.go_to(215, -175) net = codesters.Sprite("basketballnet") net.go_to(215, 175) ball = codesters.Sprite("basketball") x = random.randint(-100, 150) ball.go_to(x, -25) stage.set_gravity(10) stage.set_bounce(.8) ball.set_gravity_off() net.set_gravity_off() left_count = 0 down_count = 0 def left_key(): ball.move_left(10) global left_count left_count += 1 # add other actions... stage.event_key("left", left_key) def down_key(): ball.move_down(10) global down_count down_count += 1 # add other actions... stage.event_key("down", down_key) def space_bar(): ball.set_gravity_on() ball.set_x_speed(left_count) ball.set_y_speed(down_count) # add other actions... stage.event_key("space", space_bar) def collision(ball, hit_sprite): my_var = hit_sprite.get_name() if my_var == "basketballnet": sprite.say("Score!") # add any other actions... ball.event_collision(collision)
  • Run Code
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)