Example #1
0
    def draw(self, surf, gameStateObj):
        """Assumes image has already been developed."""
        image = self.create_image(self.image_state)
        x, y = self.unit.position
        left = x * GC.TILEWIDTH + self.spriteOffset[0]
        top = y * GC.TILEHEIGHT + self.spriteOffset[1]

        # Active Skill Icon
        if not self.unit.isDying:
            for status in self.unit.status_effects:
                if (status.combat_art and status.combat_art.check_charged()
                   and status.combat_art.get_max() > 0 and status.combat_art.is_activated()) \
                   or (status.activated_item and status.activated_item.check_charged()
                   and status.activated_item.get_max() > 0):
                    active_icon = GC.ICONDICT["ActiveSkill"]
                    active_icon = Engine.subsurface(active_icon, (GC.PASSIVESPRITECOUNTER.count*32, 0, 32, 32))
                    topleft = (left - max(0, (active_icon.get_width() - 16)//2), top - max(0, (active_icon.get_height() - 16)//2))
                    surf.blit(active_icon, topleft)
                    break

        if self.transition_state in WARP_OUT_SET:
            if self.unit.deathCounter:
                image = Image_Modification.flickerImageWhiteColorKey(image, 255)
                image = Image_Modification.flickerImageTranslucentColorKey(image, int(100*self.unit.deathCounter//27))
            else:
                image = Image_Modification.flickerImageTranslucentColorKey(image, 100 - self.transition_counter//(self.transition_time//100))
        elif self.transition_state == 'warp_in' or self.transition_state == 'fade_in':
            image = Image_Modification.flickerImageTranslucentColorKey(image, self.transition_counter//(self.transition_time//100))
        
        if self.unit.flicker:
            color = self.unit.flicker[2]
            total_time = self.unit.flicker[1]
            starting_time = self.unit.flicker[0]
            time_passed = Engine.get_time() - starting_time
            if time_passed >= total_time:
                self.unit.end_flicker()
            else:
                color = ((total_time - time_passed)*float(c)//total_time for c in color)
                #  image = Image_Modification.flicker_image(image.convert_alpha(), color)
                image = Image_Modification.change_image_color(image.convert_alpha(), color)
        elif self.unit.flickerRed and gameStateObj.boundary_manager.draw_flag:
            image = Image_Modification.flickerImageRed(image.convert_alpha(), 80)
        # if any(status.unit_translucent for status in self.unit.status_effects):
        if 'unit_translucent' in self.unit.status_bundle:
            image = Image_Modification.flickerImageTranslucentColorKey(image, 50)

        if 'unit_tint' in self.unit.status_bundle:
            for status in self.unit.status_effects:
                if status.unit_tint:
                    color = status.unit_tint.color
                    time = Engine.get_time()
                    diff = Utility.determine_perc(time, status.unit_tint.period, status.unit_tint.width)
                    diff = Utility.clamp(255. * diff * status.unit_tint.max_alpha, 0, 255)
                    color = (color[0], color[1], color[2], diff)
                    image = Image_Modification.color_tint(image.convert_alpha(), color)            

        # Active Skill Indicator -- this flashes the unit yellow when a skill is charged
        # if not self.unit.isDying and 'ActiveSkillCharged' in self.unit.tags:
        #     time = Engine.get_time()
        #     length = 500
        #     if not (time//1000)%3 and not (time//length)%(1000//length):
        #         diff = time%length
        #         if diff > length//2:
        #             diff = length - diff
        #         diff = Utility.clamp(255. * diff / length * 2, 0, 255)
        #         color = (248, 248, -248, diff)
        #         image = Image_Modification.color_tint(image.convert_alpha(), color)

        # Turnwheel indicator -- this flashes the unit green
        if self.turnwheel_indicator:
            time = Engine.get_time()
            length = 200
            if not (time//200)%2 and not (time//length)%(200//length):
                diff = time%length
                if diff > length//2:
                    diff = length - diff
                diff = Utility.clamp(255. * diff / length * 2, 0, 255)
                color = (-120, 120, -120, diff)
                image = Image_Modification.color_tint(image.convert_alpha(), color)

        # What is this line even doing? - Something majorly important though
        # Each image has (self.image.get_width() - 32)/2 buffers on the left and right of it, to handle any off tile spriting
        # Without self.image.get_width() - 32)//2, we would output the left buffer along with the unit, 
        # and the unit would end up +left buffer width to the right of where it should be
        topleft = left - max(0, (image.get_width() - 16)//2), top - 24
        surf.blit(image, topleft)

        # =======
        # Status Aura Icon
        if not self.unit.isDying and 'aura' in self.unit.status_bundle:
            aura_icon_name = self.unit.team + 'AuraIcon'
            aura_icon = GC.IMAGESDICT[aura_icon_name] if aura_icon_name in GC.IMAGESDICT else GC.IMAGESDICT['AuraIcon']
            aura_icon = Engine.subsurface(aura_icon, (0, GC.PASSIVESPRITECOUNTER.count*10, 32, 10))
            topleft = (left - max(0, (aura_icon.get_width() - 16)//2), top - max(0, (aura_icon.get_height() - 16)//2) + 8)
            surf.blit(aura_icon, topleft)
        # Status always animationss
        for status in self.unit.status_effects:
            if status.always_animation:
                x, y = self.unit.position
                topleft = (x-1) * GC.TILEWIDTH + self.spriteOffset[0], (y-1) * GC.TILEHEIGHT + self.spriteOffset[1]
                surf.blit(status.always_animation.image, topleft)

        if self.transition_state.startswith('warp'):
            num_frames = 12
            fps = self.transition_time//num_frames
            frame = (self.transition_time - self.transition_counter)//fps
            if frame >= 0 and frame < num_frames:
                warp_anim = Engine.subsurface(GC.IMAGESDICT['Warp'], (frame*32, 0, 32, 48))
                topleft = (left - max(0, (warp_anim.get_width() - 16)//2), top - max(0, (warp_anim.get_height() - 16)//2) - 4)
                surf.blit(warp_anim, topleft)

        # Talk, Warning and Danger icons
        if gameStateObj.cursor.currentSelectedUnit:
            cur_unit = gameStateObj.cursor.currentSelectedUnit
            if (cur_unit.id, self.unit.id) in gameStateObj.talk_options:
                frame = (Engine.get_time()//100)%8
                topleft = (left - 1, top - 12)
                if frame in (0, 1, 2):
                    offset = 0
                elif frame in (3, 7):
                    offset = 1
                else:
                    offset = 2
                surf.blit(GC.IMAGESDICT['TalkMarker'], (topleft[0], topleft[1] + offset))
            elif self.unit.checkIfEnemy(cur_unit) and cur_unit.team == 'player':
                self.draw_warning_marker(surf, left, top, cur_unit)
            elif gameStateObj.support and gameStateObj.support.get_edge(cur_unit.id, self.unit.id):
                level = gameStateObj.support.get_edge(cur_unit.id, self.unit.id).get_support_level()
                if level > 0:
                    level = min(level, 3)
                    icon = Engine.subsurface(GC.IMAGESDICT['MapSupportIcons65'], ((level-1)*8, 0, 8, 11))
                    frame = (Engine.get_time()//100)%8
                    topleft = (left + 4, top - 11)
                    if frame in (0, 1, 2):
                        offset = 0
                    elif frame in (3, 7):
                        offset = 1
                    else:
                        offset = 2
                    # diff = Utility.determine_perc(Engine.get_time(), 2000, 2000)
                    # print(diff)
                    # diff = Utility.clamp(255. * diff, 0, 255)
                    # tint = (0, -64, 128, diff)
                    # icon = Image_Modification.color_tint(icon.copy(), tint)
                    surf.blit(icon, (topleft[0], topleft[1] + offset))
    def draw(self, surf, gameStateObj):
        """Assumes image has already been developed."""
        image = self.create_image(self.image_state)
        x, y = self.unit.position
        left = x * GC.TILEWIDTH + self.spriteOffset[0]
        top = y * GC.TILEHEIGHT + self.spriteOffset[1]

        # Active Skill Icon
        if not self.unit.isDying and 'ActiveSkillCharged' in self.unit.tags:
            active_icon = GC.ICONDICT["ActiveSkill"]
            active_icon = Engine.subsurface(
                active_icon, (GC.PASSIVESPRITECOUNTER.count * 32, 0, 32, 32))
            topleft = (left - max(0, (active_icon.get_width() - 16) // 2),
                       top - max(0, (active_icon.get_height() - 16) // 2))
            surf.blit(active_icon, topleft)

        if self.transition_state in WARP_OUT_SET:
            if self.unit.deathCounter:
                image = Image_Modification.flickerImageWhiteColorKey(
                    image, 255)
                image = Image_Modification.flickerImageTranslucentColorKey(
                    image, int(100 * self.unit.deathCounter // 27))
            else:
                self.transition_counter -= Engine.get_delta()
                if self.transition_counter < 0:
                    self.transition_counter = 0
                image = Image_Modification.flickerImageTranslucentColorKey(
                    image, 100 - self.transition_counter //
                    (self.transition_time // 100))
                if self.transition_counter <= 0:
                    if self.transition_state == 'fade_out':
                        self.transition_state = 'normal'
                        if self.state == 'fake_transition_out':
                            self.change_state('normal', gameStateObj)
                        self.unit.die(gameStateObj)
                    elif self.transition_state == 'fade_out_event':
                        self.transition_state = 'normal'
                        if self.state == 'fake_transition_out':
                            self.change_state('normal', gameStateObj)
                        self.unit.die(gameStateObj, event=True)
                    elif self.transition_state == 'warp_out':
                        gameStateObj.map.initiate_warp_flowers(
                            self.unit.position)
                        self.unit.die(gameStateObj, event=True)
                        self.transition_state = 'normal'
                        if self.state == 'fake_transition_out':
                            self.change_state('normal', gameStateObj)
                    elif self.transition_state in ('fade_move', 'warp_move'):
                        # gameStateObj.map.initiate_warp_flowers(self.unit.position)
                        self.unit.leave(gameStateObj)
                        self.unit.position = self.next_position
                        self.unit.previous_position = self.next_position
                        self.unit.arrive(gameStateObj)
                        gameStateObj.cursor.setPosition(
                            self.unit.position, gameStateObj)
                        # gameStateObj.stateMachine.changeState('move_camera')
                        self.next_position = None
                        gameStateObj.map.initiate_warp_flowers(
                            self.unit.position)
                        if self.transition_state == 'fade_move':
                            self.set_transition('fade_in')
                        elif self.transition_state == 'warp_move':
                            self.set_transition('warp_in')
        elif self.transition_state == 'warp_in' or self.transition_state == 'fade_in':
            self.transition_counter -= Engine.get_delta()
            if self.transition_counter < 0:
                self.transition_counter = 0
            image = Image_Modification.flickerImageTranslucentColorKey(
                image,
                self.transition_counter // (self.transition_time // 100))
            if self.transition_counter <= 0:
                self.transition_state = 'normal'
                if self.state == 'fake_transition_in':
                    self.change_state('normal', gameStateObj)

        if self.unit.flicker:
            color = self.unit.flicker[2]
            total_time = self.unit.flicker[1]
            starting_time = self.unit.flicker[0]
            time_passed = Engine.get_time() - starting_time
            if time_passed >= total_time:
                self.unit.end_flicker()
            else:
                color = ((total_time - time_passed) * float(c) // total_time
                         for c in color)
                #  image = Image_Modification.flicker_image(image.convert_alpha(), color)
                image = Image_Modification.change_image_color(
                    image.convert_alpha(), color)
        elif self.unit.flickerRed and gameStateObj.boundary_manager.draw_flag:
            image = Image_Modification.flickerImageRed(image.convert_alpha(),
                                                       80)
        # if any(status.unit_translucent for status in self.unit.status_effects):
        if 'unit_translucent' in self.unit.status_bundle:
            image = Image_Modification.flickerImageTranslucentColorKey(
                image, 50)

        if 'unit_tint' in self.unit.status_bundle:
            for status in self.unit.status_effects:
                if status.unit_tint:
                    color = status.unit_tint.color
                    time = Engine.get_time()
                    diff = Utility.determine_perc(time,
                                                  status.unit_tint.period,
                                                  status.unit_tint.width)
                    diff = Utility.clamp(
                        255. * diff * status.unit_tint.max_alpha, 0, 255)
                    color = (color[0], color[1], color[2], diff)
                    image = Image_Modification.color_tint(
                        image.convert_alpha(), color)

        # Active Skill Indicator -- this flashes the unit yellow when a skill is charged
        # if not self.unit.isDying and 'ActiveSkillCharged' in self.unit.tags:
        #     time = Engine.get_time()
        #     length = 500
        #     if not (time//1000)%3 and not (time//length)%(1000//length):
        #         diff = time%length
        #         if diff > length//2:
        #             diff = length - diff
        #         diff = Utility.clamp(255. * diff / length * 2, 0, 255)
        #         color = (248, 248, -248, diff)
        #         image = Image_Modification.color_tint(image.convert_alpha(), color)
        # What is this line even doing? - Something majorly important though
        # Each image has (self.image.get_width() - 32)/2 buffers on the left and right of it, to handle any off tile spriting
        # Without self.image.get_width() - 32)//2, we would output the left buffer along with the unit,
        # and the unit would end up +left buffer width to the right of where it should be
        topleft = left - max(0, (image.get_width() - 16) // 2), top - 24
        surf.blit(image, topleft)

        # =======
        # Status Aura Icon
        if not self.unit.isDying and 'aura' in self.unit.status_bundle:
            aura_icon_name = self.unit.team + 'AuraIcon'
            aura_icon = GC.IMAGESDICT[
                aura_icon_name] if aura_icon_name in GC.IMAGESDICT else GC.IMAGESDICT[
                    'AuraIcon']
            aura_icon = Engine.subsurface(
                aura_icon, (0, GC.PASSIVESPRITECOUNTER.count * 10, 32, 10))
            topleft = (left - max(0, (aura_icon.get_width() - 16) // 2),
                       top - max(0, (aura_icon.get_height() - 16) // 2) + 8)
            surf.blit(aura_icon, topleft)
        # Status always animationss
        for status in self.unit.status_effects:
            if status.always_animation:
                x, y = self.unit.position
                topleft = (x - 1) * GC.TILEWIDTH + self.spriteOffset[0], (
                    y - 1) * GC.TILEHEIGHT + self.spriteOffset[1]
                surf.blit(status.always_animation.image, topleft)

        if self.transition_state.startswith('warp'):
            num_frames = 12
            fps = self.transition_time // num_frames
            frame = (self.transition_time - self.transition_counter) // fps
            if frame >= 0 and frame < num_frames:
                warp_anim = Engine.subsurface(GC.IMAGESDICT['Warp'],
                                              (frame * 32, 0, 32, 48))
                topleft = (left - max(0, (warp_anim.get_width() - 16) // 2),
                           top - max(0,
                                     (warp_anim.get_height() - 16) // 2) - 4)
                surf.blit(warp_anim, topleft)

        # Talk, Warning and Danger icons
        if gameStateObj.cursor.currentSelectedUnit:
            cur_unit = gameStateObj.cursor.currentSelectedUnit
            if (cur_unit, self.unit.name) in gameStateObj.talk_options:
                frame = (Engine.get_time() // 100) % 8
                topleft = (left - 1, top - 12)
                if frame in (0, 1, 2):
                    offset = 0
                elif frame in (3, 7):
                    offset = 1
                else:
                    offset = 2
                surf.blit(GC.IMAGESDICT['TalkMarker'],
                          (topleft[0], topleft[1] + offset))
            if self.unit.checkIfEnemy(cur_unit):
                self.draw_warning_marker(surf, left, top, cur_unit)
    def draw(self, surf, gameStateObj):
        """Assumes image has already been developed."""
        image = self.create_image(self.image_state)
        x, y = self.unit.position
        left = x * GC.TILEWIDTH + self.spriteOffset[0]
        top = y * GC.TILEHEIGHT + self.spriteOffset[1]

        # Active Skill Icon
        if not self.unit.isDying and 'ActiveSkillCharged' in self.unit.tags:
            active_icon = GC.ICONDICT["ActiveSkill"]
            active_icon = Engine.subsurface(
                active_icon, (GC.PASSIVESPRITECOUNTER.count * 32, 0, 32, 32))
            topleft = (left - max(0, (active_icon.get_width() - 16) / 2),
                       top - max(0, (active_icon.get_height() - 16) / 2))
            surf.blit(active_icon, topleft)

        if self.transition_state in WARP_OUT_SET:
            if self.unit.deathCounter:
                image = Image_Modification.flickerImageWhiteColorKey(
                    image, 255)
                image = Image_Modification.flickerImageTranslucentColorKey(
                    image, int(100 * self.unit.deathCounter / 27))
            else:
                self.transition_counter -= Engine.get_delta()
                if self.transition_counter < 0:
                    self.transition_counter = 0
                image = Image_Modification.flickerImageTranslucentColorKey(
                    image, 100 - self.transition_counter /
                    (self.transition_time / 100))
                if self.transition_counter <= 0:
                    if self.transition_state == 'fade_out':
                        self.transition_state = 'normal'
                        if self.state == 'fake_transition_out':
                            self.change_state('normal', gameStateObj)
                        self.unit.die(gameStateObj, event=True)
                    elif self.transition_state == 'warp_out':
                        gameStateObj.map.initiate_warp_flowers(
                            self.unit.position)
                        self.unit.die(gameStateObj, event=True)
                        self.transition_state = 'normal'
                        if self.state == 'fake_transition_out':
                            self.change_state('normal', gameStateObj)
                    elif self.transition_state in ('fade_move', 'warp_move'):
                        gameStateObj.map.initiate_warp_flowers(
                            self.unit.position)
                        self.unit.leave(gameStateObj)
                        self.unit.position = self.next_position
                        self.unit.arrive(gameStateObj)
                        self.next_position = None
                        gameStateObj.map.initiate_warp_flowers(
                            self.unit.position)
                        if self.transition_state == 'fade_move':
                            self.set_transition('fade_in')
                        elif self.transition_state == 'warp_move':
                            self.set_transition('warp_in')
        elif self.transition_state == 'warp_in' or self.transition_state == 'fade_in':
            self.transition_counter -= Engine.get_delta()
            if self.transition_counter < 0:
                self.transition_counter = 0
            image = Image_Modification.flickerImageTranslucentColorKey(
                image, self.transition_counter / (self.transition_time / 100))
            if self.transition_counter <= 0:
                self.transition_state = 'normal'
                if self.state == 'fake_transition_in':
                    self.change_state('normal', gameStateObj)
        elif self.unit.flicker:
            color = self.unit.flicker[2]
            total_time = self.unit.flicker[1]
            starting_time = self.unit.flicker[0]
            time_passed = Engine.get_time() - starting_time
            if time_passed >= total_time:
                self.unit.end_flicker()
            else:
                color = ((total_time - time_passed) * float(c) / total_time
                         for c in color)
                #  image = Image_Modification.flicker_image(image.convert_alpha(), color)
                image = Image_Modification.change_image_color(
                    image.convert_alpha(), color)
        elif self.unit.flickerRed and gameStateObj.boundary_manager.draw_flag:
            image = Image_Modification.flickerImageRed(image.convert_alpha(),
                                                       80)
        # if any(status.unit_translucent for status in self.unit.status_effects):
        if 'unit_translucent' in self.unit.status_bundle:
            image = Image_Modification.flickerImageTranslucentColorKey(
                image, 50)
        # What is this line even doing? - Something majorly important though
        # Each image has (self.image.get_width() - 32)/2 buffers on the left and right of it, to handle any off tile spriting
        # Without self.image.get_width() - 32)/2, we would output the left buffer along with the unit,
        # and the unit would end up +left buffer width to the right of where it should be
        topleft = left - max(0, (image.get_width() - 16) / 2), top - 24
        surf.blit(image, topleft)

        # =======
        # Status Aura Icon
        if not self.unit.isDying and 'aura' in self.unit.status_bundle:
            aura_icon_name = self.unit.team + 'AuraIcon'
            aura_icon = GC.IMAGESDICT[
                aura_icon_name] if aura_icon_name in GC.IMAGESDICT else GC.IMAGESDICT[
                    'AuraIcon']
            aura_icon = Engine.subsurface(
                aura_icon, (0, GC.PASSIVESPRITECOUNTER.count * 10, 32, 10))
            topleft = (left - max(0, (aura_icon.get_width() - 16) / 2),
                       top - max(0, (aura_icon.get_height() - 16) / 2) + 8)
            surf.blit(aura_icon, topleft)
        # Status always animationss
        for status in self.unit.status_effects:
            if status.always_animation:
                x, y = self.unit.position
                topleft = (x - 1) * GC.TILEWIDTH + self.spriteOffset[0], (
                    y - 1) * GC.TILEHEIGHT + self.spriteOffset[1]
                surf.blit(status.always_animation.image, topleft)

        if self.transition_state.startswith('warp'):
            num_frames = 12
            fps = self.transition_time / num_frames
            frame = (self.transition_time - self.transition_counter) / fps
            if frame >= 0 and frame < num_frames:
                warp_anim = Engine.subsurface(GC.IMAGESDICT['Warp'],
                                              (frame * 32, 0, 32, 48))
                topleft = (left - max(0, (warp_anim.get_width() - 16) / 2),
                           top - max(0, (warp_anim.get_height() - 16) / 2) - 4)
                surf.blit(warp_anim, topleft)

        if gameStateObj.cursor.currentSelectedUnit and (
                gameStateObj.cursor.currentSelectedUnit.name,
                self.unit.name) in gameStateObj.talk_options:
            frame = (Engine.get_time() / 100) % 8
            topleft = (left + 6, top - 12)
            surf.blit(
                Engine.subsurface(GC.IMAGESDICT['TalkMarker'],
                                  (frame * 8, 0, 8, 16)), topleft)