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

2012/5/16

Creating a New World

theDoctor theDoctor

2012/5/16

#
I'm trying to make a game with different bulidings, and when you walk into a certain building, it moves you to a new World that looks like the inside of that buliding. Any ideas? It's an adventure based game, where you begin in a village and have to go into certain shops to buy items. I need to make it where when you intersect a Shop, it moves you to a different World that should be the inside of the Shop.
erdelf erdelf

2012/5/16

#
This creates a new World:
World shop1 = new Shop1();
Greenfoot.setWorld(shop1);
theDoctor theDoctor

2012/5/16

#
Oh! Ok, thanks! I'm new to programming, so I haven't really been introduced to much of that kind of thing yet. Thanks for the help.
theDoctor theDoctor

2012/5/16

#
One more thing, how do I move an Actor to a different World?
davmac davmac

2012/5/16

#
You remove it from the first world, and then you add it to the second world.
IsVarious IsVarious

2012/5/24

#
lol, in the constructor of the new level, set the location of where you want your actor to be added, think of this like you're working with your first level, but you can have many different. you can also setup conditions if they are met after leaving that building, where you want your actor to be placed. here's the same code we used for our final project which did this exact same thing.
// be sure to place this code in the main actor, as in it makes logical sense that he would be looking for a building.

private void checkForBuildingLevel()
{       // Warehouse.class is the name of the class we used for our building picture. 
        if ( canSee(Warehouse.class) ) 
            {
            Level1.enteredBuilding = true;
            Greenfoot.setWorld(new Level4());
            }
}
Our project started with a guy who crashed, and had to go to various levels to collect plane parts in order to fix his plane. Once he found them all, the plane was repaird and it then took off. It was pertty good if I do say so myself :P
You need to login to post a reply.