STEP 7: Each time the interval event runs, we get a point. That means we need score to increase!

To change an existing variable inside a function or event, we need to make the variable global.

  • No more spinning please! Find this code in the interval event and delete it: sprite.turn_left(15)
  • Go to the LOGIC tab and toolkit. Drag Global Variable out so that it is indented inside the event.
  • Drag Add Value onto the next line. Make sure it's also indented! Change all my_var variables to score.

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

# Program variables (DON'T DELETE!!!) block_speed = -6 # controls how fast the pipes move across the stage block_gap = 200 # controls the space between the top and bottom of each pipe block_interval = 1 # controls how often a new pipe appears gravity = 8 # controls how fast the sprite falls flappiness = 5 # controls how much the sprite moves up # Store and display score score = 0 score_text = codesters.Text("Score: " + str(score), 100, 200, "yellow") ######################################################################## # ADD CODE BELOW THIS LINE # ######################################################################## stage.set_background("space") stage.disable_all_walls() sprite = codesters.Sprite("dinosaur") sprite.set_size(0.4) sprite.set_say_color("yellow") sprite.say("TAP THE SPACE BAR TO GUIDE ME THROUGH THE BLOCKS!", 3) sprite.go_to(-200, 0) stage.set_gravity(gravity) def space_bar(): sprite.jump(flappiness) stage.event_key("space", space_bar) def interval(): sprite.turn_left(15) # add any other actions... stage.event_interval(interval, block_interval)
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)