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

2014/5/5

I need help!

jmdreyer jmdreyer

2014/5/5

#
When one of my objects eats another, the image is off based on the position of where the object eats the other object. So, half of the image that is supposed to be eating the other object will just pass through it harmlessly. What should I do? Here is the code.
  public void act() 
    {
        lookForMarble();
        checkForEdge();
        getWorld();
    }
    public void checkForEdge()
    {
        if (atWorldEdge() )
        {
            getWorld().removeObject(this);
        }
        else
        {
            setLocation(getX(), getY() - 5);
        }
    }
    public boolean atWorldEdge()
    {
        if(getX() < 20 || getX() > getWorld().getWidth() - 20)
            return true;
        if(getY() < 20 || getY() > getWorld().getHeight() - 20)
            return true;
        else
            return false;
    }
        public boolean canSee(Class clss)
    {
        Actor actor = getOneObjectAtOffset(65, 0, clss);
        return actor != null;  
        //Coding from "Little Crab"
    }
     public void eat(Class clss)
    {
        Actor actor = getOneObjectAtOffset(65, 0, clss);
        if(actor != null) {
            getWorld().removeObject(actor);
        }
    }
         public void lookForMarble()   
    {   
        if ( canSee(Marble.class) )
        {
            eat (Marble.class);
            //Coding from "Little Crab"
            Greenfoot.stop();
        }
    }
}
danpost danpost

2014/5/5

#
You are explaining what you do not want; but, you did not really say what you wanted. Do you want it so that any overlap of the images the marble should disappear? or, do you want it so that if the marble intersects the center of the actor, it should disappear? or, do you want it so that if the marble comes within a specific range of the center of the actor, it should disappear? or, what?
jmdreyer jmdreyer

2014/5/7

#
I want is so that right when the two images overlap one another one of the objects gets eaten
jmdreyer jmdreyer

2014/5/7

#
Sorry I wasn't very clear
danpost danpost

2014/5/7

#
Try changing lines 29 and 35 to this:
Actor actor = getOneIntersectingObject(clss);
You need to login to post a reply.