[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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 <glasse@xxxxxxxxxx> 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('''
000001111
000000001
000001111''')
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