How do I Spawn Random Enemy Types in a Room

  • 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.

  • 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

  • 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...

  • 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..

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I got it to work. Thanks Jobel!

  • Could you post capx pls ?

  • Sorry, I don't think I have the ability to post those yet.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)