How do I make a random enemy spawn a key

Get help using Construct 2

Post » Tue Sep 27, 2016 8:57 pm

In my game i have 4 different enemies. When the player kills an enemy they spawn a key that opens a chest.

I'd like to be able to have a different enemy spawn that key. EXAMPLE: player kills enemy 2, they spawn the key. If the player quits the game and restarts or passes that level on the next level(s) enemy 4 will spawn the key.


Thanks for any help.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Tue Sep 27, 2016 10:45 pm

jeffige wrote:In my game i have 4 different enemies. When the player kills an enemy they spawn a key that opens a chest.

I'd like to be able to have a different enemy spawn that key. EXAMPLE: player kills enemy 2, they spawn the key. If the player quits the game and restarts or passes that level on the next level(s) enemy 4 will spawn the key.


Thanks for any help.


My first thought is to have an instance variable that is a boolean (hasKey - default to no). Then set an event to randomize it
On Layout Start - > pick random instance --> set boolean to yes

Or could do:
On instance destroyed
If instance count > 1
If random(0,1) > 0.75 then spawn key
Else (if instance count is 1) then spawn key
ImageImageImage
B
39
S
22
G
11
Posts: 486
Reputation: 9,913

Post » Wed Sep 28, 2016 1:14 pm

If you're wanting it to always be a different enemy then I would go the instance variable route like badmoodtaylor suggested. You're question sounds like you want this difference across multiple levels (layouts), so you would need to store the enemy number that had key last time in a global and filter him out next spawn.
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
B
65
S
17
G
8
Posts: 636
Reputation: 9,333


Return to How do I....?

Who is online

Users browsing this forum: troxx and 1 guest