[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] map format



I did this for my ludumdare pseudo-game:
http://www.pygame.org/ludumcontest1/warten.zip

I went the route of defining an image containing one
pixel, where the name of the image represents the name
of what that pixel represents in my map.

eg edge.png may be black, and would have a name of
'edge'.

I then make a dict keyed by color, and valued by name.
 Then when I want to test a position on the map I read
that position then do a lookup in my pixel definition
dict.

When you want to add a new type of pixel, you just
make a new one pixel image and you have a new
definition.



NOTE: due to caffiene abuse, and use of one python
session in the 48 hour period my code needs a few
opengl lines removed before it will run(as it doesn't
use it).  The code is still there to look at though.


 --- Michael Benfield <mike@duckbrain.com> wrote: >
I'm looking for a way to store maps for a game. What
> I have in mind, and what I will implement
> unless I find something better, is to store the map
> in 2 files: one file is an image that contains
> what the map looks like, which will actually be the
> background in the game. The second file is
> an image that dictates how the map works. ie, white
> color in the second file is where the character
> can walk, black color is walls, etc. So the first
> thing I'm wondering is: is this a decent way
> to go about this?
> 
> Next... If I do it that way, there are two ways I
> could deal with knowing when the character is
> smacking into a wall... 
> 1. When I load the map, I could build a list of
> rectangles that contain all the black (or whatever)
> pixels in the second image, and then during the game
> check if the character's rect collides with
> one of those rects.
> 2. Just check if any of the pixels that are within
> the character's rect on the second image are
> black.
> 
> I'm leaning towards method 1, but I think I'll write
> both and do tests. But I was wondering if
> anyone had any advice about that. Also, if I do
> implement method 1, any advice about how to go
> about building that list of rects? The way I'm
> thinking about doing starts with
> for x in range(surface.width()):
> 	for y in range(surface.height()):
> 
> and it won't be difficult to implement or anything
> but there's got to be a more efficient way...
> 
> anyway, Thanks 
> 
> 
> -- 
> Mike Benfield
> ____________________________________
> pygame mailing list
> pygame-users@seul.org
> http://pygame.seul.org 

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org