"RPG" - Level design

Hey everyone, Lately i have decided that I wanted to redo my “RPG” map class design because right now it just isnt really friendly enough to expand much, and am kind of getting lost on having each level hold all the data in a file (so the map editor i create will be able to create levels all on its own) I was thinking i would output all the info from the map editor into XML and then read it in the engine, would that be a workable method?

Also with that, I am kind of getting lost on Items and Enemies and was wondering if I am on the right track or if someone can help clear it up for me.

I was thinking I could have the user be able to add items in the map editor ( give its attributes like how powerful it is or w.e) and because my engine uses Rectangle collision I wouldnt need to read it in from a tilemap or anything so i could just output in XML the item type, value, etc?

But also, one thing is should I have a master list of all the items in the game (0- w.e) then load that into the map editor, then when the user clicks lets say item 1 (potion) the map editor will export item type to be 1, then the engine will call from a master item type arraylist, 1, Would i have a class that loads up all Items and then the engine calls it and asks it to return the item to its number, or should I have it so that when a user adds an Item to the map editor they need to specify the values and what not so that when the engine reads in the xml it can just create it on the fly? . I wouldnt want to have to load every single item in the game just for a certain level, so should each level just have a master list of items, enemies and "images’ that it will use?

Or opposite of that method should I just allow the user (its just going to be me using really so it doesnt have to be too friendly) to define object type, name, and position, then the engine will create an new Item of Type, so if it were a potion, it would create a new Potion with the name “name”, and the Potion class will use “name” to call a LUA file that will set up the potion specific Attributes, I really think this method would be best.

Sorry for the sloppy typing and if its not clear, im just really trying to straighten things out.

Help is appreciated!

You should definitely have your maps in text files. Xml is not that bad.

I think you should also have all your enemies and items in text files as well. Plain text works well here.

Have on property be the class to instanciate, find it by reflection and instanciate it. Use reflection to find the setters to apply all values to, like this:

    private static void setupObject(Object o, Node node) throws IllegalAccessException, InvocationTargetException {
        Method[] methods = o.getClass().getMethods();
        for (Method m : methods) {
            if (m.getName().startsWith("set")) {
                String att = m.getName().substring(3);
                if (node.getAttributes().containsKey(att)) {
                    Class paramType = m.getParameterTypes()[0];
                    Object param = null;
                    if (paramType == Float.class || paramType == float.class) {
                        param = node.getFloat(att);
                    } else if (paramType == Integer.class || paramType == int.class) {
                        param = node.getInt(att);
                    } else if (paramType == Boolean.class || paramType == boolean.class) {
                        param = node.getBoolean(att);
                    } else if (paramType == String.class) {
                        param = node.getString(att);
                    }
                    m.invoke(o, param);
                }
            }
        }
    }

Naming the setters and the values in the text-file the same is wise anyway. Now it is very easy to extend with more properties, and you will do it.

Im really sorry, thanks for the post and everything but honestly it flew right over my head :(…

What I have right now (ideas) is
have an xml file with map data (1,0,1,0,1, etc for the 2d array) then in the map editor i will be able to add an object layer that will allow me to place 1 type of items all around the map, and then it will output that into the xml for example

etc etc

Then when the data is read into the engine, it will create a new item object with the name “super potion” and that name string will call its matching lua script that will fill in its attributes.

I think it looks fine… except the lua part. Of course you could script all properties of all objects, but I think it is much more convenient to have them in text format. I use excel to keep track of all data of enemies and all items (I mean the blueprints, not where each enemy are on the map). Excel (or open office spreadsheet) can save to comma separated text. Comma separated text are very easy to read in java.

When you start the game or editor, read in this text file and parse it. For each item/enemy (row), make a hashmap with all its properties, including name. Put all these in a big hashmap with their names as the key. Have a class that manages the database. Now you can easily call the “database”: give me a “Healing potion 10” or “Brown bear” and it will return the correct object, set up and everything. Also, you can ask the database: “Give me the names of all the enemies”. These you can put in a dropdown in the editor.

This is very handy when scripting events in your game. A script can call the database, get five bears and one potion and place them anywhere on the map.

Also, if you use the method I wrote in the last post (but use an hashmap instead of a node), you don’t have to worry if you add more properties to items or enemies.

Ahhh thank you very much for clearing all of that up, I really appreciate it! Also I am assuming I should have that “database txt file” of items and what not be specific to each “level” otherwise I would be loading up every single item in the game when it wouldnt really be necessary correct?

Yes, but why not make that XML too? If you’re using XML for the map, why not XML for the item data? Item data seems like exactly what XML is intended for.

Game data doesn’t take up much space in the memory. Maybe the footprint of an items data is 1000 bytes (thats a lot of data). You can have 1000 items in that database before they take up one megabyte. And one megabyte isn’t much.

But keeping the items in separate files for organisation can be real nice.

And as Fletchergames say, you can use xml for this if you want (I personally don’t want to, but that’s just me).

yea thats what im thinking of, im thinking of havin all in one XML file, that way in the editor when you add an object you will give it its name, type and xml will print out the tags
<object type=“potion” name ="super potion>
<item1 posx posy etc etc

that way the engine will read in the object type, then create a Potion object with the name “super potion” that will call super potions lua file and set its attributes appropriately.

Thanks guys for all the help!

Ahh guys sorry there arent many updates, school has been beating me over the head. But I have some things I need clearing up, the loading of all the items and storing them into a hashmap should happen during maybe a loading screen or something right? Like in a seperate file and I could have the functions loadMap(), loadItems() etc that would load the necessary things from the file and store the items in the Master Item list?

Sorry once again I have a problem though, the Master Item List takes all the items I have currently “created” from a file and reads them in, stores them in a HashMap and then when i load the level one file which contains the name of the item i need and the location I want it at. So when I read in that file I read in lets say “potion” the master list is called and then returns the Item potion and then i use its setX and setY methods to set them to the specified locations. However because the master list is a hashmap of objects when I return them they return object refrences therefore impossible to have 2 different potions or anything, so I was wondering how I could fix that?

I was thinking of returning a clone but for some reason that method is unavailable… I was thinking about just getting the values for the Item and then creating a new one in the return method but with all the Items having different constructors it wouldnt work too well. Any advice?

To use clone your object must implement the Cloneable interface.

Another way to do it would be to have the master list only contain info thats shared by all instances of an object, like the name damage etc. Then have an object that hold a pointer to the master list object along with all the variables for an instance of the object, like the location, condition etc.