[video] problem with tower defense game.

FloridaGamesFloridaGames Member Posts: 328
edited November -1 in Working with GS (Mac)

My towers attack when an enemy is within range, which is calculated with a magnitude formula. The problem is that they are attacking every enemy within that range, and I only want it to attack one at a time. Any ideas would be greatly appreciated.

Comments

  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    The only things I'm thinking are long winded.

    Have an invisible actor 'target'. And an attribute 'alive'. The guns attack the target.

    If enemy 1 = alive, constrain target x and y position to enemy 1
    otherwise if enemy 2 = alive constrain target x and y position to enemy 2

    etc

    EDIT: Also, to avoid using constrains you can use a manual timer using modulo.
  • FloridaGamesFloridaGames Member Posts: 328
    I'm afraid that wont work, because then enemy 2 couldn't be attack until after enemy 1 is killed. So if enemy 1 leaves the range of a tower and enemy is still in range, which it will because its behind enemy 1, it wont be attacked.
    I do appreciate your attempt though.
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    Then add a condition

    when enemy 1 =in range
    and when enemy 1 = alive

    otherwise
  • firemaplegamesfiremaplegames Member Posts: 3,211
    The way that this is usually done is with an array or a table.

    An array is simply a list of things. However, the items in the list can be complex objects, such as Actors.

    In your case you would create an array called "allEnemiesOnScreen". This list would keep track of all the enemies who are still alive on the screen. If one gets killed, they get removed from the list. If new ones appear, they get added to the list.

    You, or another actor, can essentially "ask" an array questions.

    In this situation, when a tower is about to fire a missile, it would "ask" the array which Actor has the closest X and Y coordinates to the tower. And it would set that Actor as the target.

    An Array takes a bunch of objects and treats them all as one unit. It simplifies the above problem tremendously. As well as being able to make the gameplay more complex.

    You could ask the array things like:

    Which Actor in the list has the most health?
    Which Actor in the list is closest to the exit?
    Which Actor in the list is closest to a particular tower?

    The missiles could ask things like:

    If my target happened to have gotten destroyed before I reached it, which is the next closest target to me?

    Without an array, the above things become needlessly complex. And nearly impossible to do.
    You would need to have so many Rules and so many Constrains that it would kill your performance.
    And that would just be for one homing missile, multiple ones would be crazy.

    Tables and Arrays are on the roadmap. You might want to wait until then to try and tackle something like this.

    In the meantime, perhaps a simpler tower defense game like Plants vs. Zombies would work out better? Where all the towers shoot horizontally and you can use simple collisions. Or have your towers simply create explosions or poison gas clouds that affect an area around them.
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    As always, great advice Joe. I don't come from a programming background like yourself. So I appreciate your in-depth answers to questions like these, as I'm sure many peeps around here do.

    Tower defence games are easily my favourite , so as soon as GS has tables and arrays I'm sure I'll start working on one...!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    @HoneyTribeStudios: Haha, I actually come from an art background ;) I have only been "programming" for a few years now. And that has just been writing Actionscript in Flash.

    I do love it though! I love the logic of it all.

    The above explanation is just a way to put into simpler terms, but that is the basic gist of it. I certainly wouldn't want to insult an actual programmer with that explanation ;)
  • HoneyTribeStudiosHoneyTribeStudios Member Posts: 1,792
    firemaplegames said:
    @HoneyTribeStudios: Haha, I actually come from an art background ;) I have only been "programming" for a few years now. And that has just been writing Actionscript in Flash.

    I do love it though! I love the logic of it all.

    The above explanation is just a way to put into simpler terms, but that is the basic gist of it. I certainly wouldn't want to insult an actual programmer with that explanation ;)

    Ok, well that would explain the artwork in Grisly Manor then :)

    Still, you do have a knack for understanding and explaining how things work in GS in detail without being confusing. That's why I assumed you had a programming background.

    My background is music, so being able to make games with using GS is great. It's quite empowering - being able to create your own games.

    We just released our first game Honey Tribe. Hopefully in a couple more games I'll be able to quit the day job like you did and just concentrate on my own projects!
Sign In or Register to comment.