ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> pygame-users
pygame-users
Re: [pygame] [Pygame] Generating a map
by Ian Mallett other posts by this author
Aug 6 2007 1:01PM messages near this date
Re: [pygame] [Pygame] Generating a map | [pygame] Compatitbility broken in Rect.collidedict
On 8/6/07, J�r�me Brilland <jerome.brilland@[...].net>  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)
      .
      .
      .
      .
Thread:
Jerome Brilland
kschnee
R. Alan Monroe
Kris Schnee
Dave LeCompte
Kris Schnee
Dr0id
Massimo S.
Dr0id
Dave LeCompte
Ian Mallett

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved