Subscribe to A Programmer's Casual Blog        RSS Feed
-----

Tossing arround ideas for a map system for a simple 2D tile based game

Icon Leave Comment
I'm thinking about building a game to help me with a novel I'm writing (lol, it sounds weird to me too). One of the first things you need to develop before you can start working on the game is coming up with a map system. You need a way to serialize an environment for your character to exist in... You need to be able to put the pretty pictures on the screen where you can walk (and where you can't walk).

I recently have been studying (staring blankly at) matrices. Then I realized, why don't I go back to working on my first game (this is literally how my mind works... I've got other stuff I'm working on... but sometimes I need a break and I just got finished with doing some serious home repair stuff).

Anyway, the mapping system will be a flat file... or an XML file. Either way, something a mapper can work on by hand, with out the assistance of a stupid tool (no offense to stupid tools of course ;) ).

So let me past some thoughts I had a very long time ago if I can find them.

*    // Preliminary notes:  The objective is to be able to draw this http://vgmaps.com/Atlas/SuperNES/LegendOfZelda-ALinkToThePast-LightWorld.png
             *    // Based on the bits stored in the XML file...  that map is actually composit of several levels (they're all square!)
             *    // anyway...
             *    // It should be able to draw a tree, begining at a certain point, and prevent anything else (wierd) being drawn in the tiles around it...
             *    // But items can be placed there, they just aren't drawn, they fall from the tree when you charge into it.  
             *    // 
             *    // It should be able to draw the shrubs (they would be the style predetermined by the floor type they're placed on
             *    // It would draw fences...
             * 
             * Map File format (XML)                    //  http://vgmaps.com/Atlas/SuperNES/LegendOfZelda-ALinkToThePast-LightWorld.png
             * <Map>
             * <FloorPlan details="This node sets up the shape of the map... the shape of the tiles... this should be row by row" 
             * LevelSize="12x4"      // this sets up the dimension of the room...  how far the camera can possibly see; where the camera stops
             *                       // If it's smaller than the screen size, then the room is centered... surrounded by black (think zelda)
             * 
             * FloorSize="12x4"      // This indicates the dimensions of the room's walkable area (not the screen...)
             * 
             * FloorReferenceToLevel="0,0"  //the upper right corner of screen...  This thing tells where you insert the floorplan (in reference to the level dimensions or rather the screen dimensions)
             * 
             * FloorPlan="000022220000       // this floorplan would indicate a hallway.  
             *            000000000000       // You can walk where there are 1s or 2s, but 2s are a higher ground!
             *            000011110000       // There might be tiles drawn on 0s though, mind you!  This only explains where you can walk
             *            000011110000"      // if there is a 2 next to a 1, it is a straight drop down, and there is no cliff...  
             *                                
             *                               // Edge tiles are automatically used on the edges (where numbers touch 1s).  
             *            
             *                               // just a random sample shot http://static2.videogamer.com/videogamer/images/gc/zelda_four_swords/screens/zelda_four_swords_3.jpg
             * 
             * FloorTypeV="0000AAAA0000       // This let's you specify what types of floor are on the ground... visually (FLOOR ONLY, WALLS ARE SEMI-AUTOMATICALLY DRAWN)
             *             000000000000       // Only mark walkable area, everything else is auto determined by game (the edges of cliffs and what not)
             *             0000AAAA0000       // The hight is automatically accounted for...  A = dungeon floor
             *             0000AAAA0000"      //  1 = NOTHING, RESERVE THIS FOR FloorCliff
             * 
             * 
             * FloorTypeQ="000011110000       // this lets you specify the quality of the floor (icy, sandy-slow, normal) the way it affects movement
             *             000000000000
             *             000011110000       // 1 = normal floor
             *             000011110000"
             * 
             * FloorCliff="000011110000       // this is optional, it lets you specify specific clifftypes...
             *             000000000000       // I.E. you can specify an abyse (no cliff) or a cliff that is sandy instead of default
             *             000000000000       // 1 = default (what ever it says in FloorTypeV);  2 = Floor_tile_#1
             *             000000000000"      // So, if zeros are placed on walkable tiles, then they will have NO CLIFFs drawn at all
             *             
             * FloorContents="00 00 00 00 00 00 00 00 00 00 00 00              // This is actually rendered in hex... like everything else? (everything else might be binary, idk)  That gives us 
             *                00 00 22 00 00 00 00 00 00 00 00 00              // if it's a 00000100 at position 1, then a lamp is drawn there (and exists there)
             *                00 00 00 22 00 00 00 00 00 00 00 00              // if it's a 01110001 at position 1, then it's a boomerang that is drawn there (and exists there)... the second item in the game
             *                00 00 00 00 22 00 00 00 00 00 00 00              // if it's a 00010110 at position 1, 2, 3, and 4, then the proper fencing tiles would be drawn there (and the floor would be rendered non-walkable by the interpreter).  
             *                                                                 // This fencing stuff is tricky because you need to handle diaginals too... so  if (pos15 == 00010110) then 
             *                                                                               // CreateFencingChainTest(pos15) ... 
             *                                                                               //     UsingMiddlePointAlgo  // after testing if pos15 is on an edge of grid
             *                                                                               //        { TestForFence(Pos15+1)  ... and if 00010110, then 
             *                                                                               //              ...{ if (pos16 == 00010110)  
             *                                                                               //                       Fence(15).right = ConnectsToFence;
             *                                                                               //                       
             *                                                                               //                   if (pos15+rowLength-1 == 00010110) 
             *                                                                               //                       Fence(15).leftLowerDiag = ConnectsToFence; ....hmmm... this sux...
             *                                                                               //         
             * 
             * FloorMonsters="00 00 00 00 00 00 00 00 00 00 00 00              // this let's you set up the placement of mobs when the level loads.  
             *                00 00 00 00 00 00 00 00 00 00 00 00              // mobs are special kinds of object that can roam around.  When you leave the floor, the position of the mobs is stored in memory, so they're right where you left them when you come back.                           
             *                00 00 00 00 00 00 00 00 00 00 00 00              // 
             *                00 00 00 00 00 00 00 00 00 00 00 00
             *             
             * 
             * 
             * CeilingPlan="000000000000       // This lets you draw the ceiling like you can see in FF3!  
             *              000000000000       // I'm not sure how to implement it at this point...
             *              000011110000       // But anyway, it allows you to draw archways that your character can walk through
             *              000000000000"      
             * 
             * CeilingImage=...                // Hey, you know how you can have a graphics layer that scrolls at a different rate as the terrain scrolls?  This does that...
             *                                 // ...I have a feeling that the best way to pull this off is to just link to the image you want...
             * 
             * 
             * 
             * 
             * <A1
             * 
             * 
             * */



