Hi Kai
See inside..
Am 24.03.2006 um 10:27 schrieb Kai Kuehne:
=> 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.)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 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.
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)))
=> you probably will have 2 ways accessing the object list: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.
Regards Farai
[More Tips]
Regards Farai
Thank you for your tips. Kai