Enemy "Queue"

0 favourites
  • 8 posts
From the Asset Store
Pixel Enemies for SHMUP consists of 45 enemy ship sprites to be used in your game.
  • Hey there. In my RPG I'm making, I have an active battle system, but I want to make it so no enemies attack at the same time as another enemy. All enemies take actions on an individualized timer, but even though I've tried to reset/randomize those timers with different events, the enemies almost always sync up anyway. I think I might want to use Wait for Signal, but I don't know if that's the best way to do it. How would you do it?

  • Many ways you could do this, first that comes to mind is to Create an instance variable called order.

    At the beginning of your battle use:

    On whatever trigger you like

    Repeat Enemy.count times

    Pick nth enemy (nth being loopindex)

    - Set enemy.order to loopindex+1

    This will provide you with a number for your enemies from 1 to however many enemies there are.

    Create a static local or global variable called var_order with initial value of 1.

    Then following those events start a timer to begin picking enemies to fight

    so

    On battle ready trigger

    - Start timer "action" (once) for random(0.5,2) (or whatever your timings are)

    On timer "action"

    Pick enemy where enemy.order=var_order

    - Do Enemy action

    Sub event:

    if var_order<enemy.count

    - add one to var_order

    - Start timer "action" (once) for random(0.5,2)

    else

    - Set var_order to 1

    - Start timer "action" (once) for random(0.5,2)

    you will also need some events to shift the enemy.order variable down if an enemy is destroyed.

    Create another global or static local variable called "var_ordershift" and a function called Ordershift.

    Whenever an enemy meets the criteria to be destroyed have it trigger:

    On your trigger

    - set var_ordershift to enemy.order

    - call Function "Ordershift"

    - Destroy Enemy

    On Function "Ordershift"

    Pick Enemy by evaluating: enemy.order>ordershift

    Sub event: For Each Enemy

    - Enemy: Subtract 1 from enemy.order

    Hope that helps

  • Wow, this is thorough! I don't suppose you have a capx of this, do you? My only question is at the beginning about creating an instance variable. This is a variable contained within each instance of an enemy, right? Thanks for your detailed reply!

  • Oh wait, I wasnt reading closely. I see now that the variable is in fact contained in the enemy instance.

  • Have a go and see if you can get it working. Otherwise I could do an example for you but just a bit busy at the moment.

  • Unfortunately it didn't work. I must have missed something. I'll get a capx loaded here soon.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1drv.ms/u/s!AkmrWgxeuxlKhItpN_TAMQLG0JgEYQ

    There is an example of both a global attack timer and individualised attack timers.

  • This is fantastic! Thanks for clearing that up for me.

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