STEP 6: Now that we spin left, let's add code to spin right if you press the right arrow key!

  • In GRAPHICS, from add Right Key to the very bottom of the program.
  • Find and delete ····sprite.move_right(20)¬ from inside the event.
  • From add Get Rotation indented inside the event. An indent is 4 spaces or 1 tab.
  • Add Set Rotation. Change 45 to rotation-3. Run your code and press the right arrow key!

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

stage.set_background("moon") sprite = codesters.Sprite("hedgehog", 0, -210) score = 0 #my_display = codesters.Display(my_var, x, y) score_display = codesters.Display(score, -210, -210) time = 60 #my_display = codesters.Display(my_var, x, y) time_display = codesters.Display(time, 210, -210) def left_key(): rotation = sprite.get_rotation() print(rotation) sprite.set_rotation(rotation+3) # add other actions... stage.event_key("left", left_key)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)