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

2018/1/7

Creating a door into next level

Echarch11 Echarch11

2018/1/7

#
Hello, I am trying to create an instance where after my character collects all of the keys placed on the screen it can enter a door which when the character touches the door will take them to level 2.
danpost danpost

2018/1/7

#
Echarch11 wrote...
I am trying to create an instance where after my character collects all of the keys placed on the screen it can enter a door which when the character touches the door will take them to level 2.
What have you tried? What codes are you trying to use for the character and the door?
xbLank xbLank

2018/1/7

#
In your Door Class something like:
public class Door extends Actor
{
    public void act()
	{
		if(getOneIntersectingObject(Character.class) && getWorld().getObjects(Key.class).isEmpty())
		{
			Level2 world = new Level2();
			Greenfoot.setWorld(world);
		}
	}
}
Echarch11 Echarch11

2018/1/7

#
It says that it doesn't compile because the first type is a greenfoot.Actor and the second type is a boolean
xbLank xbLank

2018/1/7

#
My bad. I'm tired.
if(getOneIntersectingObject(Character.class)!= null && getWorld().getObjects(Key.class).isEmpty())
Yehuda Yehuda

2018/1/8

#
The following code is the same as 일리아스 just simpler/shorter.
public class Door extends Actor {
    public void act() {
        if (isTouching(Character.class) && getWorld().getObjects(Key.class).isEmpty())
            Greenfoot.setWorld(new Level2());
    }
}
Tyleroneil72 Tyleroneil72

2018/1/8

#
일리아스 wrote...
My bad. I'm tired.
if(getOneIntersectingObject(Character.class)!= null && getWorld().getObjects(Key.class).isEmpty())
Please source my code. I made this.
xbLank xbLank

2018/1/8

#
I didn't copy that, therefor I cant give any source.
Tyleroneil72 Tyleroneil72

2018/1/8

#
일리아스 wrote...
I didn't copy that, therefor I cant give any source.
No I made it myself, you thief. im banning you, my dad is greenfoot.
Tyleroneil72 Tyleroneil72

2018/1/8

#
일리아스 wrote...
I didn't copy that, therefor I cant give any source.
System.exit(0);
You need to login to post a reply.