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

2013/11/22

How to make my Container edges like walls

JasonZhu JasonZhu

2013/11/22

#
    public Container()
    {
        GreenfootImage img = new GreenfootImage(100,200);
        img.drawRect(0,0,99,199);
        setImage(img);
        counter = 0;
    }
    public WaterWorld()
    {    
        super(800, 600, 1);
        addObject(new Paddle(),100,getHeight()-100);
        addObject(new Container(),530,460);
        int counter = 0;
    }
These are the coordinates of my container, but how to I write a method that checks for the walls of my container? Do I write a Boolean that returns coordinates?
danpost danpost

2013/11/22

#
You should be able to use one of the Actor classes collision checking methods ('getOneIntersectingObject(Container.class)' or one of the others) to determine when your actor makes contact with an edge of the container (at least, from outside the container).
JasonZhu JasonZhu

2013/11/22

#
Would I be using getOneObjectAtOffset? If so, I'm still confused as to go about writing this. Would I return those specific x and y values that correspond to a wall and writing and if statement so that if my object touches those values to make it do as I wish?
danpost danpost

2013/11/22

#
What method you choose to use usually depends on how close you will allow your objects to get. I presume that you do not want your actor to overlap the container object at all, which would indicate you probably want to use the 'getOneIntersectingObject' method (this method will return true as soon as the images of the two objects intersect). The 'getOneObjectAtOffset' method when using (0, 0) as offset values will return true if the image of the other object intersects the center of the image of the actor; which means half the actor image will have been passed into the other image before it returns true.
JasonZhu JasonZhu

2013/11/22

#
Yes, but by doing so, the top of the container where I plan on having drops that can only enter through there would be affected. What do you suggest?
JasonZhu JasonZhu

2013/11/22

#
Should I make the walls separate objects
danpost danpost

2013/11/22

#
Add a Boolean to indicate whether it is being entered or not and qualify everything with it.
DanPostV2 DanPostV2

2013/11/24

#
hey
You need to login to post a reply.