Now we'll make the sprite that the user will catch. We'll use both of the random variables we set up.

  • Go to and drag out Sprite at Position. Drop it inside the interval event.
  • The sprite's name is the word before the equals sign. Change the sprite's name to info.
  • Delete "codester" in the .Sprite() command and replace it with info_img. It should not have quotes around it.

Now the sprite will display one of the randomly chosen images from the list we made earlier.

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

stage.set_background("schoolhallway") sprite = codesters.Sprite("person8") stage.set_gravity(4) stage.disable_floor() sprite.set_gravity_off() sprite.go_to(0, -220) score = 0 score_board = codesters.Display(score) my_info = ["cellphone", "address", "birthdate"] def left_key(): sprite.move_left(20) # add other actions... stage.event_key("left", left_key) def right_key(): sprite.move_right(20) # add other actions... stage.event_key("right", right_key) def interval(): x = random.randint(-230, 230) info_img = random.choice(my_info) # add any other actions... stage.event_interval(interval, 3)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)