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

Re: [pygame] board game



Ian Mallett wrote:
    It doesn't really matter which way you do it, but I would
recommend making the entire thing all at once, as I see no advantage
to having individual squares, and it would make programming less
complicated.
Ian


I would make a square of the appropriate size of one color, and load it using this function:

def load_image(name):
   fullname = os.path.join('images')
   fullname = os.path.join(fullname, name)
   try:
       image = pygame.image.load(fullname)
   except pygame.error, message:
       print 'Cannot load image:', fullname
       raise SystemExit, message
   image = image.convert()
   colorkey = image.get_at((0,0))
   image.set_colorkey(colorkey, RLEACCEL)
   return image, image.get_rect()

Then use it for all the squares, and define their coordinates by pixel. The result is a whole bunch of little, invisible squares, each one having a question attached to it, that the player can click on, and behind that a background image that doesn't change. This might be more trouble than it's worth for the sort of thing you're aiming for--I used it when building a small RPG where the background was a complete image for each area and the blocks were defined as being either "Player can't walk here", "Player can walk here", or "Player meets monsters here", so that (if I could actually draw on a computer) each area would have a pretty background.

Anyway, I hope that helps. God luck!