def __init__(self, logic_manager): super().__init__( img=ResourceManager.load_image(ResourceClass.UI, "panel.png")) self._actor = None self._logic_manager = logic_manager self.widget_id = "guardian_panel" self._upgrade_button = UpgradeButton(None, self._logic_manager) self._upgrade_button.position_attach_type = PositionAttachType.CENTER self._upgrade_button.position = Vector2(50, 164) self._coins = Text(text="") self._coins.position_attach_type = PositionAttachType.CENTER self._coins.position = Vector2(150, 164) self._coins_icon = Panel( img=ResourceManager.load_image(ResourceClass.UI, "coins.png")) self._coins_icon.position_attach_type = PositionAttachType.CENTER self._coins_icon.position = Vector2(200, 164) self._guardian_name = Text("", size=16) self._guardian_name.position_attach_type = PositionAttachType.CENTER self._guardian_name.position = Vector2(142, 18) self._guardian_level = Text("", size=48) self._guardian_level.position_attach_type = PositionAttachType.CENTER self._guardian_level.position = Vector2(142, 77) self.add_child(self._guardian_name) self.add_child(self._guardian_level) self.add_child(self._upgrade_button) self.add_child(self._coins) self.add_child(self._coins_icon) self.visible = False
def __init__(self, actor, logic_manager): super().__init__( img=ResourceManager.load_image(ResourceClass.UI, "upgrade.png"), disabled_img=ResourceManager.load_image(ResourceClass.UI, "upgrade-disabled.png")) self._actor = actor self._logic_manager = logic_manager self.z = 2 self._click_callback = self.clicked
def __init__(self): super().__init__(Base.PROPERTIES) set_animations(self, 'base') self.base_statistics.speed = 0 self.base_statistics.attack_range = 100 self.base_statistics.hit_effects = [('HitEffect', {'damage': 50})] self.base_statistics.bullet_speed = 500 self.base_statistics.bullet_image = 'small-knife.png' self.base_statistics.max_health = self.hp = 200 self.recalculate_statistics() self._play_current_animation() self.rect.width = 64 self.rect.height = 64 self.add_controller(DeathController()) self.add_controller(NotRotatingRangeAttackController()) self.set_ai(StandardAI()) stats = copy.deepcopy(self._base_statistics) stats.hit_effects = [('HitEffect', { 'damage': 70 }), ('SlowEffect', { 'time': 1, 'percent': 0.8 })] self.add_evolution_level( stats, 1000, { ActorState.ATTACK: ResourceManager.load_animation(ResourceClass.CHARACTERS, 'base-attack-1.json') })
def __init__(self, owner): super().__init__() self._target = None self._owner = owner self._start_position = Vector2(owner.position) self._speed = owner.statistics.bullet_speed self.sprite = ResourceManager.load_image(ResourceClass.BULLETS, owner.statistics.bullet_image)
def __init__(self, logic_manager): super().__init__() self._logic_manager = logic_manager self._gold_icon = Panel( img=ResourceManager.load_image(ResourceClass.UI, "coins.png")) self._gold_text = Text("") self._gold_text.position = Vector2(24, 0) self.add_child(self._gold_icon) self.add_child(self._gold_text)
def initialise(self, **kwargs): image = ResourceManager.load_image(ResourceClass.UI, 'main-menu-bg.jpg') panel = Panel(img=pygame.transform.scale(image, (1024, 768))) start_button = Button("Start Game", color=(255, 255, 255), size=44) start_button.click_callback = self.start_game start_button.position_attach_type = PositionAttachType.CENTER start_button.position = Vector2(self._ui_manager.window_size.x / 2, self._ui_manager.window_size.y / 2) start_button.z = 1 panel.z = 0 self._ui_manager.add_widget(start_button) self._ui_manager.add_widget(panel)
def set_animations(actor, animation_name_prefix): """ Creates all animations set based on animation_name_prefix :param actor: :param animation_name_prefix: :return: """ actor.set_animation( ActorState.IDLE, ResourceManager.load_animation(ResourceClass.CHARACTERS, animation_name_prefix + '-idle.json')) actor.set_animation( ActorState.MOVE, ResourceManager.load_animation(ResourceClass.CHARACTERS, animation_name_prefix + '-move.json')) actor.set_animation( ActorState.ATTACK, ResourceManager.load_animation(ResourceClass.CHARACTERS, animation_name_prefix + '-attack.json')) actor.set_animation( ActorState.DEATH, ResourceManager.load_animation(ResourceClass.CHARACTERS, animation_name_prefix + '-death.json'))
def text(self, text): """ Text value setter :param text: :return: """ if text is not None: self._text = text self._font = pygame.font.Font( ResourceManager.get_path(ResourceClass.UI, "monotype-corsiva.ttf"), self._size) self._surface = self._font.render(text, True, self._color) self._rect.width = self._surface.get_width() self._rect.height = self._surface.get_height() self.position_changed()
def initialise(self, **kwargs): self._load_level(kwargs['filename']) self._logic_manager = LogicManager( self._level_data['start_properties'], self._app) self.level = Level(self._ui_manager.window_size, self._logic_manager) self.level.load(self._level_data['map_file']) self._creatures_factory = CreaturesFactory(self.level) self._wave_manager = WaveManager(factory=self._creatures_factory) self._wave_manager.load(self._level_data['wave_file']) self._logic_manager.wave_manager = self._wave_manager self._game_window = GameWindow(self._ui_manager.window_size.x, self._ui_manager.window_size.y) self._action_manager = ActionManager(self._game_window, self.level, self._creatures_factory, self._logic_manager, self._ui_manager) self._ui_manager.add_widget(self._game_window) self._ui_manager.focus_widget(self._game_window) self._logical_effect_manager = LogicEffectManager(self.level) add_button = GameActionButton(img=ResourceManager.load_image( ResourceClass.UI, 'add-button.png'), action_name="AddTower", action_manager=self._action_manager, tower='Bandit') add_button.position = Vector2(900, 650) self._ui_manager.add_widget(add_button) panel = GuardianPanel(self._logic_manager) panel.position = Vector2(375, 536) self._ui_manager.add_widget(panel) self._ui_manager.add_widget(PlayerInfoPanel(self._logic_manager)) health_panel = PlayerHealthPanel(self.level.base) health_panel.position_attach_type = PositionAttachType.CENTER health_panel.position = Vector2(self._ui_manager.window_size.x / 2, 35) self._ui_manager.add_widget(health_panel)
def __init__(self, base): super().__init__(img=ResourceManager.load_image(ResourceClass.UI, "base-health-panel.png")) self._health_progress = ProgressBarDrawer( ResourceManager.load_image(ResourceClass.UI, "base-health-bar.png")) self._base = base
def __init__(self, actor=None): self._actor = actor self._background = ResourceManager.load_image( ResourceClass.UI, 'health-bar-background.png') self._progress = ProgressBarDrawer( ResourceManager.load_image(ResourceClass.UI, 'health-bar.png'))