PREVIEW: This is an example of the basketball game you will make today!

  • Click Run to start the game and follow the instructions on the stage.
  • After you play the game, click Submit and Next to build it yourself!

Click Submit and Next after every activity in this lesson to move to the next activity!

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

stage.set_background("halfcourt") sprite = codesters.Sprite("player4", -175, -150) net = codesters.Sprite("basketballnet", 215, 175) instructions = codesters.Text("Click on the sprite to shoot the basketball. Hit the basket to score a point!", 0, 50, "white") stage.set_gravity(10) sprite.set_gravity_off() score = 0 score_display = codesters.Display(score, -200, 150) def click(sprite): ball = codesters.Sprite("basketball", -150, -100) ball.set_x_speed(10) ball.set_y_speed(10) sprite.event_click(click) def collision(net, hit_sprite): global score my_var = hit_sprite.get_name() if my_var == "basketball": hit_sprite.hide() score += 1 score_display.update(score) net.event_collision(collision) stage.disable_right_wall()
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)