PASO 13: Hagamos que el programa cree rocas de diferentes tamaños cada vez que corra el evento de intervalo.

  • Clic en . Arrastra Set Height y suéltalo DENTRO de tu evento de intervalo.
  • Cambia el nombre en frente a top_rock. Cambia el número dentro del comando a la variable top_height.

Recuerda que la variable top_height es un número generado aleatoriamente, creado cada vez que corre el evento de intervalo. Ahora, cuando ejecutamos el programa, ¡veremos rocas de diferentes tamaños!

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

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)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)