Example #1
0
def _preload2() -> None:
    # FIXME: Could integrate these loads with the classes that use them
    #  so they don't have to redundantly call the load
    #  (even if the actual result is cached).
    for mname in ['powerup', 'powerupSimple']:
        ba.getmodel(mname)
    for tname in [
            'powerupBomb', 'powerupSpeed', 'powerupPunch', 'powerupIceBombs',
            'powerupStickyBombs', 'powerupShield', 'powerupImpactBombs',
            'powerupHealth'
    ]:
        ba.gettexture(tname)
    for sname in [
            'powerup01', 'boxDrop', 'boxingBell', 'scoreHit01', 'scoreHit02',
            'dripity', 'spawn', 'gong'
    ]:
        ba.getsound(sname)
    from bastd.actor.bomb import BombFactory
    BombFactory.get()
    ba.timer(0.1, _preload3)
Example #2
0
    def arm(self, old_function: Callable):
        """Arm the bomb.

        These types of bombs will not explode until they have been armed.
        """
        if not self.node:
            return
        factory = BombFactory.get()
        mebomb: Optional[MeBomb] = get_mebomb(self.bomb_type)
        if mebomb is None:
            old_function(self)
            return
        mebomb.arm(self)
        ba.playsound(factory.activate_sound, 0.5, position=self.node.position)
Example #3
0
    def __init__(self, old_function: Callable,
                 position: Sequence[float] = (0.0, 1.0, 0.0),
                 velocity: Sequence[float] = (0.0, 0.0, 0.0),
                 blast_radius: float = 2.0,
                 blast_type: str = 'normal',
                 source_player: ba.Player = None,
                 hit_type: str = 'explosion',
                 hit_subtype: str = 'normal'):
        meblast = _blasts.get(blast_type)
        if meblast is None:
            old_function(self, position=position, velocity=velocity, blast_radius=blast_radius,
                         blast_type=blast_type, source_player=source_player, hit_type=hit_type,
                         hit_subtype=hit_subtype)
            return
        """Instantiate with given values."""

        # bah; get off my lawn!
        # pylint: disable=too-many-locals
        # pylint: disable=too-many-statements

        ba.Actor.__init__(self)

        factory = BombFactory.get()

        self.blast_type = blast_type
        self._source_player = source_player
        self.hit_type = hit_type
        self.hit_subtype = hit_subtype
        self.radius = blast_radius

        # Do we need to light?
        # lcolor = ((0.6, 0.6, 1.0) if self.blast_type == 'ice' else
        #           (1, 0.3, 0.1))
        # light = ba.newnode('light',
        #                    attrs={
        #                        'position': position,
        #                        'volume_intensity_scale': 10.0,
        #                        'color': lcolor
        #                    })

        # scl = random.uniform(0.6, 0.9)
        # scorch_radius = light_radius = self.radius
        # if self.blast_type == 'tnt':
        #     light_radius *= 1.4
        #     scorch_radius *= 1.15
        #     scl *= 3.0
        #
        # iscale = 1.6
        # ba.animate(
        #     light, 'intensity', {
        #         0: 2.0 * iscale,
        #         scl * 0.02: 0.1 * iscale,
        #         scl * 0.025: 0.2 * iscale,
        #         scl * 0.05: 17.0 * iscale,
        #         scl * 0.06: 5.0 * iscale,
        #         scl * 0.08: 4.0 * iscale,
        #         scl * 0.2: 0.6 * iscale,
        #         scl * 2.0: 0.00 * iscale,
        #         scl * 3.0: 0.0
        #     })
        # ba.animate(
        #     light, 'radius', {
        #         0: light_radius * 0.2,
        #         scl * 0.05: light_radius * 0.55,
        #         scl * 0.1: light_radius * 0.3,
        #         scl * 0.3: light_radius * 0.15,
        #         scl * 1.0: light_radius * 0.05
        #     })
        # ba.timer(scl * 3.0, light.delete)

        # make a scorch that fades over time

        # if self.blast_type == 'ice':
        #     ba.playsound(factory.hiss_sound, position=light.position)

        # lpos = light.position
        # ba.playsound(factory.random_explode_sound(), position=lpos)
        # ba.playsound(factory.debris_fall_sound, position=lpos)

        ba.camerashake(intensity=5.0 if self.blast_type == 'tnt' else 1.0)

        _blasts[blast_type](self,
                            position=position,
                            velocity=velocity,
                            blast_radius=blast_radius,
                            hit_type=hit_type,
                            hit_subtype=hit_subtype)
Example #4
0
    def __init__(self, old_function: Callable,
                 position=(0.0, 1.0, 0.0),
                 velocity=(0.0, 0.0, 0.0),
                 bomb_type: str = 'normal',
                 blast_radius: float = 2.0,
                 source_player: ba.Player = None,
                 owner: ba.Node = None):
        """Create a new Bomb.

        bomb_type can be standard or one from declared with bd.me.
        Note that for impact or land_mine bombs you have to call arm()
        before they will go off.
        """
        mebomb: MeBomb = get_mebomb(bomb_type)
        if mebomb is None:
            old_function(self, position, velocity, bomb_type, blast_radius, source_player, owner)
            return

        ba.Actor.__init__(self)

        factory = BombFactory.get()
        shared = SharedObjects.get()
        self.bomb_type = bomb_type
        self._exploded = False
        self.texture_sequence = None
        self.blast_radius = blast_radius

        self._explode_callbacks = []

        # the player this came from
        self._source_player = source_player

        # by default our hit type/subtype is our own, but we pick up types of
        # whoever sets us off so we know what caused a chain reaction
        self.hit_type = 'explosion'
        self.hit_subtype = self.bomb_type

        # if no owner was provided, use an unconnected node ref
        # (nevermind; trying to use None in these type cases instead)
        # if owner is None:
        #     owner = ba.Node(None)

        # the node this came from
        self.owner = owner

        # adding footing-materials to things can screw up jumping and flying
        # since players carrying those things
        # and thus touching footing objects will think they're on solid
        # ground.. perhaps we don't wanna add this even in the tnt case?..
        materials: tuple
        materials = (factory.bomb_material,
                     shared.object_material)

        if mebomb.is_impact:
            materials = materials + (factory.impact_blast_material,)
        elif mebomb.is_mine:
            materials = materials + (factory.land_mine_no_explode_material,)
        # TODO: add custom materials (now you may add they in mebomb.init)

        fuse_time = None

        mebomb = get_mebomb(self.bomb_type)
        fuse_time = mebomb.fuse_time
        self.blast_radius *= mebomb.blast_coefficient
        if mebomb.sticky:
            materials = materials + (factory.sticky_material,)
        else:
            materials = materials + (factory.normal_sound_material,)
        if mebomb.is_impact:
            materials = materials + (factory.impact_blast_material,)
        if mebomb.is_mine:
            materials = materials + (factory.land_mine_no_explode_material,)
        mebomb.init(self, position, velocity, materials)

        # Light the fuse!!!
        if fuse_time is not None:
            ba.timer(fuse_time,
                     ba.WeakCall(self.handlemessage, ExplodeMessage()))

        ba.animate(self.node, "model_scale", {0: 0, 0.2: 1.3, 0.26: 1})