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

2011/5/27

How to return parameters of intersecting object

quelea quelea

2011/5/27

#
Hello. I am writing a scenario where a predator eats a prey if it intersects with it AND if the parameters of the prey satisfy certain conditions. Thecenario is an offshoot of the lobster crab scenario, and basically when the lobster encounters a crab it only eats the crab if the crab has certain parameters. I have figured out how to return the x and y of an intersecting object (like in the Newton's lab scenario), but how do I get a return of specific crab parameters that I defined myself?? Many thanks for any advice!!
quelea quelea

2011/5/27

#
I have posted the scenario if anyone is interested. It is called crab-evolution 1.0
danpost danpost

2011/5/28

#
I am sure this would work (I HAVE tried it). Instead of returning a boolean in 'canSee', you could return the Worm itself and set it to an Worm variable. Of course, now you would have to check for null in the Worm variable. Then all you need to do, I believe, is set up methods to return the parameters in the class. In Lobster, call with:
Crab crab = (Crab) getOneObjectAtOffset(0, 0, Crab.class);
if (crab != null) {
    int red = crab.getRed(); 
    .....
}

And in Crab:
public int getRed()
{
    return red;
}

This should start you in the right path. You will need a separate method for each parameter you wish to pass.
quelea quelea

2011/5/28

#
Thank you, that solved it!
You need to login to post a reply.