Re: [pygame] map format
On 12/19/06, Greg Ewing [EMAIL PROTECTED] wrote: Farai Aschwanden wrote: I wanted to use such a system too, but 2 points stopped me using it: 1. Its restricted to the charset (well 256 chars is quite a lot) Unicode! Then you can use the Chinese characters for water, grass, hill, etc. Much more readable. :-) Not that I enjoy being a chinese grammer nazi, but of course there are 3 unicode characters needed for 'hill' - xiao, shan and po. -- Science is open source religion
Re: [pygame] map format
Farai Aschwanden wrote: I wanted to use such a system too, but 2 points stopped me using it: 1. Its restricted to the charset (well 256 chars is quite a lot) Unicode! Then you can use the Chinese characters for water, grass, hill, etc. Much more readable. :-) -- Greg Ewing, Computer Science Dept, +--+ University of Canterbury, | Carpe post meridiem! | Christchurch, New Zealand | (I'm not a morning person.) | [EMAIL PROTECTED] +--+
Re: [pygame] map format
I generally make the map file as simple to read and change in a text editor as I can. This generally makes the python code to parse the file a bit more complex, but since this is done only once at start-up I don't notice any speed issues. Another way of doing it is to write a simple map loader that then pickles the data structure and saves it, and then in your game, load the pickle file. On 12/17/06, spotter . [EMAIL PROTECTED] wrote: Thanks, I just wanted to make it fast because if I start loading the map at the beginning, it might seem to take a while before the game starts due to parsing and caching. Probably just my computer though, its a bit low on ram :( On 12/17/06, Ethan Glasser-Camp [EMAIL PROTECTED] wrote: spotter . wrote: Hey everybody, I am in the process of trying to make a file format for maps. The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. I think that unless you're going to be opening/reading map files all the time -- numerous times per frame? -- the performance differential is likely to be negligible. Get it working, then get it fast. If loading maps does turn out to be slow, perhaps you can cache them once loaded. I do something like this with image files, storing the images as .png with information like colorkey in a seperate file. Since I'm caching images anyhow, performance doesn't suffer much. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? I typically try to write my maps as pure Python that call game engine functions. For instance, I've been toying with something like this: setMap(''' 0 1 0''') setTerrain(0, passable=True, tile=grass) setTerrain(1, passable=False, tile=forest) Of course, the last two times I tried to write a tile-based RPG I got nowhere fast and gave up, so maybe you shouldn't take my advice. :) The map format I describe above is inspired by looking at some Wesnoth maps, which look like a huge block of letters, with some other meta information stored in a seperate file. Ethan -- Science is open source religion
Re: [pygame] map format
On 12/18/06, Chris Smith [EMAIL PROTECTED] wrote: I generally make the map file as simple to read and change in a text editor as I can. This generally makes the python code to parse the file a bit more complex, but since this is done only once at start-up I don't notice any speed issues. Another way of doing it is to write a simple map loader that then pickles the data structure and saves it, and then in your game, load the pickle file. Pickling sounds awesome, looking at some tutorials on the web. It would be a good choice if the editor was made in python, and it could be pickled. Text just makes it simpler to start, but pickling would probably be faster in the end. Thanks, -spot
Re: [pygame] map format
On Tuesday 19 December 2006 04:41, spotter . wrote: On 12/18/06, Chris Smith [EMAIL PROTECTED] wrote: I generally make the map file as simple to read and change in a text editor as I can. This generally makes the python code to parse the file a bit more complex, but since this is done only once at start-up I don't notice any speed issues. Another way of doing it is to write a simple map loader that then pickles the data structure and saves it, and then in your game, load the pickle file. Pickling sounds awesome, looking at some tutorials on the web. It would be a good choice if the editor was made in python, and it could be pickled. Text just makes it simpler to start, but pickling would probably be faster in the end. Pickling is good, but can create code maintenance problems as your data files store references to actual classes in modules. Consider reducing your data down to Python builtin types (list, dict, etc.) and use the marshal module instead. It's faster and has none of the potential hassles of pickling. Richard
Re: [pygame] map format
I use a map serialization format like this (works best with a fixed width font): carteString = '''\ 0 1 2 3 4 5 . . . . . . . . . . . . . . . . . . _ . . . _ . . . _ . 3 . . . . . . . 3 . % . . . + . . . ^ . . . . . . . ~ . . . . . % . . . _ . ! . ^ . 2 . . . . ~ ! . 2 . % . . . $ . . . _ . . . . . . . # ! . . . . $ . . . + . ~ . ^ . 1 . = = = . ~ . 1 . _ . . . ^ . . . _ . ~ . . . . . . ~ . . . . _ . . . _ . . . _ . 0 . . . . . . . 0 . _ . . . _ . . . _ . . . . . . . . . . . . . . . . . . 0 1 2 3 4 5 ''' symbolToTerrain = { '_' : Plains, '@' : Fertile, '+' : Desert, '^' : Mountains, '*' : Hills, '$' : Forest, '%' : Water, '~' : River, '' : WideRiver, '=' : Roads, '#' : Bridge, '!' : Cliff, } The center of each hex represents it's terrain, and the center of each hex-side represents edge terrain (e.g. roads). I also use the 3 characters above and below each hex as labels that work as shorthand for locations, so that serialization code placing objects into the map can be more easily read and edited. This also allows naming collections of hexes to create provinces, etc. Following is a more concrete serialization that I used to generate the strategic map seen in this screenshot: http://brass-golem.com/wp-content/uploads/2006/03/0216-154851_screen1.jpg -Jasper carteString = '''\ 0 1 2 3 4 5 6 7 8 9 10 111213141516171819 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . 9 . . . . . . . . . . . . . . . . . . . . . 9 . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . . . . . . . c3c . . . . . . . . r4c . . r4b . . . . . . . . ^ . . . % . . . $ . . . % . . . % . . . % . . . _ . . . _ . . . _ . . . % . 8 . . p3b . . . . p3a . . . r3a . . . . . p4a . . p4a . . p4a . . . 8 . % . . . % . . . % . . . $ . . . + . . . % . . . _ . . . $ . . . _ . . . _ . . . . . . . . . r3b . p3a . r3e . p3a . . . . p4a . . p4a . c4c . p4a . . p4b . . . . . ^ . . . $ . . . _ . ~ . + . . . % . . . % . . . $ . . . $ . . . _ . . . % . 7 . . p3b . r3d . p3b . . p3a ~ ~ p3a . . . . . . p4a . r4a . p4a . . p4b . r4e . . 7 . % . . . ^ . ~ . $ . ~ . + . ~ . + . . . % . . . $ . . . ^ . . . $ . . . _ . . . . . ~ p3b ~ ~ p3b ~ . p3a . c3a ~ p3a . . . c4a . p4a . . p4a . . p4b . . p4b . . . . . ^ . ~ . ^ . ~ . $ . . . + . . . % . . . _ . . . $ . . . ^ . . . $ . . . % . 6 . . p3b . . p3b . . p3a . . p3a . . . . p4a = . p4a . . p4b . . p4b . . . 6 . % . . . ^ . . . ^ . . . + . . . % . . . % . . . $ . . . ^ . . . $ . . . _ . . . . . c3d . p3b . c3b . p3b . r3c . p3a . . . . . . p4a . . p4a . c4b . p4b . . p4b . . . . . _ . . . _ . . . _ . . . % . . . % . . . % . = . ^ . . . $ . . . $ . . . % . 5 . . p3b . . p3b . . p3a . . . . . . . t1 . p4a . r4d . p4b . . p4b . . . 5 . % . . . % . . . _ . . . % . . . % . . . % . . . * . . . ^ . . . $ . . . _ . . . . . . . . p3b . . . . . r2c . . c1a = p1a . . p4b . . p4b . . p4b . . . . . % . . . % . . . % . . . % . . . _ . . . @ . = . ^ . ! . * . . . _ . . . % . 4 . . . . . . . . . c2a = p2a = p1a = r1b . p1a ! ! p4b . .
Re: [pygame] map format
G, my code got it's line breaks mangled. Try #2: symbolToTerrain = { '_' : Plains, '@' : Fertile, '+' : Desert, '^' : Mountains, '*' : Hills, '$' : Forest, '%' : Water, '~' : River, '' : WideRiver, '=' : Roads, '#' : Bridge, '!' : Cliff, } carteString = '''\ 0 1 2 3 4 5 . . . . . . . . . . . . . . . . . . _ . . . _ . . . _ . 3 . . . . . . . 3 . % . . . + . . . ^ . . . . . . . ~ . . . . . % . . . _ . ! . ^ . 2 . . . . ~ ! . 2 . % . . . $ . . . _ . . . . . . . # ! . . . . $ . . . + . ~ . ^ . 1 . = = = . ~ . 1 . _ . . . ^ . . . _ . ~ . . . . . . ~ . . . . _ . . . _ . . . _ . 0 . . . . . . . 0 . _ . . . _ . . . _ . . . . . . . . . . . . . . . . . . 0 1 2 3 4 5 ''' carteString = '''\ 0 1 2 3 4 5 6 7 8 9 10 111213141516171819 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . 9 . . . . . . . . . . . . . . . . . . . . . 9 . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . % . . . . . . . . . c3c . . . . . . . . r4c . . r4b . . . . . . . . ^ . . . % . . . $ . . . % . . . % . . . % . . . _ . . . _ . . . _ . . . % . 8 . . p3b . . . . p3a . . . r3a . . . . . p4a . . p4a . . p4a . . . 8 . % . . . % . . . % . . . $ . . . + . . . % . . . _ . . . $ . . . _ . . . _ . . . . . . . . . r3b . p3a . r3e . p3a . . . . p4a . . p4a . c4c . p4a . . p4b . . . . . ^ . . . $ . . . _ . ~ . + . . . % . . . % . . . $ . . . $ . . . _ . . . % . 7 . . p3b . r3d . p3b . . p3a ~ ~ p3a . . . . . . p4a . r4a . p4a . . p4b . r4e . . 7 . % . . . ^ . ~ . $ . ~ . + . ~ . + . . . % . . . $ . . . ^ . . . $ . . . _ . . . . . ~ p3b ~ ~ p3b ~ . p3a . c3a ~ p3a . . . c4a . p4a . . p4a . . p4b . . p4b . . . . . ^ . ~ . ^ . ~ . $ . . . + . . . % . . . _ . . . $ . . . ^ . . . $ . . . % . 6 . . p3b . . p3b . . p3a . . p3a . . . . p4a = . p4a . . p4b . . p4b . . . 6 . % . . . ^ . . . ^ . . . + . . . % . . . % . . . $ . . . ^ . . . $ . . . _ . . . . . c3d . p3b . c3b . p3b . r3c . p3a . . . . . . p4a . . p4a . c4b . p4b . . p4b . . . . . _ . . . _ . . . _ . . . % . . . % . . . % . = . ^ . . . $ . . . $ . . . % . 5 . . p3b . . p3b . . p3a . . . . . . . t1 . p4a . r4d . p4b . . p4b . . . 5 . % . . . % . . . _ . . . % . . . % . . . % . . . * . . . ^ . . . $ . . . _ . . . . . . . . p3b . . . . . r2c . . c1a = p1a . . p4b . . p4b . . p4b . . . . . % . . . % . . . % . . . % . . . _ . . . @ . = . ^ . ! . * . . . _ . . . % . 4 . . . . . . . . . c2a = p2a = p1a = r1b . p1a ! ! p4b . . p4b . c4d . . 4 . % . . . % . . . % . . . + . . . _ . . . @ . . @ . . . * . ! . _ . . . _ . . . . . . . . . . . . p2a . . p2a = p1a = r1c = p1a = ! p4b . . p4b . . . . . % . . . % . . . % . . . % . = . $ . . . @ . # . @ . . . $ . ! . $ . . . % . 3 . . . . . c2b . . . . r2b . p2a . . p2a = ~ p1a . . p1a = ! p4b . . . 3 . % . . . % . . . $ . . . % . . . _ . . . ^ . . . @ . ~
Re: [pygame] map format
Arg! I hate thunderbird. To avoid further screw-ups, I've just posted the source for the larger map here (which is actually a .py file): http://brass-golem.com/wp-content/uploads/2006/12/showmap.txt Ignore the comments about kludges... -Jasper Jasper wrote: G, my code got it's line breaks mangled. Try #2: [garbled code snipped]
Re: [pygame] map format
Looks ok to me. One thing to mention: If you use 001 and 002, etc. it will be turned to 1 and 2 if you read them in (Python treats them as number). So you can safe space using direct number w/o leading zeros. About the metafile. If you can define this in one line why not adding it to the first line of the map? Then you can read first out the metaline and after this you iterate through the whole map. There is no perfomance lost on this. Farai Am 17.12.2006 um 06:02 schrieb spotter .: Hey everybody, I am in the process of trying to make a file format for maps. I am doing this right now with this: Test_Map,the_author,the_date,version_number 10,5 # the width and height 1 # layers 000,001,002,001,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002 1 Another way that might be easier to read into a file is to Have two files. One is called mapname.map and the other file will be called mapname.meta The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? Thanks, spot
Re: [pygame] map format
Ah, thanks for that, I forgot about how python handles leading zeros. I dont want to place any sort of restriction on the meta information incase I have to add more stuff later on, this way it will scale and simply work. On 12/17/06, Farai Aschwanden [EMAIL PROTECTED] wrote: Looks ok to me. One thing to mention: If you use 001 and 002, etc. it will be turned to 1 and 2 if you read them in (Python treats them as number). So you can safe space using direct number w/o leading zeros. About the metafile. If you can define this in one line why not adding it to the first line of the map? Then you can read first out the metaline and after this you iterate through the whole map. There is no perfomance lost on this. Farai Am 17.12.2006 um 06:02 schrieb spotter .: Hey everybody, I am in the process of trying to make a file format for maps. I am doing this right now with this: Test_Map,the_author,the_date,version_number 10,5 # the width and height 1 # layers 000,001,002,001,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002, 000,001.002,002,002,002,001,000,001,002 1 Another way that might be easier to read into a file is to Have two files. One is called mapname.map and the other file will be called mapname.meta The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? Thanks, spot
Re: [pygame] map format
Thanks, I just wanted to make it fast because if I start loading the map at the beginning, it might seem to take a while before the game starts due to parsing and caching. Probably just my computer though, its a bit low on ram :( On 12/17/06, Ethan Glasser-Camp [EMAIL PROTECTED] wrote: spotter . wrote: Hey everybody, I am in the process of trying to make a file format for maps. The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. I think that unless you're going to be opening/reading map files all the time -- numerous times per frame? -- the performance differential is likely to be negligible. Get it working, then get it fast. If loading maps does turn out to be slow, perhaps you can cache them once loaded. I do something like this with image files, storing the images as .png with information like colorkey in a seperate file. Since I'm caching images anyhow, performance doesn't suffer much. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? I typically try to write my maps as pure Python that call game engine functions. For instance, I've been toying with something like this: setMap(''' 0 1 0''') setTerrain(0, passable=True, tile=grass) setTerrain(1, passable=False, tile=forest) Of course, the last two times I tried to write a tile-based RPG I got nowhere fast and gave up, so maybe you shouldn't take my advice. :) The map format I describe above is inspired by looking at some Wesnoth maps, which look like a huge block of letters, with some other meta information stored in a seperate file. Ethan
Re: [pygame] map format
spotter . wrote: Hey everybody, I am in the process of trying to make a file format for maps. The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. I think that unless you're going to be opening/reading map files all the time -- numerous times per frame? -- the performance differential is likely to be negligible. Get it working, then get it fast. If loading maps does turn out to be slow, perhaps you can cache them once loaded. I do something like this with image files, storing the images as .png with information like colorkey in a seperate file. Since I'm caching images anyhow, performance doesn't suffer much. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? I typically try to write my maps as pure Python that call game engine functions. For instance, I've been toying with something like this: setMap(''' 0 1 0''') setTerrain(0, passable=True, tile=grass) setTerrain(1, passable=False, tile=forest) Of course, the last two times I tried to write a tile-based RPG I got nowhere fast and gave up, so maybe you shouldn't take my advice. :) The map format I describe above is inspired by looking at some Wesnoth maps, which look like a huge block of letters, with some other meta information stored in a seperate file. Ethan signature.asc Description: OpenPGP digital signature
Re: [pygame] map format
I just use .tga files -- and surface.get_at() and surface.set_at(). You get limited to 256 tiles and 4 layers, but I've yet to have that be a problem. Quite adequate for any small game -- and it's simple. If you need to upgrade later, you can always change to a text based format that supports more stuff. Phil Ethan Glasser-Camp [EMAIL PROTECTED] wrote: spotter . wrote: Hey everybody, I am in the process of trying to make a file format for maps. The meta file will have the info like name, author, date, version, and the width and height. The other file will have the actual map data in it. This method will be slower, since it involves opening, parsing, and closing two files. I think that unless you're going to be opening/reading map files all the time -- numerous times per frame? -- the performance differential is likely to be negligible. Get it working, then get it fast. If loading maps does turn out to be slow, perhaps you can cache them once loaded. I do something like this with image files, storing the images as .png with information like colorkey in a seperate file. Since I'm caching images anyhow, performance doesn't suffer much. The second method will be easier to read in, but will affect performance. How do all of you implement maps? Do you use regular expressions or simple search a string ? I typically try to write my maps as pure Python that call game engine functions. For instance, I've been toying with something like this: setMap(''' 0 1 0''') setTerrain(0, passable=True, tile=grass) setTerrain(1, passable=False, tile=forest) Of course, the last two times I tried to write a tile-based RPG I got nowhere fast and gave up, so maybe you shouldn't take my advice. :) The map format I describe above is inspired by looking at some Wesnoth maps, which look like a huge block of letters, with some other meta information stored in a seperate file. Ethan __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com