[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] bidimensional arrays or the quick way to maps
On Wed, 5 Sep 2007, pistacchio wrote:
> maps are certainly a very common feature in game development. the
> easiest way to trace maps (and the one that i've used in other languages
> in tha past) is to use multidimensional arrays. so, a tile-map, can be
> stored and worked on as a simple array (or list) that goes like this:
>
> tile_map[x][y] = tile_number
tile_map = {}
tile_map[x, y] = tile_number
cell = tile_map.get(x, y)
or to automatically default cells to None:
import collections
tile_map = collections.defaultdict()
cell = tile_map[x, y]
or if you don't want it sparse:
tile_map = [[None]*x_dim for i in range(y_dim)]
I prefer the sparse approach.
Richard