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

2020/4/10

how would i create an openable door

1
2
3
4
5
danpost danpost

2020/4/25

#
The only other thing you need in your Door class is a way for your player to "see" if it is open:
public boolean isOpen()
{
    return open;
}
Then, when touching door, you can determine whether you should be allowed to pass or not.
Weeb.exe Weeb.exe

2020/4/26

#
so was i right? if not what would it be because i don't have allowCollision code
danpost danpost

2020/4/26

#
You would need to restrict movement through the door -- basically something like:
if (isTouching(Door.class) && << trying to go through >>)
{
    Door door = (Door)getOneIntersectingObject(Door.class);
    if (door.isOpen()) << go through >>;
}
I cannot provide the missing parts.
Weeb.exe Weeb.exe

2020/4/27

#
ok thanks
Weeb.exe Weeb.exe

2020/4/27

#
ok so now i have created the code "allowCollision" it says
public boolean DoorClosed()
    {
        if (allowCollision()<<here it says "void type not allowed here">> == false)
        {
            int spriteWidth = getImage().getWidth();
            int xDistance = (int) (spriteWidth/2);

            Actor closeDoor = getOneObjectAtOffset (xDistance, 0, OpenableDoor.class);
            if (closeDoor == null)
            {
                return false;
            }
            else
            {
                stopByOpenableDoor(closeDoor);
                return true;
            }
        }
    }
how would i fix that this is the current code for "allowCollision"
public void allowCollision()
    {
        if (isTouching(OpenableDoor.class) && DoorClosed())
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                
               
            };
        }
    }
Weeb.exe Weeb.exe

2020/4/27

#
or would post above have to be boolean?
Weeb.exe Weeb.exe

2020/4/27

#
like this?
public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && DoorClosed())
        {

            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);

            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
                noAllowCollision(dontAllowCollision);
            }
        }
    }

    public void stopByOpenableDoor(Actor closeDoor)
    {
        int wallWidth = closeDoor.getImage().getWidth();
        int newX = closeDoor.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }
Weeb.exe Weeb.exe

2020/4/27

#
above i put the wrong code under the noAllowCollision statement its actually says this
    public void noAllowCollision(Actor dontAllowCollision)
    {
        int wallWidth = dontAllowCollision.getImage().getWidth();
        int newX = dontAllowCollision.getX() -(wallWidth + getImage().getWidth())/2;
        setLocation(newX , getY());
    }
so if that's right it says this at "return false; noAllowCollision(dontAllowCollision);"
cannot find symbol - variable dontAllowCollision
danpost danpost

2020/4/27

#
Weeb.exe wrote...
so if that's right it says this at "return false; noAllowCollision(dontAllowCollision);"
cannot find symbol - variable dontAllowCollision
Well, you shouldn't need a noAllowCollision method. Remove the method and the code after "return false;". Basically, what you want from act is (a) get direction to move; (b) if door not touched or not facing door or both facing door and door is open, then move; No code would be needed to "not move" (if you do not execute move code, actor will not move). So, this would be part of the movement code and the allowCollision method would not be needed either.
Weeb.exe Weeb.exe

2020/4/27

#
so remove allowCollision and add a movement code? how would i do this via code because there is another problem my code requires allow collision here
if (allowCollision() == false)
so how would i do it there?
Weeb.exe Weeb.exe

2020/4/27

#
public boolean allowCollision()
    {
        if (isTouching(OpenableDoor.class) && DoorClosed())
        {
            OpenableDoor door = (OpenableDoor)getOneIntersectingObject(OpenableDoor.class);
            if (door.isOpen())
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }//here it says missing return statement
how would i fix that?
danpost danpost

2020/4/27

#
Weeb.exe wrote...
so remove allowCollision and add a movement code? how would i do this via code because there is another problem my code requires allow collision here
if (allowCollision() == false)
so how would i do it there?
You do not need DoorClosed() -- just use isOpen().
Weeb.exe Weeb.exe

2020/4/27

#
danpost wrote...
Weeb.exe wrote...
so remove allowCollision and add a movement code? how would i do this via code because there is another problem my code requires allow collision here
if (allowCollision() == false)
so how would i do it there?
You do not need DoorClosed() -- just use isOpen().
where would i place that? because when i place it in the DoorClosed() code it just tells me that it cant find it because of the fact i think its in OpenableDoor class
danpost danpost

2020/4/27

#
Weeb.exe wrote...
where would i place that? because when i place it in the DoorClosed() code it just tells me that it cant find it because of the fact i think its in OpenableDoor class
Well, you do not need that OpenableDoor class either. Being open or closed is a state of the door that can described with a single boolean value.
Weeb.exe Weeb.exe

2020/4/27

#
the openable door class is where the door is itself also what would that boolean value be?
There are more replies on the next page.
1
2
3
4
5