STEP 11: Hm. Our basketball is just bouncing up and down. Let's shoot it at the basket!

The x speed of a sprite is how fast it moves horizontally. The y speed of a sprite is how fast it moves vertically.

  • In , drag Set x Speed INSIDE your click event. It should be indented 4 spaces.
  • Change the name in front of .set_x_speed() from sprite to ball.
  • Finally, change the number inside the parentheses from 5 to 10. This makes the ball go faster and farther!

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

stage.set_background("halfcourt") sprite = codesters.Sprite("player1") sprite.go_to(-175, -150) net = codesters.Sprite("basketballnet") net.go_to(215, 175) stage.set_gravity(10) sprite.set_gravity_off() def click(sprite): ball = codesters.Sprite("basketball") ball.go_to(-175, -125) # add other actions... sprite.event_click(click)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)