RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
Strukain
Lowly Slime


Joined: 08 Feb 2004
Posts: 3
Location: behind the moon (in germany)

PostPosted: Mon Feb 09, 2004 8:30 pm    Post subject: More Maps [quote]

Hi,
I've seen in every RPG, that the worlds are bigger than one map. But how did people this programmed? How can I save maps in other files, but could bring interactivity on the map (for example doors and stairs to other maps, people who you can talk with and so on...)?
I won't write extra code for every map in the game. How did the other programmers make this?
Back to top  
white_door
Icemonkey


Joined: 30 May 2002
Posts: 243
Location: New Zealand

PostPosted: Mon Feb 09, 2004 9:33 pm    Post subject: [quote]

There are several ways of doing these things.

Maybe the easiest way is to mark special points or areas of interest on your map and include data about how to deal with them. this might include a string with the name of the new map to change to, and location... or some dialog between the character and npc. or anything else you can think of. You can also use flags to help decide what is required for the event to activate.. like maybe 1 = walk here, 2 = look at this point and push button, 4 = push the button and have some item.. or whatever.

Another way I have seen it done is to use event numbers.. like assign a number to each area of interest on the map.. And then in your code, have a large switch where you code each event in your engine. It might be the easiest way of programming events and such.. but I it could be quite annoying in terms of every small change requiring a recompile of the code.

A more advanced way of doing the same thing is to include a scripting language or some from of interpreted code that you can make for each event that happens... This reduces the need for recompiling your project and makes it easier to modify areas of the game. It can make debugging more complex though. ;)
Back to top  
ThousandKnives
Wandering Minstrel


Joined: 17 May 2003
Posts: 147
Location: Boston

PostPosted: Mon Feb 09, 2004 10:06 pm    Post subject: [quote]

Quote:
Another way I have seen it done is to use event numbers.. like assign a number to each area of interest on the map.. And then in your code, have a large switch where you code each event in your engine. It might be the easiest way of programming events and such.. but I it could be quite annoying in terms of every small change requiring a recompile of the code.

Switches work if you are programming a very small, simple game. I programmed a few text-based DOS games that worked like that. It is the simplest way to make games, UP TO A POINT. Beyond that point, it becomes ridiculously laborious and confusing.

Each map in my game is split into two files.
-One is a binary file storing all the tile data. There are 3 segments to these files: tile, overlay, and encounter zone data. Obviously the last only applies because I am making a random-encounter game.
-The second is an XML file with object information. The format is basically this:
Code:

<map>
    <name>My Map</name>
    <object>
        <pos>
            <x>5</x>
            <y>5</y>
        </pos>
        <activation>talk</activation>
        <icon>generic_guy</icon>
        <movement>random</movement>
        <script>
            <event>
                <type>inn</type>
                <order>1</order>
                <cost>100</cost>
            </event>
        </script>
    </object>
</map>

You get the idea. The advantage to using XML is if you know any PHP/ASP/etc you can easily write an editor/evaluator for it, and values that arent used or are left as their default values dont need to be saved or loaded.

I'm not the best programmer in the world, I know a lot of other people around here have very, very feature-rich scripting engines. All you really need though is to give your self the right sized blocks that you feel comfortable building a game with. I only have 27 types of events, although some have a lot more variables than others. I never find myself wanting for more though.

Anyway the list of map files is saved in a seperate file. Changes from map to map are called by a "warp" event. If the warp event specifies a map ID value different from the map currently loaded, it saves the object that called the warp to a special data item and disposes of the current map, replacing it with the new map data. The object that was running and was saved continues running as a special state within the new map.
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Mon Feb 09, 2004 11:12 pm    Post subject: [quote]

In our engine, while characters walk on the map, their position is checked against all other objects on the map. When a character is standing on another object, a function is called on this object telling it who is standing on it. This object can then take action.

If the object is a portal, it will call the LoadMap function defined in the engine. In previous versions of our engine, there was always 1 active map. When a new map was loaded, the engine would forget all about the previous one. In Cave Adventure, this meant all spiders came back when you return to a certain area.

With BBRpg, we adapted the engine to be able to load multiple maps at a time and we're loading them all at the start. Then, the portals just need to move the player from one map to another and have the camera follow him there.

What it comes down to, I think, is that you can view the map as an object containing the tile data and all the objects present on the map. You can then easily have multiple map objects and move objects from one map to another. Maybe your problem is that you're thinking in terms of global variables, instead of containing the information inside objects?
Back to top  
Strukain
Lowly Slime


Joined: 08 Feb 2004
Posts: 3
Location: behind the moon (in germany)

PostPosted: Tue Feb 10, 2004 5:29 pm    Post subject: [quote]

The idea with the two files is a good idea, because I use a map format with only the tiles. A can't bring any things like areas in it, only objects like medi-drinks or swords and so on. The other way is, to programm a new Editor for the maps.
My engne is allegro and do only the graphics for me. The rest I have to programming myself.
Do somebody know a small and fast XML-Parser for GNU-C++, I wont programm it not myself, too.
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Wed Feb 11, 2004 12:33 pm    Post subject: [quote]

There is libxml and libxslt, but I've never used them so I don't know if they're comfortable to work with. The tree API seems nice. Hmm, you probably don't need libxslt unless you are going to ravamp your data structure and decide to write an XSLT file to transform your old stuff to the new format. You could do so with xsltproc. :-)

The main point about adding a text file together with the file containing tile data is that you don't have to make an editor for it, which can be rather tedious especially when it comes to placing and configuring objects and events, and it will be likely be too limited even when you put a lot of effort in it. XML as a format is good because it allows the file to be both easily editable by hand and safeable by an editor. We embedded Lua in our engine and the second file is effectively the script that adds the more complex or event driven objects to the map, while most decoration can be added with the editor. This means object data is effectively stored in two ways, in the binary map file and by spawning objects in the script.

Fast and easy is the following, though the disadvantages are obvious:
Code:
name,My map
obj,5,5,talk,generic_guy,random
event,inn,1,100
obj,4,5,nothing,table,static

The file doesn't explain itself, it's not particularly good for nested data structures and adding new properties can be tedious. It's close to what our first scripting language looked like when we were using QB. Hence the commas because QB would parse them automatically. :-)
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum