Exemplo n.º 1
0
 def __init__(
     self,
     name: str,
     background: BaseTexture,
     pass_map: PassMap,
     triggers: List[Trigger],
     player_position: Vector,
     scripts: Mapping[str, Callable[[], None]],
     path: Path,
     save_point: Optional[Object],
 ):
     self.name = name
     self.background = background
     self.pass_map = pass_map
     self.trigger_event_watchers = [
         TriggerEventWatcher(trigger) for trigger in triggers
     ]
     self.player = Player(player_position)
     self.scripts = scripts
     self.path = path
     self.objects: WalList[Object] = WalList([])
     self.named_objects: Dict[str, Object] = {}
     self.state: dict = {}
     self.sprites: WalList[BaseSprite] = WalList([])
     self.save_point = save_point
     if save_point is not None:
         self.add_object(save_point)
     self._update_callbacks: WalList[Callable[[float], None]] = WalList([])
     get_event_manager().subscribe('key:confirm',
                                   Subscriber(self.on_interact))
Exemplo n.º 2
0
 def __init__(self, fight_script: 'FightScript'):
     super().__init__(fight_script)
     self.board_texture = load_texture(Path('.') / 'assets' / 'fight' / 'bullet_board.png')
     self.heart_texture = load_texture(Path('.') / 'assets' / 'fight' / 'heart.png')
     self.hit_heart_texture = load_texture(Path('.') / 'assets' / 'fight' / 'hit_heart.png')
     self.row = 4
     self.col = 4
     self.movement_state = MovementState(
         coords = self.get_coords_at(self.row, self.col),
         movement_length = 0.15,
         mapping = Mappings.ease_out,
     )
     self.sprites: WalList[BaseSprite] = WalList([])
     self.unrestricted_sprites: WalList[BaseSprite] = WalList([])
     self._last_time_player_hit: Optional[float] = None
     self._timeout_event: Any = None
Exemplo n.º 3
0
    def __init__(self, battle: EnemyBattle):
        # TODO: Rewrite this code since it is absolutely unmaintainable.
        # Some objects start using FightScript before it is fully constructed,
        # which leads to complete nightmare with undefined attributes,
        # which aren't catchable by mypy.
        self.battle = battle
        self.textures = {
            texture_name: _load_texture(battle.root, texture_filename)
            for texture_name, texture_filename in battle.data.get(
                'textures', {}).items()
        }
        self.state: dict = {}

        hp: int = battle.data['hp']
        damage_by_weapon: Dict[str,
                               int] = battle.data.get('damage_by_weapon', {})
        name: str = battle.data['name']

        self.sprites: WalList[BaseSprite] = WalList([])
        self.enemy = Enemy(
            hp=hp,
            damage_by_weapon=damage_by_weapon,
            #attack = attack,
            name=name,
            normal_texture=self.get_enemy_normal_texture(),
            wounded_texture=self.get_enemy_wounded_texture(),
            pos=self.get_enemy_pos(),
            fight_script=self,
        )
        self._has_spared: bool = False
        self.bullet_board: Optional['BulletBoard'] = None
        self._bullet_spawner: Optional['BulletSpawner'] = None
        self.elements: WalList[ElementProtocol] = WalList([
            EnemyNameIndicator(self.enemy, fight_script=self),
            FightHpIndicator(self, pg.Rect(350, 550, 100, 30)),
            EnemyHpIndicator(self.enemy, self, pg.Rect(300, 15, 200, 30)),
        ])
Exemplo n.º 4
0
    def raise_event(self, event_id: EventId, argument: Any = None, silent: bool = False):
        if not silent:
            logger.debug('EventManager: raise_event: `{}` with argument `{}`', event_id, argument)

        subscribers = self.subscribers.get(event_id, WalList([]))
        with subscribers:
            for sub in subscribers:
                sub.handler(event_id, argument)
            subscribers.filter(lambda x: x.is_persistent, now=True)
        if len(subscribers) == 0:
            self.subscribers.pop(event_id, None)

        with self.any_subscribers:
            for sub in self.any_subscribers:
                sub.handler(event_id, argument)
            self.any_subscribers.filter(lambda sub: sub.is_persistent, now=True)
Exemplo n.º 5
0
class SpawnerManager:
    def __init__(self):
        self.spawners = WalList([])
        self.madecs = WalList([])
        self._is_frozen = False

    def add_spawner(self, **kwargs):
        self.spawners.append(Spawner(**kwargs, manager=self))

    def register(self, madec):
        self.madecs.append(madec)

    def freeze(self):
        self._is_frozen = True

    def unfreeze(self):
        self._is_frozen = False

    def is_frozen(self):
        return self._is_frozen

    def kill_all(self):
        with self.madecs:
            for madec in self.madecs:
                madec.kill()

        self.madecs.filter(lambda x: False)

    def clear(self):
        self.kill_all()
        self.unfreeze()

    def update(self, time_delta):
        with self.spawners:
            for s in self.spawners:
                s.update(time_delta)

        self.madecs.filter(lambda x: x.is_alive())
Exemplo n.º 6
0
 def __init__(self, game: 'Game'):
     self.game = game
     self.sprites: WalList[BaseSprite] = WalList([])
Exemplo n.º 7
0
 def subscribe(self, event_id: EventId, subscriber: Subscriber):
     logger.debug('EventManager: subscribe: `{}`', event_id)
     ls = self.subscribers.setdefault(event_id, WalList([]))
     with ls:
         ls.append(subscriber)
Exemplo n.º 8
0
 def __init__(self):
     self.subscribers: Dict[EventId, WalList[Subscriber]] = {}
     self.any_subscribers: WalList[Subscriber] = WalList([])
     self._counter = 0
Exemplo n.º 9
0
 def __init__(self):
     self.spawners = WalList([])
     self.madecs = WalList([])
     self._is_frozen = False