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

2013/10/30

objects follow

13111876 13111876

2013/10/30

#
Hello all, I'm trying to get my objects follow an other object. Here is my code till now:
 public int weight;       // instance variable
    private int limit = 300;  //instance variable

public boolean isOverWeight()
    {
        List<Persoon> personen = (List<Persoon>)getIntersectingObjects(Persoon.class);   
        int currentWeight = 0;
        for (Persoon persoon : personen)
        {
            currentWeight += persoon.getWeight() ;

        }
        
        if (currentWeight >= 49)
        {
            setLocation (getX(), getY() +1);
            //setLocation (List<Persoon>)getIntersectingObjects(Persoon.class) (getX() getY() +5);
        }
        return currentWeight > 300;
        
    }
In this code I let the objects follow 'Boot'. The 'Boot' keeps track of how much weight there is in 'Boot' and who is intersecting him. I want 'Boot' to sink a every time an objects intersects him. Help please.
You need to login to post a reply.