Sep-01-2022, 11:07 PM
I have a dictionary of tile sprites, (x,y) are the keys. I think I have found how to determine the tiles local to the player, but I get a KeyError when those tiles don't exist.
Is it best practice to use an Exception to pass, or is there some better way avoid the error?
The hope is that I can use this local list to prevent the player and bullets from checking collisions for tiles that are a million miles away.
Thanks for help.
Is it best practice to use an Exception to pass, or is there some better way avoid the error?
def find_local(self): local = [] pos = (self.rect.centerx // self.game.level.tilesize, self.rect.centery // self.game.level.tilesize) for x in range(pos[0] - 3, pos[0] + 3): for y in range(pos[1] - 3, pos[1] + 3): local.append(self.game.level.tile_dict[x, y])
The hope is that I can use this local list to prevent the player and bullets from checking collisions for tiles that are a million miles away.
Thanks for help.