I think that's an interesting approach. But look at the way I was using string variables... I don't think I realized I could use a 2D array to make a matrix for the floor plans, lol. Well, now that I think about it, each MAP should consist of 3 equal sized matrices:
1) Background Tile (two types of tiles, walkable, and non-walkable, & elevations...)
2) Monster/Item Starting locations
3) Moveable Object Locations (check the graveyard)

or perhaps I should have a 32 bit int array that allows me to map each tile...

map[x,y] = 0xAA BB CC
where AA = background tile
BB = Monster/item locations
CC = Movable object locations

So if map[0,0] = 0x120124, then that would mean that the tile at location (0,0) contains a background tile image number 12, the item defined as item 01, and the movable object number 24... I kinda like this approach, but defining the map like this is a LOT less intuitive.



<MapData>
  <TileDefinitions>
    <Geographics>
      <Terrain number=00 id="path01">
      <Terrain number=01 id="GreenGrass01">
      ...
    </Geographics>
    <Monsters>
      <Monster number=01 id="redKnightGuy"/>
      ...
    </Monsters>
  </TileDefinitions>

  <Dungeon name="dungeon01">
    <floor number=1 dimensions="20x10">
      <terrainLayout>
        //Array Goes Here
        
        20 20 20 20 20 20 20 20 20 05 05 20 20 20 20 20 20 20 20 20
        00 00 00 00 00 00 00 00 00 01 01 00 00 00 00 00 00 00 00 00
        00...
        00...
        00...
        00...
        00...
        00...
        00...
        00...

      </terrainLayout>
      <monsterLayout>
        ArrayGoesHere...
      </monsterLayout> 
    </floor>
  </Dungeon>

</MapData>




Hmmm... I like it. It's catchy. My first thought is, of course, "OK, how do I program one of those stupid tools to fill this out for me" but alas, having a sound, and well thought out "binary" map format is what I would consider to be the most crucial first step of any open source game engine with the intent of lowering the learning curve on entering the game industry (cause games nowadays SUCK and we need more competition out there :gunsmilie: ).

1) I guess the next step is to write one of these xml map files by hand, and then get my C# application to load it up...

2) Then after that I will have to get my engine to associate the id names with actual tile images and "unit objects"...
2a) I will eventually need to devise a simple "unit object" definition. I think I have something that does this in a VB source on my hdd.

3) After associations are made, I will finally need to place the "game content" on the screen where it belongs. I will start out by making it just place the whole 20x10 dungeon floor on the screen. It won't even have a starting location for a hero yet.

4) Then I will need to create that hero. Make it so he can move around.

5) As an aside, I will delegate the duty of Hero programming to one of my team mates.

6) Then I will need to make doors lead to other dungeons (great, I have to hand draw another dungeon xml node).

6) After that I will need to make a mini-map routine...

7) Finally, I will have completed developement on the map portion of the game engine. Perhaps I will deligate the optimizers to write an routine that converts the inefficient xml data into a single, razor sharp binary data array.

Well... this will never happen, lol. I better get back to work.

0 Comments On This Entry

 

Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

August 2018

S M T W T F S
   1234
567891011
121314151617 18
19202122232425
262728293031 

Tags

    Recent Comments

    Search My Blog

    0 user(s) viewing

    0 Guests
    0 member(s)
    0 anonymous member(s)

    Categories