Science Oxford Logo

Collecting Items

In this example, we will add an item to the game that your player can collect. A future tutorial page will expand on this so that the item either gives the character another life, or makes them invulnerable for a certain length of time.

Step 1 is to create a new sprite for the item - but we don't want it to appear at the start of the game, we want it to be created at a random time and in a random position!

To do this, use an on game update every 500ms block, and combine this with a pick random block from the Math menu, to allow your item to be created at random times!

Screenshot of blocks - on game update every pick random 2000 to 5000 ms, set myItem to sprite of kind Item, set myItem position to x pick random 0 to 160 y pick random 0 to 160

Try out this code and see what happens.

The next steps for this project are...

  1. When your character overlaps with the item, destroy it.
  2. When your character overlaps with the item, how can you show that they picked it up? Try changing the appearence of the sprite!
  3. Do you want more than one item to be created at once, or should the old one get destroyed when a new one is created?
  4. What effect do you want the item to have on the character? Addings lives (using the Info menu), or adding invulnerability (you will need an 'if then else' statement!).