Beispiel #1
0
class Weapon(YTGBaseWeapon):
    name = NAME
    max_health = 40
    size_inc = 1.25
    proj_velocity = 1200
    fire_delay = 100
    sound = {
        'fire': [load_sound('Weapons\\Models\\explosion_dull'), {'channel': CHANNEL.PLASMA_WEAPON}]
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.i_body = pymunk.Body()
        self.shape = pymunk.Circle(self.body, self.RADIUS, self.image_to_local((26, 17)))
        self.shape.density = 1

    @classmethod
    def init_class(cls):
        cls._frames, cls.IMAGE_SHIFT = cast_model(MODEL, CS, cls.size_inc)
        cls.precalculate_shape()
        cls.calculate_poly_shape()
        from Projectiles.plasma_bolt import Projectile
        cls.Projectile = Projectile
        cls.fire_pos = cls.image_to_local((65, 17))

    @classmethod
    def precalculate_shape(cls):
        radius = 22

        cls.RADIUS = radius * cls.size_inc

    @classmethod
    def calculate_poly_shape(cls):
        img_poly_left = []
        poly_left = [tuple(e[n] - CS[n] for n in range(2)) for e in img_poly_left]
        poly_right = [(e[0], -e[1]) for e in poly_left[::-1]]
        cls.POLY_SHAPE = [(e[0] * cls.size_inc, e[1] * cls.size_inc) for e in poly_left + poly_right]
Beispiel #2
0
class Projectile(BaseProjectile):
    size_inc = 2.25
    hit_damage = 350
    damping = .5
    sound = {
        'explode': [
            load_sound('Projectiles\\Models\\flagdrop', ext='wav'), {
                'channel': CHANNEL.PULSON_EXPLOSION
            }
        ]
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.body = pymunk.Body()
        self.shape = pymunk.Circle(self.body, self.RADIUS)
        self.shape.density = 1
        self.shape.collision_type = COLLISION_TYPE.PROJECTILE
        self.explosion = False
        self._image.n = 1

    def damage(self, val):
        pass

    def effect(self, obj, arbiter, first=True):
        if self.explosion:
            cps = arbiter.contact_point_set
            if cps.points:
                pc_depth = abs(cps.points[0].distance) / self.shape.radius
                obj.body.apply_impulse_at_local_point(
                    (cps.normal * (10000000 * pc_depth *
                                   (1 if first else -1))), (0, 0))
                obj.damage(self.hit_damage * pc_depth)

    def death(self):
        self.explode()

    def explode(self):
        self.play_sound('explode')
        self._image.n = 0
        self._image.fps = 20
        self._image.que_end(self.kill)
        self.explosion = True

    def update(self):
        if self.explosion:
            self.shape.unsafe_set_radius(self.R_LIST[self._image.n])

    @classmethod
    def init_class(cls):
        cls._frames, cls.IMAGE_SHIFT = cast_model(MODEL, CS, cls.size_inc)
        cls.precalculate_shape()
        cls.calculate_poly_shape()

    @classmethod
    def precalculate_shape(cls):
        radius = 12
        rs = (6, 7, 12, 18, 36, 58, 90, 120, 146)

        cls.RADIUS = radius * cls.size_inc
        cls.R_LIST = [e * cls.size_inc for e in rs]

    @classmethod
    def calculate_poly_shape(cls):
        img_poly_left = []
        poly_left = [
            tuple(e[n] - CS[n] for n in range(2)) for e in img_poly_left
        ]
        poly_right = [(e[0], -e[1]) for e in poly_left[::-1]]
        cls.POLY_SHAPE = [(e[0] * cls.size_inc, e[1] * cls.size_inc)
                          for e in poly_left + poly_right]
Beispiel #3
0
class Weapon(YTGBaseWeapon):
    name = NAME
    size_inc = 1
    max_health = 50
    fire_delay = 2000
    proj_velocity = 1400
    sound = {
        'fire': [
            load_sound('Weapons\\Models\\boing_x', ext='wav'), {
                'channel': CHANNEL.PULSON_WEAPON
            }
        ]
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.i_body = pymunk.Body()
        self.shape = pymunk.Circle(self.body, self.RADIUS,
                                   self.image_to_local((48, 30)))
        self.shape.density = 1

    def force_fire(self, **kwargs):
        self.play_sound('fire')
        proj = self.spawn_proj()
        ang = self.miss_angle()
        rad = math.radians(ang)
        if 'target' in kwargs.keys():
            dis = (proj.position - kwargs['target']).length
            vel = proj.velocity_for_distance(dis, proj.life_left)
            if vel > self.proj_velocity:
                vel = self.proj_velocity
        else:
            vel = self.proj_velocity
        vec = Vec2d(vel * math.cos(rad), vel * math.sin(rad))
        proj.velocity = vec
        proj.angle = ang

    @classmethod
    def init_class(cls):
        cls._frames, cls.IMAGE_SHIFT = cast_model(MODEL, CS, cls.size_inc)
        cls.precalculate_shape()
        cls.calculate_poly_shape()
        from Projectiles.pulson import Projectile
        cls.Projectile = Projectile
        cls.fire_pos = cls.image_to_local((64, 30))

    @classmethod
    def precalculate_shape(cls):
        radius = 40

        cls.RADIUS = radius * cls.size_inc

    @classmethod
    def calculate_poly_shape(cls):
        img_poly_left = []
        poly_left = [
            tuple(e[n] - CS[n] for n in range(2)) for e in img_poly_left
        ]
        poly_right = [(e[0], -e[1]) for e in poly_left[::-1]]
        cls.POLY_SHAPE = [(e[0] * cls.size_inc, e[1] * cls.size_inc)
                          for e in poly_left + poly_right]
Beispiel #4
0
class Weapon(YTGBaseWeapon):
    name = NAME
    size_inc = .5
    max_health = 60
    fire_delay = 2500
    proj_velocity = 2500
    inaccuracy = .25
    fragmentation = 14
    sound = {
        'fire': [
            load_sound('Weapons\\Models\\undetach', ext='wav'), {
                'channel': CHANNEL.NET_WEAPON
            }
        ]
    }

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.i_body = pymunk.Body()
        self.shape = pymunk.Poly(self.body, self.POLY_SHAPE)
        self.shape.density = 1

    def force_fire(self, **kwargs):
        self.play_sound('fire')
        ca = self.angle
        da = self.inaccuracy * 360
        sa = ca - da / 2

        frag = self.fragmentation
        vel = self.proj_velocity
        segments = []

        b_a = self.spawn(Ballast)
        b_a.set_parent(self)
        b_a.angle = sa
        b_a.velocity = Vec2d.from_anglen(sa, vel)

        b_b = self.spawn(Ballast)
        b_b.set_parent(self)
        b_b.angle = sa + da
        b_b.velocity = Vec2d.from_anglen(sa + da, vel)

        b_a.pair = b_b
        b_b.pair = b_a

        w = (self.Projectile.LENGTH - self.Projectile.RADIUS) / 2

        for n in range(frag):
            proj = self.spawn_proj()

            if segments:
                Pivot(proj.body, segments[-1].body, (-w, 0), (w, 0))

            segments.append(proj)
            ang = sa + da * (n / frag)
            proj.angle = ang - 90
            proj.velocity = Vec2d.from_anglen(ang, vel * .8)

        Pivot(b_a.body, segments[0].body, (0, 0), (-w, 0))
        Pivot(b_b.body, segments[-1].body, (0, 0), (w, 0))

    @classmethod
    def init_class(cls):
        cls._frames, cls.IMAGE_SHIFT = cast_model(MODEL, CS, cls.size_inc)
        cls.precalculate_shape()
        cls.calculate_poly_shape()
        cls.Projectile = Segment
        cls.fire_pos = cls.image_to_local((170, 39))

    @classmethod
    def precalculate_shape(cls):
        radius = 40

        cls.RADIUS = radius * cls.size_inc

    @classmethod
    def calculate_poly_shape(cls):
        img_poly_left = [(0, 39), (20, 6), (158, 2)]
        poly_left = [
            tuple(e[n] - CS[n] for n in range(2)) for e in img_poly_left
        ]
        poly_right = [(e[0], -e[1]) for e in poly_left[::-1]]
        cls.POLY_SHAPE = [(e[0] * cls.size_inc, e[1] * cls.size_inc)
                          for e in poly_left + poly_right]
Beispiel #5
0
class Projectile(BaseProjectile):
    size_inc = 1
    damping = 0
    max_health = 10
    lifetime = 3000
    hit_damage = 15
    sound = {
        'launch': [
            load_sound('Projectiles\\Models\\mini_launch',
                       ext='wav',
                       volume=.5), {
                           'channel': CHANNEL.MINI_LAUNCH
                       }
        ]
    }
    death_effect = VideoEffect

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.body = pymunk.Body()
        self.shape = pymunk.Poly(self.body, self.POLY_SHAPE)
        self.shape.density = 1

        self.target = None
        self.boost = False

    def effect(self, obj, arbiter, first=True):
        if self.boost:
            obj.damage(self.hit_damage)
            self.death()

    def death(self):
        if self.health > 0 and not self.boost:
            self.emit_death_effect()
        else:
            v = Explosion()
            v.add(*self.groups())
            v.position = self.position
            v.set_parent(self)
        self.kill()

    def update(self):
        if self.boost:
            self.body.apply_force_at_local_point((5000000, 0), (0, 0))
            if self.target is not None:
                if hasattr(self.target, '__call__'):
                    tp = self.target()
                else:
                    tp = list(self.target)
                da = angular_distance(self.angle,
                                      (Vec2d(tp) - self.position).angle)
                self.angle += da * .1

    def launch(self):
        self.play_sound('launch')
        self.boost = True
        self.damping = 0
        self._image.fps = 10

    @classmethod
    def init_class(cls):
        cls._frames, cls.IMAGE_SHIFT = cast_model(MODEL, CS, cls.size_inc)
        cls.precalculate_shape()
        cls.calculate_poly_shape()

    @classmethod
    def precalculate_shape(cls):
        radius = 15

        cls.RADIUS = radius * cls.size_inc

    @classmethod
    def calculate_poly_shape(cls):
        img_poly_left = [(75, 31), (146, 33)]
        poly_left = [
            tuple(e[n] - CS[n] for n in range(2)) for e in img_poly_left
        ]
        poly_right = [(e[0], -e[1]) for e in poly_left[::-1]]
        cls.POLY_SHAPE = [(e[0] * cls.size_inc, e[1] * cls.size_inc)
                          for e in poly_left + poly_right]