logic problem for a tower defence.

proNounproNoun Member Posts: 8
edited April 2012 in Working with GS (Mac)
OK. I've got a lot working in the mechanics side of my tower defence. However I am REALLY stuck on 1 logic problem.

How do I get the enemy to know which tower-range it has 'overlapped' with if there are multiple instances of the same tower-range actor??? I can get it all working perfectly if there is only 1 tower, and many enemies - the tower will snipe the exact enemy I want it to; but how in the nackers can I tell the enemy actor which instance of a tower range it has entered??

Any help would be highly appreciated! I'm committed to figuring this problem out before I sleep tonight....

Thanks in advance.

EDIT: I've uploaded a simple screenshot of what my game looks like currently within the creator preview;
http://img707.imageshack.us/img707/4244/gameshot.png
- Just think of each green blob as a tower with an area around it for an attack range. The red dots are the enemies that they need to kill. I can't just fire a projectile as it might kill 1,2 or sometimes 3 enemies due to enemy grouping so close together. What I need to figure out is how to get a red dot to have information about which green blob it is near (or multiple green blob ranges)... even though they are all the same actor.

EDIT: FYI, every tower has it's own ID attribute with unique value, and every enemy (red dot) has it's own unique ID attribute.

Best Answer

  • pinata14pinata14 Posts: 150
    edited April 2012 Accepted Answer
    hmm, cant you just use distances? real attribute self.distance
    constrain attribute self.distance to abs(magnitude(game.towerx-self.x,game.towery-self.y))
    ---
    when self.distance <= game.towerrange <br /> (html glitch?)
    every game.towerrateoffire
    change attribute self.health to self.health-game.damage*self.towersinrange
    ---
    when self.range = game.towerrange
    change attribute self.towersinrange to self.towersinrange+1
    otherwise
    when self.range > game.towerrange
    change attribute self.towersinrange to self.towersinrange-1

    hope this helps and let me know!
    -Ryan

Answers

  • proNounproNoun Member Posts: 8
    edited April 2012
    I'm thinking it is impossible... but that I could instead create multiple actors that will all act the same; but at least then a separate actor will know the difference between colliding with tower1 and tower2.
    Because no matter which way I do it, I can't figure out how to allow all of the following possibilities at the same time;
    *multiple enemies to be inside the range of a single tower
    *an enemy to be inside the range of multiple towers
    **if the towers are the same actor.

    EDIT: I really wish an actor could interact directly with the custom attributes of another actor - not only itself and game attributes.
    e.g. if 'enemy1' overlaps 'towertype1'; where 'towertype1' has the custom attribute of 'towertype1 ID = 3 '
    -> Then do this
    Ahh well :(
  • mynameisacemynameisace Hull, UKMember Posts: 2,484
    If I grasp what you're asking, then easy. Just create an index game attribute game.zone and for each zone, double click the actor in the scene and change its name to 1, then the next 2, etc.

    In the prototype, just create when actor overlaps or collides with whichever actor you collid with then change attribute game.zone to self.name - now you have which zone it is in as a global attribute. Alternatively, instead of changing the name, have a self attribute to handle the numbers and change the numbers in the actors on the scene.

    Write down which zone is which to keep track.
  • proNounproNoun Member Posts: 8
    edited April 2012
    @mynameisace I'll try to explain better.
    every zone has it's own unique name, or ID.
    I've created game.zone and assign the value of self.ID (from the zone) to game.zone whenever the enemy actor collides with the zone. It works for the first collision with each zone. But because I have so many enemy actors to collide with, there will be multiple of the same enemy actor within the one zone - which causes the Rule to never update.

    In other words - I display game.zone on the prototype, and it is updated for when an enemy actor collides with zone. The value of game.zone will change to the ID of the zone when the first enemy actor enters it - but not the 2nd, or 3rd, or 4th (because the 1st is still inside the zone)

    EDIT: @mynameisace I just realised you said to use an 'index' attribute. I haven't yet used an index attribute, so maybe it will do something I need. [I'm going to have to look up how to use the index type attribute] EDIT: Just positive integers. as the cookbook says, these will only become really useful when GS introduces arrays and tables.
  • proNounproNoun Member Posts: 8
    @pinata14 That is a very interesting solution. I don't have all day today to work on it, so it might take me some time to get back to you (tonight or tomorrow) - but I will definitely give this a shot. Also, I don't know how the abs function works so I'm going to have to look that up.
    - If it works it seems like an elegant solution, as I'd be able to expand it to work with different types of towers.
    - On one point though, as far as I understand. your solution would make every enemy actor get damaged (roughly) equally; instead of the tower only shooting 1 within it's range at a time. (but I could probably fix that with some booleans).
  • pinata14pinata14 Member Posts: 150
    edited April 2012
    @pronoun oh hmm i see what you mean, i will try to give this a little thought sometime later but im not sure if it is possible to do what you want. anyway the abs function is just absolute value i think (right guys?) so like
    abs(-2) = |-2| =2
  • proNounproNoun Member Posts: 8
    edited April 2012
    @pinata14 Thanks for the idea - I will definitely give it a shot - but I think the best way for me to do what I want is to create 10 different actors for 10 basic towers (rather than 1 actor and try to get it to be 10 towers); and use game variables to only build one of each actor. Sure this means more copied & pasted code and more coding time, etc.... but as I was planning on introducing tower upgrades, I was already going to be doing this to a certain extent.

    Thanks for the insight and I'll keep you updated on how the distance implementation goes.

    EDIT: I don't think i can constrain self.distance to this;
    'abs(magnitude(game.towerx-self.x,game.towery-self.y))'
    if there are multiple towers to calculate it's distance from...
    - So unless I create game x and y attributes for upto (max) number of towers and store that information - and create self.distancex for all the different tower's, it can't keep updated it's distance from every tower.

    I think I'll just do what I've been avoiding this whole time - creating many actors instead of many instances of the one actor. That way everything will work.
Sign In or Register to comment.