Random power-ups

By the end, potions will appear in random places at random moments, and one lucky coin will glow at random.

What you need

Random chance and Make one now are Advanced. Switch to Advanced mode.

HeroHero from the library on a Grass floor.
PotionPotion from the library. Tick Falls with gravity so it drops to the floor.
Spawner+ Add object โ†’ New โ†’ Spawner. Makes: Potion. Every (seconds): 60. Wander across: 300. Untick Starts making things straight away. Name it Potion Maker.
CoinsA row of Coin sprites, made with Make gridโ€ฆ.
SoundsPower up and Coin.

Build it

  1. Put the Potion Maker near the top, in the middle. Wander across 300 means a potion can land anywhere in a 600-pixel band.
  2. Events tab โ†’ + New event โ†’ โฑ Timer โ†’ Every, 1000. That checks once a second.
  3. Click + andโ€ฆ โ†’ โš™ Special โ†’ Random chance. Set 1 chance in 8.
  4. In Potion Maker choose Make one now. On average a potion appears every eight seconds, but never on a schedule.
  5. + New event โ†’ Hero โ†’ Collides with another object โ†’ Potion. Do Destroy Potion, Add lives 1, play Power up.
  6. Now the lucky coin. + New event โ†’ โฑ Timer โ†’ Every, 5000. + andโ€ฆ โ†’ Coin โ†’ Pick one of them at random.
  7. In the Coin cell choose Flash (blink) for 1 second. Only the picked coin blinks.
  8. Press โ–ถ Play level and wait. Potions drop here and there; one coin winks every five seconds.
WhenEvery 1000 ms1 chance in 8
DoPotion Maker makes one now
WhenHero collides with Potion
DoDestroy PotionAdd 1 to livesPlay sound Power up
WhenEvery 5000 msPick one Coin at random
DoCoin flashes for 1 seconds

Using Random in a formula

Any number box can hold Random(10), which gives 0 to 9. Click ฦ’x to see it in the Functions list. Two ideas:

  • Create an object with X (across) set to Random(600). No spawner needed.
  • Compare two values: Random(10) = equal to 0. That is another way to say "1 chance in 10".

Make it yours

  • Different prizes: a second spawner that makes Heart, with a chance of 1 in 20.
  • A bad surprise: Bomb instead of Potion. Touching it costs a life.
  • Power-ups that wear off: Set speed Hero 80, then Every 10000 โ†’ Set speed 50.

Still stuck?

Try the Chocobreak tutorial, open a sample game and read its rules, or look at the questions people ask.