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

2013/6/21

TWO independent parts in ONE world:possible? important!!!!!

pigletisland pigletisland

2013/6/21

#
We have to write a game for computer science lessons in school. It's a multiplayer game and our problem is the following: the world moves depending on the position of the actor and because we have two independent actors, we want to have two independent "worlds", so that every actor has his own part of the world in which he acts and which moves depending on his position. Can anyone help us? We are really desperate and we don't know whether it is possible or not. If you have any idea, we would be grateful if you answer, as soon as possible. thank you in anticipation
I'm pretty sure you can't display two worlds on one Greenfoot screen, unless you modify the source code of greenfoot...
danpost danpost

2013/6/21

#
Maybe my PIP Actor Class can be used for this. PIP stands for picture-in-picture and is an actor class whose instances are actual running worlds. And I do not see any problems with using multiple instances of the same world for different PIP objects (or even the same world for multiple PIP instances).
pigletisland pigletisland

2013/6/21

#
Thank you were much!!! If I am able to understand your programm, it will help me!!! Thank you for your effort :)
pigletisland pigletisland

2013/7/1

#
Your programm did help me, but know we have another problem: We want to have several levels and the actors should be able to go into a new level at different time (in the minor wolrds). Do you have an idea, how this could work or it is even possible?
danpost danpost

2013/7/1

#
You could add the following method to the PIP actor class code:
public void setMinor(World minorWorld, Class[] classes)
{
    minor = minorWorld;
    paintOrder = classes;
    updateImage();
}
You can use it to change the world that the PIP object displays. As an alternative, you could just remove the old PIP object and create and add a new one for the new 'world' level.
pigletisland pigletisland

2013/7/2

#
Just one more question: How can I use your method to change levels after adding your method to the PIP actor class?
Just have a spot in the game that tells the PIP actor to change to the next level. If they've reached a specific coordinate, or if they are intersecting a checkpoint or whatever. Have a method in your actor that will allow other objects to change to the next level. You could do this in two ways:
  • Have a method that accepts a world, then change to that world.
  • Have a method that accepts nothing, and inside your actor class keep track of which level it is (through an int) and when that method is called, increase that int by 1, then from an array of worlds (doesn't have to be in the actor class) it determines witch one is next based off your level counter.
Somewhere you're going to have to keep track of where you're worlds are. I recommend the second option if you want to keep track of the worlds in your actor class. If you have a different class that keeps track of everything for you (my first couple games have a GameStats class that does this) you could then use the first method.
danpost danpost

2013/7/2

#
You would create your new world (or level), as normal, then change the world that the pip object displays by calling the method provided on the pip object:
// using 'pip' for the reference to the pip object
// create the new level world
Level level = new Level();
// create a paint order list
Class[] classes = { /* list of classes here */ };
// set the new world for the pip object
pip.setMinor(level, classes);
You need to login to post a reply.