def __init__(self, x, y, category, special, all_groups): Barricade.__init__(self, x, y, all_groups) DamageMixin.__init__(self, self.hit_rect) all_groups['damageable'].add(self) img_file = f'specialBarrel{special}.png' offset = pg.math.Vector2(0, 0) self._barrel = Barrel(self, offset, img_file, "Dark", category, all_groups) self.pos = self.rect.center
def __init__(self, x, y, color, type, groups): img = f"tankBody_{color}_outline.png" Tank.__init__(self, x, y, img, groups) self.id = id(self) # Create, position, and assign id to barrel. offset = cfg.Vec2(self.hit_rect.height // 3, 0) self.color = color.capitalize() barrel = Barrel(self.color, type, self, offset, _BARREL_IMAGES[self.color][type], groups) # barrel.rect.midtop = self.rect.center barrel.id = self.id self._barrels.append(barrel) self.max_ammo = self._barrels[0].get_ammo_count()
def __init__(self, x, y, groups): Tank.__init__(self, x, y, LargeTank._IMAGE, groups) self.id = id(self) self.equip_barrel( Barrel("Dark", "standard", self, cfg.Vec2(0, -10), "specialBarrel4.png", groups)) barrel = Barrel("Dark", "standard", self, cfg.Vec2(0, 10), "specialBarrel4.png", groups) barrel.flip(True, False) # barrel.orig_image = barrel.image self.equip_barrel(barrel) self.max_ammo = self._barrels[0].get_ammo_count() self.color = "Dark" self.MAX_ACCELERATION *= LargeTank.ACC_MULTIPLIER
def color_tank(cls, x: float, y: float, color: str, category: str, groups: typing.Dict[str, pg.sprite.Group]): """Factory method for creating Tank objects.""" tank = cls(x, y, f"tankBody_{color}_outline.png", groups) offset = pg.math.Vector2(tank.hit_rect.height // 3, 0) barrel = Barrel.create_color_barrel(tank, offset, color.capitalize(), category, groups) tank.equip_barrel(barrel) return tank
def huge_tank(cls, x: float, y: float, groups: typing.Dict[str, pg.sprite.Group]) -> 'Tank': """Returns the a 'huge' enemy tank.""" tank = cls(x, y, "tankBody_huge_outline.png", groups) tank.MAX_ACCELERATION *= 0.8 for y_offset in (-10, 10): barrel = Barrel.create_special(tank, pg.math.Vector2(20, y_offset), "Dark", groups, special=4) tank.equip_barrel(barrel) barrel = Barrel.create_special(tank, pg.math.Vector2(-10, 0), "Dark", groups, special=1) tank.equip_barrel(barrel) return tank
def big_tank(cls, x: float, y: float, groups: typing.Dict[str, pg.sprite.Group]) -> 'Tank': """Returns the a 'big' enemy tank.""" tank = cls(x, y, "tankBody_bigRed.png", groups) for y_offset in (-10, 10): barrel = Barrel.create_special(tank, pg.math.Vector2(0, y_offset), "Dark", groups, special=1) tank.equip_barrel(barrel) return tank
class Turret(Barricade, DamageMixin): """Represents a barrel at stands in one place, which can be controlled by others to attack,""" def __init__(self, x, y, category, special, all_groups): Barricade.__init__(self, x, y, all_groups) DamageMixin.__init__(self, self.hit_rect) all_groups['damageable'].add(self) img_file = f'specialBarrel{special}.png' offset = pg.math.Vector2(0, 0) self._barrel = Barrel(self, offset, img_file, "Dark", category, all_groups) self.pos = self.rect.center @property def barrel(self) -> Barrel: """Returns the barrel that belongs tot he barrel.""" return self._barrel @property def range(self) -> float: """Returns the range of the Turret's barrel, i.e., how far its bullets reach.""" return self._barrel.range def kill(self) -> None: self._barrel.kill() # kill the barricade? super().kill() def fire(self, angle: float) -> None: """Causes the Turret's barrel to turn in a certain direction and fire a bullet.""" # TODO: Make it so that it rotates slowly? self._barrel.rot = angle self._barrel.rotate() self._barrel.fire()