def __init__(self, position=(0, 0)): super(Player, self).__init__() self.animation = { "right": Animation((pygame.transform.rotate(sprite, -90) for sprite in settings.SPRITES["pacman"]), 0.17), "left": Animation((pygame.transform.rotate(sprite, 90) for sprite in settings.SPRITES["pacman"]), 0.17), "up": Animation((pygame.transform.rotate(sprite, 180) for sprite in settings.SPRITES["pacman"]), 0.17), "down": Animation((pygame.transform.rotate(sprite, 0) for sprite in settings.SPRITES["pacman"]), 0.17), "death": OneTimeAnimation(settings.SPRITES["death"], 0.17) } self.image = self.animation["right"].sprites[0] self.rect = self.image.get_rect(center=position) self.position = Vector2D(*position) self.tile_index = settings.get_tile_index(position) self.moving = False self.target = self.position self.direction = Vector2D(0, 0) self.radius = self.rect.width // 3 self.energized = True self.dead = False
def add_points(tile_map): energizer_tiles = [(6, 1), (6, 26), (26, 1), (26, 26)] energizer_pos = [ settings.get_position(x, offset="topleft") for x in energizer_tiles ] empty_pos = list(itertools.product(range(12, 23), range(7, 21))) # Square by the house. for tile in tile_map.tile.values(): if settings.get_tile_index(tile.rect.topleft) in empty_pos: continue if tile.is_any_type( "path", "restricted") and 0 <= tile.rect.x < settings.WIDTH: if any(tile.rect.collidepoint(pos) for pos in energizer_pos): tile.content.add(Enegizer(tile.rect)) else: tile.content.add(Point(tile.rect))
def __init__(self, position=(0, 0)): super(Ghost, self).__init__() self.ID = Ghost.ID Ghost.ID += 1 self.sprites = settings.SPRITES[Ghost.NAME[self.ID]] self.image = self.sprites[0] self.rect = self.image.get_rect(center=position) self.prev_tile_index = (0, 0) self.tile_index = settings.get_tile_index(position) self.direction = Vector2D(0, 0) self.moving = False # replace with abs(self.direction) == 0 self.position = Vector2D(*position) self.target = self.position self.end_target = self.position self.time = 0 self.speed = 80 self.dead = False self.frightened = False self.mode = 0
def stop_if_arrived(self): if self.position == self.target: self.moving = False self.tile_index = settings.get_tile_index(self.position)
def __repr__(self): return "Tile: index={0}, type={1}".format(settings.get_tile_index(self.rect.center), self.type_)