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  
  Map Storage Suggestions  (Read 2148 times)
0 Members and 1 Guest are viewing this topic.
Offline Vondre

Innocent Bystander





« Posted 2012-03-08 22:53:11 »

So I've lurked around here for a while, but the time has come for me to reveal myself and ask a question.

I'm currently developing a game with a 2D tiled map, similart to the 2D Final Fantasy games and their ilk.  I plan on handling tiled maps through instances of a Map class.

Here's a very simple overview of how I plan to handle the Map class:

1  
2  
3  
4  
5  
6  
7  
    private Image tileSet = null;
    private Image[][] tiles = null;
    private int[][] solidTiles;
    private int[][] eventTiles;
    private int[][] mapGroundLayer;
    private int[][] mapWallLayer;
    private int[][] mapOverheadLayer;


So each Map class has its own tileSet PNG and a 2D matrix of Images that serve as tiles for the map.

I plan to use five 2D integer matrices to handle collision, event activation, and draw order:
  • The solidTiles matrix is filled with 1s and 0s, where a 1 is a solid tile
  • The eventTiles matrix is filled with 0s, 1s, 2s, and 3s, where 0 is a tile with no attached event, 1 is a tile that activates an event upon entering the tile, 2 is a tile that activates an event when the player "interacts" with the tile, and 3 is a tile that has both "enter" and "interact" events.
  • The map____Layer matrices will be filled with integers that each correspond to an entry in the tiles[][] Image matrix.  The draw hierarchy is mapGroundLayer<mapWallLayer<entities on screen such as NPCs and the player<mapOverheadLayer

Now we get to my actual question: how should I store these matrices?  I'd rather not define a subclass of Map for every single map in my game; the only reasonable alternative I see is a text file, but that could get very cumbersome very fast, especially if I have maps with hundreds of tiles.

So! If you have suggestions, let me hear them!  And if you think my way of handling maps is ass-backwards for some reason, then tell me that, too!  I've never tried to make a game before, and I'm quite sure that my inexperience shows.

Thanks!

[Edited to explain the map____Layer matrices a bit better.]
[Edit 2: Obviously my Map class will have more variables/methods than what I put here; I just showed these because they're relevant to my question.]
Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #1 - Posted 2012-03-08 23:03:17 »

Now we get to my actual question: how should I store these matrices?  I'd rather not define a subclass of Map for every single map in my game; the only reasonable alternative I see is a text file, but that could get very cumbersome very fast, especially if I have maps with hundreds of tiles.

Consider either Mappy or Tiled.

They're both pretty ok. I usually end up writing something custom or using my own ( Analog ) but they're a good starting point.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline RylandAlmanza

Junior Member


Medals: 3



« Reply #2 - Posted 2012-03-08 23:20:07 »

I use tiled, and set it to save as a csv. Then I take all the csv layers and put it in my own map file format, because I don't need all the extra features tiled provides.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Geemili

Senior Member


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #3 - Posted 2012-03-08 23:22:33 »

Solid tiles are only going to be 0s and 1s? I pretty sure that a boolean type would be more efficient than integers.
Offline zngga
« Reply #4 - Posted 2012-03-08 23:46:58 »

I created a tiled map game a while ago, and I used a rather interesting method maybe you can make it work for you.

What I did is saved the map as an image. Mind you my maps only had to deal with height, and terrain type, so this was fairly simple. The general idea is that each tile represents one pixel on the image. The color range based on the tile's properties. For example, with my map height was represented in the pixel color as the alpha value. Then the terrain type (grass, water, sand, etc..) was represented as the actual color of the pixel. Then just make a loader that reads each pixel and builds the map accordingly. You can actually store quite a bit of information this way. RGB can easily represent at least 3 different attributes, then add in alpha, and you could even make each digit of each RGBA value represent different things, so without getting complicated you could save up to 12 attributes just in pixel color.

I hope this helps, and maybe sparks some ideas for you.

My code never has bugs... it just develops unexpected features!
Offline _Al3x

Senior Member


Medals: 7


Indie Games FTW!


« Reply #5 - Posted 2012-03-08 23:54:53 »

zngga that's very interesting indeed, what about save and load times? How does it scale on bigger maps? What about the final weight of the save file compared to say, other ways of resolving this issue? Smiley

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #6 - Posted 2012-03-09 00:07:03 »

Images based maps are ok for basic stuff (I've used them for 48-hour games before) but even though you can technically pack in a lot of information, I find that after about 7/8 different colours for different things it's really hard to remember what does what. And after that it gets awkward to tell the different pixel types apart.

Might be worth a try just to get something up and running, but IMHO you'll out grow it pretty quickly.

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline zngga
« Reply #7 - Posted 2012-03-09 00:25:45 »

zngga that's very interesting indeed, what about save and load times? How does it scale on bigger maps? What about the final weight of the save file compared to say, other ways of resolving this issue?

For me, with the largest of maps being a max of 999 x 999 tiles (each represented as a pixel) save and load times were about 2 - 3 seconds, but as it used the bufferedImage class you will get longer times as the size gets bigger. As I said before my max map size was 999 x 999 tiles, which translates to 999 x 999 pixel images (pretty large) not an ideal solution. One of the cool things about it though is you can open up paint and literally draw a map and your game will load it! Which was one of the reasons I did it this way. Compared to other methods, serialization obviously kicks-ass compared to this, txt files would be better as far as size is concerned. But I used this for the ability to draw maps, as I said earlier, it a very cool advantage over other methods.

My code never has bugs... it just develops unexpected features!
Offline 65K
« Reply #8 - Posted 2012-03-09 08:32:32 »

I use Tiled for visual part of the map. Object layers I find too cumbersome to handle.
I have a second game internal tile class layer made of booleans. Thus, each tile can get several attributes, like WALL, FLOOR, and for events something like DOOR, for example. Integers allow 32 attributes, Long for up to 64.
The initial class setup can easily be derived from the Tiled map (tiles 1 to x are floor tiles, 9-12 walls, etc.), later on bits for OPEN_DOOR or CLOSED_DOOR are set dynamically.
So, I don't need additional storage beside Tiled.

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 (38 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 (35 views)
2014-08-16 06:12:11

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

BurntPizza (48 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!