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

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



Hi Kai

See inside..

Am 24.03.2006 um 10:27 schrieb Kai Kuehne:

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.
=> Thats true. You have to go though the list when reading out the coordinates. When setting it (while a ghost got new coordinates, you can access the related tuple in the list directly.)


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 looks fine to me. As I said, there are many ways to solve a problem. Be aware that you might create the grid (background) blockwise (f.e.walls: 1 field = 20 x 20 pixel) but the movement of the Pacman and ghosts might be pixelwise. Working the way you describe (with character signs) gives you a good way to implement a level editor.
Another question: Is it necessary to check for "Nothing"? You might have a background color (for Pacman normally black). In case you dont set any wall or ground the background color will appear anyway.
Another point about walls: If you treat walls as blocks, you don't need to care about horizontal, vertical or crossed walls. But I guess you anyway will work with squares (blocks).



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.
=> you probably will have 2 ways accessing the object list:
1. Reading (yes, then just go through the whole list and display whats in it
2. Update (moving objects needs to be updated by their coordinates -> direct tuple access)
3. Delete (objects not to be displayed anymore need to be deleted or set as "invisible")


Your name sounds German and if you coming speak it also: Before annoying all the people here you can contact me via Email directly (in German ;) ).

Regards
Farai


[More Tips]

Regards
Farai

Thank you for your tips. Kai