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

2016/9/12

how do I use the getObjectsInRange method the right way?

A2O A2O

2016/9/12

#
I have a player and an enemy. Now I want the player to hit, which inflicts damage to every enemy in a particular range. how do I do that? my method looks kinda empty atm, because I'm not sure how to access the found enemies beacuse I then have to make the enemy to "play" the getHit method. Not sure if my point is too lose here, do you guys even understand what I'm talking about? thats my method so far.
public void hit()
    {
        if (!getObjectsInRange(5, Enemy.class).isEmpty())
        {
            This is where I need the found enemies to play the getHit method
        }
    }
any suggestions?
Super_Hippo Super_Hippo

2016/9/12

#
It could look like this:
for (Object obj : getObjectsInRange(5, Enemy.class))
{
    Enemy e = (Enemy) obj;
    e.getHit();
}
You need to login to post a reply.