How to create multiple moving regions on the fly

dtoebe

  • Posts: 3
I am building a game where the player can create ships in one of 5 lanes from a button at the base of the lane to move to an enemy base at the opposite end of the scene.  Also the AI will be creating ships to move to my base.

These ships need to detect when they are in a range of the opposing ships or base.

Now I've tried to create regions to follow the ships. First creating the region in a "When Created" event then, on either an "When Drawing" event and a "When Updating" event; I make last created region follow self (this works until there are more than on region on the scene, then the new region follows the new ship created).  Then I create a custom region attribute, and that bogs the game down once more than one ship is created.

How can I make a range around each ship created that can move with each ship individually and detect when an opposing ship is within the defined range.

Please let me know of any other info you may need

Tuo

  • *
  • Posts: 2469
Instead of regions, you can also use comparison tests based on position. For example, a ship moving to the right with a firing range of 150:

always
  for each actor of group/type
    if [absolute value of [(y-center of self) - (y-center of actor of group/type)] < 50]
      if [[(x of self) + (width of self) + 150] < (x of group/type)]
        fire
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

dtoebe

  • Posts: 3
Thank you I will try that when I am no forced to actually work... A follow up question.

What would be the advantages / disadvantages to instead using an empty actor as a sensor?

P.S. this is day 3 on Stencyl and this is by far the best visual editor I have used.

Tuo

  • *
  • Posts: 2469
The advantage would simply be if it was easier for you to work with.

The major disadvantage is that actors cause lag, especially if you start doing it with a lot of actors, basically doubling the actor count (and double lag then ;) )
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)