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

Re: [pygame] My first game; the design of pacman



Hi,

On 3/22/06, Farai Aschwanden <fash@xxxxxxxxxx> wrote:
> > Me wrote:
> > if c == 'G':
> >     c = Ghost()
> => Its turns too complicated to scan the whole list to check what
> type of object to display. Well it's a way...
> How about to work with a list or a dictionary? Like
> monster_list = [(color_a, x_coordinate, y_coordinate, ), color_b,
> x_coordinate, y_coordinate, ), ...]

Yes, that's good.
But I have to iterate through the map-list, though.

This is the way I made it:

        for x in range(len(self.map)):
            for y in range(len(self.map[x])):
                screen_x = x * GRIDSIZE
                screen_y = y * GRIDSIZE
                if self.map[x][y] == '#':
                    self.background_list.add(Wall((screen_y, screen_x)))
                elif self.map[x][y] == ' ':
                    self.background_list.add(Ground((screen_y, screen_x)))
                elif self.map[x][y] == '0':
                    self.background_list.add(Nothing((screen_y, screen_x)))

This create's the background_list.
I do this for Pacman, the ghosts and the pills too.


> This list repesents 2 ghosts in 2 tuples that you only have to go
> through and read out the coordinaties for blitting them by their
> coordinates (you need another routine updating those coordinates
> depending on the movement of the ghosts).

Yes, but i have to iterate trough the maplist. If I do it not,
i don't know the coordinates defined in the map.

> [More Tips]

> Regards
> Farai

Thank you for your tips.
Kai