+ Fighter: Is overlapping Fighter:
// First we build a list of IID
-> Array: Set size to (0,1,1)
+ System: Foreach Fighter
-> Array: push back Fighter.IID on X axis
// Then we need to pick all to be able to use the IID instead of the picked indexes
+ System: Pick all Fighter
+ System: Repeat Array.width times
Local number A = 0 // IID of the first term of the comparaison
-> System: Set A to Array.At(loopindex)
+ System: Repeat Array.width times
Local number B = 0 // IID of the second term of the comparaison
-> System: Set B to Array.At(loopindex)
+ System: A != B
+ System: Fighter(A).team != Fighter(B).team
+ System: distance(Fighter(A).X,Fighter(A).Y,Fighter(B).X,Fighter(B).Y) < Fighter.Width * sqrt(2)
+ System: Pick Fighter instance A
-> Fighter: set State to "attack"
-> System: Stop loop // here since we found a match we stop the inner most loop
Note that there's one little problem with this implementation:
I'm grouping all the Fighters that overlap with other fighters by building a list of IID in an array.
Then I make a team comparaison between all of them.
Which is wrong! Since you only want to check Fighters that overlaps each others. If you have two groups of fighter in two different area that overlap each other you would want to treat them separately.
To kind of adress this issue, I'm using a distance comparaison (in the last subevent)
But it's a bit imprecise. What you would want in fact, to be able to run the overlap check for each possible pair.
One way to do that is to use Family. You check for each Fighter if it overlaps a family containing the fighters. This way you can easily evaluate each pair.
Another way to do that is to handle collisions by yourself. An easy collision check algo is a circle collision. You just have to check if the distance between the object is lower than the sum of the radius of each object in the comparaison pair.
And still another way is to use two different object (let's call them col1 and col2) but with the same collision. You pair them together in the same container so they follow each other and you check overlap between col1 and col2 of each object. This way you can more easily isolate treat each overlap pair separately.
That's equivalent of using family in the principles
Anyway that's the gist of it (: