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

2012/2/26

getObjectsInRange help!

1
2
danpost danpost

2012/2/29

#
The following code should find the closest Enemy class object (if any Enemy class objects are in the world), no matter how far it may be from the player, and transport it to that player.
if (!getObjectsInRange(1000, Enemy.class).isEmpty)
{
    int closeness = 0;
    while (getObjectsInRange(closeness, Enemy.class).isEmpty) closeness++;
    Enemy enemy = (Enemy) getObjectsInRange(closeness, Enemy.class).get(0);
    enemy.setLocation(getX(), getY());
}
Y3llowMustang Y3llowMustang

2012/2/29

#
Thanks for the help!(:
You need to login to post a reply.
1
2