def _drop_powerup(self, index: int, poweruptype: str = None) -> None: from bastd.actor import powerupbox if poweruptype is None: poweruptype = (powerupbox.get_factory().get_random_powerup_type( excludetypes=self._excludepowerups)) powerupbox.PowerupBox(position=self.map.powerup_spawn_points[index], poweruptype=poweruptype).autoretain()
def __init__(self, settings: Dict[str, Any]): from bastd.actor.scoreboard import Scoreboard from bastd.actor import powerupbox super().__init__(settings) self._scoreboard = Scoreboard() self._cheer_sound = ba.getsound("cheer") self._chant_sound = ba.getsound("crowdChant") self._foghorn_sound = ba.getsound("foghorn") self._swipsound = ba.getsound("swip") self._whistle_sound = ba.getsound("refWhistle") self.puck_model = ba.getmodel("puck") self.puck_tex = ba.gettexture("puckColor") self._puck_sound = ba.getsound("metalHit") self.puck_material = ba.Material() self.puck_material.add_actions(actions=(("modify_part_collision", "friction", 0.5))) self.puck_material.add_actions( conditions=("they_have_material", ba.sharedobj('pickup_material')), actions=("modify_part_collision", "collide", False)) self.puck_material.add_actions( conditions=(("we_are_younger_than", 100), 'and', ("they_have_material", ba.sharedobj('object_material'))), actions=("modify_node_collision", "collide", False)) self.puck_material.add_actions( conditions=("they_have_material", ba.sharedobj('footing_material')), actions=("impact_sound", self._puck_sound, 0.2, 5)) # Keep track of which player last touched the puck self.puck_material.add_actions( conditions=("they_have_material", ba.sharedobj('player_material')), actions=(("call", "at_connect", self._handle_puck_player_collide), )) # We want the puck to kill powerups; not get stopped by them self.puck_material.add_actions( conditions=("they_have_material", powerupbox.get_factory().powerup_material), actions=(("modify_part_collision", "physical", False), ("message", "their_node", "at_connect", ba.DieMessage()))) self._score_region_material = ba.Material() self._score_region_material.add_actions( conditions=("they_have_material", self.puck_material), actions=(("modify_part_collision", "collide", True), ("modify_part_collision", "physical", False), ("call", "at_connect", self._handle_score))) self._puck_spawn_pos: Optional[Sequence[float]] = None self._score_regions: Optional[List[ba.NodeActor]] = None self._puck: Optional[Puck] = None
def _preload1() -> None: """Pre-load some assets a second or two into the main menu. Helps avoid hitches later on. """ for mname in [ 'plasticEyesTransparent', 'playerLineup1Transparent', 'playerLineup2Transparent', 'playerLineup3Transparent', 'playerLineup4Transparent', 'angryComputerTransparent', 'scrollWidgetShort', 'windowBGBlotch' ]: ba.getmodel(mname) for tname in ["playerLineup", "lock"]: ba.gettexture(tname) for tex in [ 'iconRunaround', 'iconOnslaught', 'medalComplete', 'medalBronze', 'medalSilver', 'medalGold', 'characterIconMask' ]: ba.gettexture(tex) ba.gettexture("bg") from bastd.actor import powerupbox powerupbox.get_factory() ba.timer(0.1, _preload2)
def _drop_powerups(self, standard_points: bool = False, poweruptype: str = None) -> None: """Generic powerup drop.""" from bastd.actor import powerupbox if standard_points: spawnpoints = self.map.powerup_spawn_points for i, _point in enumerate(spawnpoints): ba.timer(1.0 + i * 0.5, ba.Call(self._drop_powerup, i, poweruptype)) else: point = (self._powerup_center[0] + random.uniform( -1.0 * self._powerup_spread[0], 1.0 * self._powerup_spread[0]), self._powerup_center[1], self._powerup_center[2] + random.uniform( -self._powerup_spread[1], self._powerup_spread[1])) # Drop one random one somewhere. powerupbox.PowerupBox( position=point, poweruptype=powerupbox.get_factory().get_random_powerup_type( excludetypes=self._exclude_powerups)).autoretain()
def _drop_powerups(self, standard_points: bool = False, force_first: str = None) -> None: """Generic powerup drop.""" from bastd.actor import powerupbox if standard_points: pts = self.map.powerup_spawn_points for i in range(len(pts)): ba.timer( 1.0 + i * 0.5, ba.WeakCall(self._drop_powerup, i, force_first if i == 0 else None)) else: drop_pt = (self._powerup_center[0] + random.uniform( -1.0 * self._powerup_spread[0], 1.0 * self._powerup_spread[0]), self._powerup_center[1], self._powerup_center[2] + random.uniform( -self._powerup_spread[1], self._powerup_spread[1])) # Drop one random one somewhere. powerupbox.PowerupBox( position=drop_pt, poweruptype=powerupbox.get_factory().get_random_powerup_type( excludetypes=self._excludepowerups)).autoretain()