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

2013/11/7

How to write code for objects intersecting at the center point

JasonZhu JasonZhu

2013/11/7

#
    private void checkHome()
    {
        AntHill home = (AntHill)getOneIntersectingObject(AntHill.class);
        if (home != null && !canCarryFood){
            this.setImage("ant.gif");
            canCarryFood = true;
            getHomeHill().countFood();
        }        
    }
I have this code in my Ant class however, when the Ant touches the Anthill in any sort of manner, it drops the food off. This is unrealistic as the ant never even reaches the center of the hill. How would I write code to check intersection at the center point of the hill? Thanks for the help!
danpost danpost

2013/11/7

#
When getX() returns the value of home.getX() then it is at the horizontal center. You can now figure out the vertical center, if needed.
JasonZhu JasonZhu

2013/11/7

#
How would I write that if I did found out?
You need to login to post a reply.