Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (686)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  "RPG" - Level design  (Read 5609 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Posted 2009-02-13 00:44:45 »

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!
Offline markus.borbely

Junior Devvie

« Reply #1 - Posted 2009-02-16 05:35:50 »

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.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #2 - Posted 2009-02-17 23:42:09 »

Im really sorry, thanks for the post and everything but honestly it flew right over my head Sad...

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

<object type = "potion" name="super potion">
  <item posx = 0, posy = 0> 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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline markus.borbely

Junior Devvie

« Reply #3 - Posted 2009-02-19 14:25:29 »

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.
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #4 - Posted 2009-02-20 01:23:32 »

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?
Offline fletchergames

Senior Devvie

« Reply #5 - Posted 2009-02-20 04:44:57 »

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.
Offline markus.borbely

Junior Devvie

« Reply #6 - Posted 2009-02-20 10:06:53 »

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?

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).
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #7 - Posted 2009-02-21 02:52:00 »

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.

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!
Offline Swattkidd7

Junior Devvie

Exp: 8 years

« Reply #8 - Posted 2009-03-05 23:19:18 »

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?
Offline zoto

Senior Devvie

Medals: 4

« Reply #9 - Posted 2009-03-14 15:21:44 »

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.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Dwinin (63 views)
2015-11-07 13:29:08

Rems19 (77 views)
2015-10-31 01:36:56

Rems19 (69 views)
2015-10-31 01:32:37

williamwoles (103 views)
2015-10-23 10:42:59

williamwoles (91 views)
2015-10-23 10:42:45

Jervac_ (105 views)
2015-10-18 23:29:12

DarkCart (132 views)
2015-10-16 00:58:11

KaiHH (114 views)
2015-10-11 14:10:14

KaiHH (153 views)
2015-10-11 13:26:18

BurntPizza (167 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!