EXTEND—STEP 2: We've stored the ball's current speed in my_var. Let's increase it!

  • In your toolkit, go to LOGIC, click on and drag in Addition inside your collision event.
  • Click inside the code editor and change what's to the right of the = sign from 2 + 3 to -my_var + 1
  • This reverses the direction of the ball and then increases its speed by 1.
  • Click Run, and then Submit and Next to move on.

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

microbit = codesters.Microbit() microbit.show_string("hello") stage.set_background("moon") sprite = codesters.Sprite("astronaut1") sprite.move_down(150) def button_a(): sprite.move_left(50) microbit.event_button_a(button_a) def button_b(): sprite.move_right(50) microbit.event_button_b(button_b) ball = codesters.Sprite("rock") ball.set_x_speed(5) ball.set_y_speed(5) def collision(sprite, hit_sprite): my_var = hit_sprite.get_y_speed() sprite.event_collision(collision) stage.disable_floor()
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)