I was wondering what would be the most efficient way to make a map in 2D for a java game?
I know this does depend on the way the开发者_JS百科 game will be seen and made so I have included info about this.
View: From Top of Player
Game Type: 2D Shooter
The game cam will focus on the player.
I am going to create my own "map maker", but was wondering if it should be stored in xml or something. Not exactly sure how to go about this. Are there any good books on this? I was reading 'killer java games', but it did not cover this particular topic very well for what I was trying to do.
Now to show you I have been thinking...
I was thinking that the best way would be .xml
Here is an example:
e = entrance / exit
b = block
. = open space
<?xml version="1.0" encoding="UTF-8"?>
<info>
<name>Crack House</name>
<date>9:49PM 5/8/2011</date>
<level>Easy</level>
<rows>10</rows>
<colums>7</colums>
</info>
<map>
<row1>bbbebbb</row1>
<row2>b.....b</row2>
<row3>b..bbbb</row3>
<row4>b.bb..b</row4>
<row5>b.....b</row5>
<row6>b..b..b</row6>
<row7>b..b..b</row7>
<row8>b..bbbb</row8>
<row9>b.....b</row9>
<row10>bbbbbbb</row10>
</map>
It depends on what kind of efficiency is most important to you:
- efficient loading of maps (time taken),
- efficient storage of maps (space utilization),
- efficient use of developer time.
It also depends on your developer skills, and other characteristics of the problem that you have not outlined.
But the bottom line is that your best strategy is probably to just implement it the simple way to start with, and worry about efficiency later ... if it turns out to be a REAL problem.
One piece of advice. Try to design / structure your software so that you can change the way that the maps are stored without too much effort.
XML would be easy to parse and work with, and it should be easy to make changes to if you needed to add more information to it later. However it would take up more disk space, and could potentially be slower to parse it when loading a map initially.
Some form of custom binary map format would take up less space on disk and could be faster to parse, but it would not be as flexible if you need to change the format later on.
Edit: If you plan on having a really large number of maps or a lot of them you may not want to use XML to save space. If you need maps to load in really short amount of time, you may not want to use XML to save time loading. If you want a map format that is easier to change later on and would be easy to modify by hand, XML may be better. It might also be easier to implement the XML map format. Overall its up to you, though I'd say go with whatever is easier/faster for you to implement and switch later if you feel its necessary.
I used for a 2D strategy game a simple plain text file. The file looks like this:
00000000000
00111111100
00111111100
00222222200
00111221100
00000000000
0 = blocked tile
1 = grass tile
2 = road tile
I think that is a really compact methode. My parser implementation works really fast and after parsing i get a 2-dimensional Array -> tile[colum][row]
精彩评论