logic problem for a tower defence.

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.
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
-
pinata14 Posts: 150
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
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
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.
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.
- 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).
abs(-2) = |-2| =2
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.