def __init__(self): super().__init__() self.spawners = pg.sprite.Group() self.enemies = pg.sprite.Group() # only enemies and nothing else self.enemies_with_health = pg.sprite.OrderedUpdates() # with healthbars self.towers = pg.sprite.Group() self.weapons = pg.sprite.Group() self.explosions = pg.sprite.Group() self.towerselectors = pg.sprite.Group() self.path = {} self.map_positions = tools.calculate_positions( self.display_surface.get_rect().center, resources.STANDARD_RECT, 9) self.unoccupied_rects = list(self.map_positions.values()) self.towerselector_positions = {} self.towerselector_area = None self.towerplacer = None self.background = tools.paint_background( self.display_surface.get_size(), self.map_positions) button.Button("Menu", (50, 20), self.buttons) button.Button("Pause", (50, 60), self.buttons) button.Button("Next Wave", (50, 100), self.buttons)
def setup_map(self, map_data): for i in map_data: coords = (i["a"], i["b"]) image_name = i["name"] direction = i["direction"] if "direction" in i else None rect = self.map_positions[coords] self.unoccupied_rects.remove(rect) if image_name.startswith("path"): self.background.blit(resources.IMAGES[image_name], rect) if direction is not None: self.path[coords] = path.Path( coords, rect, direction) elif image_name.startswith("spawner"): self.background.blit(resources.IMAGES["dark_borderless_tile"], rect) spawner.Spawner(image_name, rect, int(image_name[-1]), self.spawners, self.enemies, self.enemies_with_health) self.towerselector_positions = tools.calculate_positions( (900, 650), resources.STANDARD_RECT, 1) towers.TowerSelector(towers.GreenTower, self.towerselector_positions[(-1, 0)], self.towerselectors) towers.TowerSelector(towers.RedTower, self.towerselector_positions[(0, 1)], self.towerselectors) ts_rects = [] for ts in self.towerselectors: ts_rects.append(ts.rect) self.towerselector_area = ts_rects[0].unionall(ts_rects[1:])