How do I Spawn Random Enemy Types in a Room

Get help using Construct 2

Post » Thu May 21, 2015 4:32 am

Hi all.

I'm trying to make my game spawn random enemies in a room. My current method is to have a global variable called "EnemyThreatValue" that increases as you progress. Each enemy has an instance variable called "Threat" assigned to them. I want to choose a random enemy, spawn that enemy, deduct "Threat" from "EnemyThreatValue", and repeat as long as "EnemyThreatValue > zero. But for the life of me I can't figure out how to get the program to choose a random enemy. Any tips?

Thanks.
B
8
S
2
Posts: 35
Reputation: 572

Post » Thu May 21, 2015 5:03 am

well it depends on how your game is set up.

if you have all your enemies off screen for example - in "standby" mode, and they were in a family called Enemies. You could "Pick Random Enemies" which would pick one of them and you could execute your logic from there...

Another way would be to make a unique animation or frame for each enemy in a single sprite. You'd give it an instance variable called "Type", and that would be which enemy it was.. that would correspond to which animation/or frame you would use.

Another way that might be best is to just have a function that spawns different enemies based on what you pass to it. So if you had 3 enemies: Imp, Guard, Troll

you'd do:

Call Function SpawnRandomEnemy(choose("Imp",Guard","Troll")) //this will pick a random one

Function SpawnEnemy
If Function.Param(0) = "Imp" then do Spawn Imp
If Function.Param(0) = "Guard" then do Spawn Guard
If Function.Param(0) = "Troll" then do Spawn Troll
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Fri May 22, 2015 4:55 am

Hi Jobel,

Thanks for the tips. I'll try it out and see how it works.
Now, time to go look up the details on functions and parameters...
B
8
S
2
Posts: 35
Reputation: 572

Post » Sat May 23, 2015 3:20 am

It's pretty easy.. there's 2 parts... 1. you write what happens when the function is called.. and 2. then you call it from somewhere.

to pass it parameters you just add the to the dialogue in the call Action. In your actual function you just reference each parameter using the generic Function.Param() <-- the number signifies which parameter it is.. 1st, 2nd or 3rd.. etc..
B
88
S
29
G
14
Posts: 1,154
Reputation: 15,003

Post » Sat May 23, 2015 6:50 am

I got it to work. Thanks Jobel!
B
8
S
2
Posts: 35
Reputation: 572

Post » Thu Jul 02, 2015 9:03 pm

Could you post capx pls ?
B
39
S
6
Posts: 3
Reputation: 2,073

Post » Sat Jul 04, 2015 3:09 am

Sorry, I don't think I have the ability to post those yet.
B
8
S
2
Posts: 35
Reputation: 572


Return to How do I....?

Who is online

Users browsing this forum: NN81, plinkie, sublimate and 6 guests