Activity: Random Height
I'M FINISHED WITH HOUR OF CODE!
img

STEP 13: Now let's make our program create different sized rocks each time the interval event runs.

  • Click on . Drag out Set Height and drop it INSIDE your interval event.
  • Change the name in front to top_rock. Change the number inside the command to the variable top_height.

Remember that the variable top_height is a randomly generated number, created each time the interval event runs. Now, when we run the program, we'll see rocks that are different sizes!

stage.set_background("space") sprite = codesters.Sprite("spaceship") sprite.set_size(0.5) sprite.go_to(-200, 0) stage.set_gravity(10) stage.disable_all_walls() def space_bar(): sprite.jump(5) # add other actions... stage.event_key("space", space_bar) def interval(): top_height = random.randint(1,10) # sprite = codesters.Sprite("image", x, y) top_rock = codesters.Sprite("asteroid", 0, 0) # add any other actions... stage.event_interval(interval, 2)
Support