Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (491)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (556)
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 4869 times)
0 Members and 1 Guest are viewing this topic.
Offline Swattkidd7

Junior Member





« 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 Member





« 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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    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 Member





« 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 Member





« 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 Member





« 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 Member





« 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 Member





« 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 Member





« 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
</object>

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 Member





« 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 Member


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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Nickropheliac (15 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (29 views)
2014-08-22 19:31:30

atombrot (41 views)
2014-08-19 09:29:53

Tekkerue (39 views)
2014-08-16 06:45:27

Tekkerue (35 views)
2014-08-16 06:22:17

Tekkerue (25 views)
2014-08-16 06:20:21

Tekkerue (36 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (49 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!