class ClusterBomb(PhysicsObject): IMAGE = Loader.get_image("cluster_bomb") EXPLOSION_RADIUS = 20 def __init__(self, alive_sec, x, y): super().__init__(x, y, 5, 0.5, bounce_times=3, time_to_death_millis=alive_sec * 1000) def get_draw_position(self): return self._pos - GRENADE_OFFSET def death_action(self, world): world.explosion(int(self.x), int(self.y), ClusterBomb.EXPLOSION_RADIUS, 15, 1) for _ in range(random.randrange(9, 12)): angle = random.random() * math.pi * 2 cluster = Cluster(*self._pos) cluster.vel_x = math.cos(angle) * ClusterBomb.EXPLOSION_RADIUS cluster.vel_y = math.sin(angle) * ClusterBomb.EXPLOSION_RADIUS world.physicsObjects.append(cluster)
class Grenade(PhysicsObject): IMAGE = Loader.get_image("grenade") EXPLOSION_RADIUS = 25 def __init__(self, alive_sec, x, y): super().__init__(x, y, 5, 0.5, bounce_times=3, time_to_death_millis=alive_sec * 1000) def death_action(self, world): world.explosion(int(self.x), int(self.y), Grenade.EXPLOSION_RADIUS, 45, 2) def get_draw_position(self): return self._pos - GRENADE_OFFSET
class Cluster(PhysicsObject): IMAGE = Loader.get_image("cluster") CLUSTER_OFFSET = 2, 2 EXPLOSION_RADIUS = 8 def __init__(self, x, y): super().__init__(x, y, 1, 0.8, bounce_times=1, time_to_death_millis=3000) def get_draw_position(self): return self._pos - Cluster.CLUSTER_OFFSET def death_action(self, world): world.explosion(int(self.x), int(self.y), Cluster.EXPLOSION_RADIUS, 10, 1)
class Bullet(PhysicsObject): IMAGE = Loader.get_image("uzi_bullet") Type = PhysicsObjectType.Bullet def __init__(self, x: float, y: float, damage: int): super().__init__(x, y, 1, 1, 1, time_to_death_millis=3000, affected_by_gravity=0.1) self.damage: int = damage self.excludedEntities: List[PhysicsObject] = [] self.hitWorm = False def set_excluded_entities(self, entities): self.excludedEntities = entities def check_collisions(self, entities) -> bool: for worm in filter(lambda p: p.is_worm(), entities): if worm not in self.excludedEntities: if worm.health <= 0: continue if worm.pos.distance_to(self.pos) < worm.radius: worm.health -= self.damage worm.draw_health() for i in range(10): bl = Blood(*worm.pos) angle = random.random() * math.pi * 2 bl.vel_x = math.cos(angle) * 10 bl.vel_y = math.sin(angle) * 10 entities.append(bl) self.hitWorm = True return True return False
class Blood(Debris): IMAGE = Loader.get_image("blood")
class WSniper(SimpleShooting): HoldImage = Loader.get_image("sniper") def __init__(self): super().__init__(SniperBullet, 1, 1, 150, 0)
class WMinigun(SimpleShooting): HoldImage = Loader.get_image("minigun") def __init__(self): super().__init__(MinigunBullet, 50, 0.03, 50, math.pi / 5)
class WUzi(SimpleShooting): HoldImage = Loader.get_image("uzi") def __init__(self): super().__init__(UziBullet, 50, 0.06, 80, math.pi / 4)
class WClusterBomb(SimpleThrowable): HoldImage = Loader.get_image("cluster_bomb") def __init__(self): super().__init__(ClusterBomb, 60)
class WGrenade(SimpleThrowable): HoldImage = Loader.get_image("grenade") def __init__(self): super().__init__(Grenade, 60)
class SniperBullet(Bullet): IMAGE = Loader.get_image("sniper_bullet") def __init__(self, x, y): super().__init__(x, y, 80)
class MinigunBullet(Bullet): IMAGE = Loader.get_image("minigun_bullet") def __init__(self, x: float, y: float): super().__init__(x, y, 4)
class UziBullet(Bullet): IMAGE = Loader.get_image("uzi_bullet") def __init__(self, x: float, y: float): super().__init__(x, y, 5)