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

[pygame] bidimensional arrays or the quick way to maps



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

now, probably i'm missing a basic feature of python, but it seems to lack of a native support for multidimensional arrays. i've seen that NumPy as an advanced array class, but probably so advanced that i got lost in the documentation and i could't find a way to get the simple things i need: -declare a multidimensional array specifiying the lenght of each dimension (like, to obtain a 10x20 grid a sort of "a = array(10,20)" or (9,19) if 0-based) -easily access the cells for reading / appending / writing data, like in "a[7][4] = 8" to alter or set the content of a given cell.

how did you solve the problem?
thanks in advance
gustavo