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

Re: [pygame] board game



So the answer is that rects don't have to be asociated to an image,isn't? What I am doing is that you've said, I have two lists of squares in which each square is actually a rect.

Thanks alot.
El 15/11/2007, a las 23:19, David Gowers escribió:

On Nov 15, 2007 11:00 PM, marta sanz <p22sacam@xxxxxx> wrote:
Hi there,

I've left the board game for a time, and now that I have time again,
I have returned to it..

Can I do new=pygame.rect(10,20,30,40) ? I mean, I do load an entire
image of my game board, that will be the surface,  and then, as
Samuel said, I've tried to create invisible squares over it using
rect function, but, do I need to load an image -many as squares have
my board- , make it invisible and take the rect from it?

That would be extremely complicated compared to what you actually need
to do -- you only need the rects, so only create the rects.

The following code will create one rect for each square in a grid.
perhaps you can use it as a base.


import pygame
# you can adjust the following parameters to change the size of the grid
# and the size of each square
numsquares_x = 7
numsquares_y = 6
square_width = 32
square_height = 32
squares = []

for x in range (0, numsquares_x):
  for y in range (0, numsquares_y):
    thissq = pygame.rect (x * square_width, y * square_height,(x+1) *
square_width, (y+1) * square_height)
    squares.append (thissq)