...Spawn powerups randomly from infinite enemies

0 favourites
  • 6 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Hi,

    So here is the scenario:

    I have four different types of enemies in my game. The enemies spawning are infinite. When I kill a random enemy, I want the enemy to spawn a random powerup.

    I am able to spawn random powerups, but cannot figure out how to make it fall from a random enemy when the enemies keep spawning infinitely.

    I don't think the Compare Two Values would work because the count is infinite, so cant put a First Value and Second Value... unless I am mistaken.

    Please Help.

    Thanks.

  • If it's spawning from the enemy that was just killed, then when you do the action that destroys the enemy, spawn the powerup then.

    I'm not totally sure if that is what you are asking or not. I was a bit confused :).

  • Hi.

    Yeah, that is what I am aiming for. When the monster dies, it spawns a new object, which is the random powerup. But, I don't want a powerup to spawn on every death. It has to be random. I don't have the monsters in array. Every monster is a unique one.

    So, I have:

    Monster A, Monster B, Monster C, Monster D.

    All the monsters spawn infinitely. Is there a way I can do a collective "random powerup spawn at any death", even though the monsters are not in an array?

    The problem I am facing is since the monsters spawning is infinite, I am not able to give percentage for the powerup drops. :(

  • Hey! I found a workaround for it!! Finally!!!

    Since when any enemy dies, they use a common Smoke sprite, I just made the powerup spawn randomly from the smoke at random seconds.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • how to do it?

  • Just answered something similar to this on another thread;

    Using global variables:

    Global Variable XXXX
    
    event - On enemy death -> Set XXXX to Round(Random(0,100))
    event - if XXXX => 50 -> CreateObject.YOUR.POWERUP.HERE    (so if the variable is greater or equal to 50, spawn a powerup)
                                              Set XXXX to 0  (and reset the variable to be safe it only spawns 1)
    [/code:25uncbt1]
    
    So what you have is 1 variable that you randomise between 0 and 100 on the enemy death.
    If you then check if it's greater than or equal to 50, this will give a 50% chance for spawning a powerup.
    Best to always reset it to 0 after you've spawned one to avoid any chance of accidentally spawning 2.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)