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

2017/4/27

Coordinates from another class

Benni Benni

2017/4/27

#
Hey there. I want to programm, that my first object "Kurzpompfe" (don't take care to the name) can hit the second object "Langpompfe", but only in a given radius. for example 20. how can i do that? I tried to do it like this:
distance = getX()-getX(Langpompfe.class);
but this doesn't work. i hope anyone can help me and you understand my problem. Benni P.s. I just started to programm java in school
danpost danpost

2017/4/27

#
Use the 'getObjectsInRange' method:
if (!getObjectsInRange(20, Langpompfe.class).isEmpty())
The above line will have its block of code execute if any are in range.
You need to login to post a reply.