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

2014/7/30

adding level missions

davemib123 davemib123

2014/7/30

#
how would I go about adding missions to a level / map? For example, can not exit the map unless a key item is picked up. My game is located here: http://www.greenfoot.org/scenarios/11862
danpost danpost

2014/7/30

#
You need to make the source available (check the 'Publish source code' checkbox when uploading).
davemib123 davemib123

2014/7/30

#
try now.
danpost danpost

2014/7/30

#
Basically, however, create a class for a 'door' (exit) object that creates a 'key' (picked up item) object. Add a 'get' method to retrieve the key so you can add it into the world where you want, and another method to get the usability of the exit. That is, something like this
public class Door extends Actor
{
    private Actor key; // to hold the key that opens the door

    // creates the key that opens the door
    public Door()
    {
        key = new Key();
    }

    // gets the key that opens the door
    public Actor getKey()
    {
        return key;
    }

    // the door is unlocked when the key is removed from the world
    public boolean isLocked()
    {
        return key.getWorld() != null;
    }
}
Then, when adding the door into the world (from your world class):
Door door = new Door();
addObject(door, /* location of door */);
addObject(door.getKey(), /* location of key */);
It does not have to be a door and a key; although, the exit and the item picked up would be synonymous with them.
davemib123 davemib123

2014/7/30

#
cool, i'll try it out and get back if i need more assistance.
You need to login to post a reply.