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

Re: [pygame] [Pygame] Generating a map



On 8/6/07, Jérôme Brilland <jerome.brilland@xxxxxxxxxx> wrote:
Hello,

I would like to develop a strategy game using Python and Pygame. I would
like to know if it's possible to generate a random map divided into
regions with Pygame. Is there a tutorial for this feature ?

Thanks
Jérôme Brilland

I don't know of a tutorial to do this, but you could make an array of tiles and add instances of a terrain class at an x and y coord.:
pseudocode:

class terrain:
  def __init__(self,x,y,terrain_type):
    self.x = x
    self.y = y
    self.terrain_type = terrain_type
terrains = []
x_dimension = 5; y_dimension = 5 #This can obviously be changed

y_coord = 0
while y_coord < y_dimension:
  x_coord = 0
  while x_coord < x_dimension:
    terrains.append(  terrain(x_coord, y_coord, math.randint(1,6))  )
    x_coord += 1
  y_coord += 1

#(later)

for terrain in terrains:
  if terrain.terrain_type == 1:
    #draw terrain type 1 at pos (terrain.x,terrain.y)
  elif terrain.terrain_type == 2:
    #draw terrain type 2 at pos (terrain.x,terrain.y)
      .
      .
      .
      .