This site requires JavaScript, please enable it in your browser!
Greenfoot back
xWanna
xWanna wrote ...

2015/5/11

Adding same Objects that act seperatly

1
2
danpost danpost

2015/6/2

#
xWanna wrote...
How to do it? << get number of intersectors minus line of sight objects (count) >> I think with a list, but can you tell me?
You will be getting a List object from the return of 'getIntersectingObjects', at any rate. However, you could determine the count this way:
int count = getIntersectingObjects(null).size() - getIntersectingObjects(LineOfSight.class).size();
where the final count will be two plus the number of objects that actually interfere with the line of sight. If you have other objects that should not be considered as ones that interfere with the line of sight, you could subtract their count the same way. If the only objects that could interfere are of a specific class, then the final count would simply be (for example):
int count = getIntersectingObjects(Wall.class).size();
// or
int count = getIntersectingObjects(Obstacle.class).size(); // where Obstacle is super to all classes that create obstacles
which would not include the two actors being lined up. Actually, in this case, the count is not even needed. You could just use something like this:
boolean  unobstructed = getIntersectingObjects(Wall.class).isEmpty();
You need to login to post a reply.
1
2