Ejemplo n.º 1
0
    def draw(self, surf, camera_offset, progress=1):
        current_time = pygame.time.get_ticks()%2000

        progress = Utility.clamp(progress, 0, 1)
        image = self.surf.copy()
        units = self.pin_surf
        # Flicker pin surf
        if current_time > 1600:
            whiteness = 2.55 * (100 - abs(current_time - 1800)/2)
            units = Image_Modification.flickerImageWhite(units, whiteness)
        image.blit(units, (0,0))

        if progress != 1:
            image = self.occlude(image.copy(), progress)

        # TODO make minimaps work with even bigger maps (current limit is 60x40)
        pos = (WINWIDTH/2 - image.get_width()/2, WINHEIGHT/2 - image.get_height()/2)
        surf.blit(image, pos)
        x = camera_offset.x
        y = camera_offset.y
        cursor_pos = pos[0] + x*self.scale_factor - 1, pos[1] + y*self.scale_factor - 1
        if progress == 1:
            minimap_cursor = self.minimap_cursor
            if current_time > 1600 or (current_time > 600 and current_time < 1000):
                if current_time > 1600:
                    whiteness = 2.55 * (100 - abs(current_time - 1800)/2)
                else:
                    whiteness = 2.55 * (100 - abs(current_time - 800)/2)
                minimap_cursor = Image_Modification.flickerImageWhite(minimap_cursor, whiteness)
            surf.blit(minimap_cursor, cursor_pos)
Ejemplo n.º 2
0
 def update(self):
     new_time = float(Engine.get_time() - self.start_time)
     # Totally transparent start_up
     if self.state == -1:
         if new_time > self.init_time:
             self.state = 0
     # Initial bouncing and fading in
     if self.state == 0:
         state_time = new_time - self.init_time
         # Position
         self.top_pos = 10 * math.exp(-state_time/250) * math.sin(state_time/25)
         # Transparency
         new_transparency = max(0, (200 - state_time)/2)
         if new_transparency > 0:
             self.image = Image_Modification.flickerImageTranslucent(self.true_image, new_transparency)
         else:
             self.image = self.true_image
         if state_time > 400:
             self.state = 1
             self.top_pos = 0
     # Pause
     if self.state == 1:
         if new_time - self.init_time > 1000:
             self.state = 2
     # Fade out and up
     if self.state == 2:
         state_time = new_time - self.init_time - 1000
         # Position
         self.top_pos = state_time/10
         # Transparency
         new_transparency = state_time/2
         self.image = Image_Modification.flickerImageTranslucent(self.true_image, new_transparency)
         if new_time > 1200:
             self.done = True
Ejemplo n.º 3
0
    def draw(self, surf, camera_offset, progress=1):
        current_time = Engine.get_time()%2000

        progress = Utility.clamp(progress, 0, 1)
        image = Engine.copy_surface(self.surf)
        units = self.pin_surf
        # Flicker pin surf
        if current_time > 1600:
            whiteness = 2.55 * (100 - abs(current_time - 1800)/2)
            units = Image_Modification.flickerImageWhite(units, whiteness)
        image.blit(units, (0, 0))

        if progress != 1:
            image = self.occlude(Engine.copy_surface(image), progress)

        # TODO make minimaps work with even bigger maps (current limit is 60x40)
        pos = (GC.WINWIDTH/2 - image.get_width()/2, GC.WINHEIGHT/2 - image.get_height()/2)
        surf.blit(image, pos)
        x = camera_offset.x
        y = camera_offset.y
        cursor_pos = pos[0] + x*self.scale_factor - 1, pos[1] + y*self.scale_factor - 1
        if progress == 1:
            minimap_cursor = self.minimap_cursor
            if current_time > 1600 or (current_time > 600 and current_time < 1000):
                if current_time > 1600:
                    whiteness = 2.55 * (100 - abs(current_time - 1800)/2)
                else:
                    whiteness = 2.55 * (100 - abs(current_time - 800)/2)
                minimap_cursor = Image_Modification.flickerImageWhite(minimap_cursor, whiteness)
            surf.blit(minimap_cursor, cursor_pos)
Ejemplo n.º 4
0
    def draw(self, surf, gameStateObj):
        self.write_index = 6
        if not self.surf:
            bg_surf = MenuFunctions.CreateBaseMenuSurf(
                self.size, 'BaseMenuBackgroundOpaque')
            self.surf = Engine.create_surface(
                (self.size[0] + 2, self.size[1] + 4),
                convert=True,
                transparent=True)
            self.surf.blit(bg_surf, (2, 4))
            self.surf.blit(GC.IMAGESDICT['SmallGem'], (0, 0))
            Image_Modification.flickerImageTranslucent(self.surf, 10)
        BGSurf = self.surf.copy()

        # Center it
        pos = surf.get_width() // 2 - self.size[0] // 2 - 2, surf.get_height(
        ) // 2 - self.size[1] // 2 - 4
        # Blit words
        for index, word in enumerate(self.banner):
            word_width = GC.FONT[self.banner_font[index]].size(word)[0]
            GC.FONT[self.banner_font[index]].blit(
                word, BGSurf, (self.write_index,
                               self.size[1] // 2 - self.font_height // 2 + 4))
            self.write_index += word_width
        # Blit item icon
        if self.item:
            self.item.draw(BGSurf, (self.size[0] - 6 - 16 - 2, 4 + 4),
                           cooldown=False)
        surf.blit(BGSurf, pos)
Ejemplo n.º 5
0
 def draw(self, surf):
     if self.show and self.fade < 100:
         self.fade += self.transition_speed
         for sprite in self.sprites:
             sprite.image = Image_Modification.flickerImageTranslucentColorKey(sprite.true_image, 100 - self.fade)
     elif not self.show and self.fade > 0:
         self.fade -= self.transition_speed
         for sprite in self.sprites:
             sprite.image = Image_Modification.flickerImageTranslucentColorKey(sprite.true_image, 100 - self.fade)
     # Now actually draw
     for sprite in self.sprites:
         sprite.draw(surf)
Ejemplo n.º 6
0
    def begin(self, gameStateObj, metaDataObj):
        if not self.started:
            # Get units to display
            self.units = [unit for unit in gameStateObj.allunits if unit.position and unit.team == 'player']

            self.bg_surf = Image_Modification.flickerImageTranslucent(GC.IMAGESDICT['UnitMenuBackground'], 10)
            self.title_bg = Image_Modification.flickerImageTranslucent(GC.IMAGESDICT['TitleBar'], 10)
            self.background = MenuFunctions.MovingBackground(GC.IMAGESDICT['RuneBackground'])
            self.states = [('Character', ['Class', 'Lv', 'Exp', 'HP', 'Max'], [4, 66, 89, 113, 133]),
                           ('Fighting Skill', ['STR', 'MAG', 'SKL', 'SPD', 'LCK', 'DEF', 'RES'], [4, 26, 48, 71, 94, 119, 142]),
                           ('Equipment', ['Equip', 'Atk', 'Hit', 'Avoid'], [16, 72, 103, 136]),
                           ('Personal Data', ['MOV', 'CON', 'Aid', 'Rat', 'Trv'], [4, 33, 60, 82, 106]),
                           ('Weapon Level', Weapons.TRIANGLE.types, [9 + idx*16 for idx in range(len(Weapons.TRIANGLE.types))])]
            if cf.CONSTANTS['support']:
                self.states.append(('Support Chance', ['Ally'], [0]))
            self.state_index = 0
            self.prev_state_index = 0
            self.unit_index = 1 # 0 means on banner
            self.scroll_index = 1
            self.banner_index = 0
            self.num_per_page = 6

            self.state_scroll = 0
            self.scroll_direction = 0

            self.weapon_icons = [Weapons.Icon(weapon) for weapon in Weapons.TRIANGLE.types]
            self.help_boxes = []
            self.info = False

            self.scroll_bar = GUIObjects.ScrollBar((233, 59))
            self.left_arrow = GUIObjects.ScrollArrow('left', (7, 41))
            self.right_arrow = GUIObjects.ScrollArrow('right', (GC.WINWIDTH - 7 - 8, 41), 0.5)

            # For sort
            self.current_sort = 'Name'
            self.descending = False
            self.sort_surf = MenuFunctions.CreateBaseMenuSurf((64, 24))
            self.sort_surf = Image_Modification.flickerImageTranslucent(self.sort_surf, 10)
            self.sort_arrow_counter = Counters.ArrowCounter()
            self.sort_arrow_counter.arrow_anim = [0, 1, 2]
            self.sort()

            # Transition in:
            gameStateObj.stateMachine.changeState("transition_in")
            return 'repeat'
        else:
            chosen_unit = gameStateObj.info_menu_struct['chosen_unit']
            if chosen_unit and chosen_unit in self.units:
                self.move_to_unit(chosen_unit)
            gameStateObj.info_menu_struct['chosen_unit'] = None
Ejemplo n.º 7
0
 def draw(self, surf, topleft, white=False, cooldown=False):
     ItemSurf = self.image
     if white:
         ItemSurf = Image_Modification.transition_image_white(ItemSurf)
     ItemRect = ItemSurf.get_rect()
     ItemRect.topleft = topleft
     surf.blit(ItemSurf, ItemRect)
Ejemplo n.º 8
0
    def draw(self, gameStateObj):
        text_lines = self.split_string(self.eval_string(self.display_name_string, gameStateObj))

        longest_surf_width = self.get_size(text_lines)

        if longest_surf_width != self.surf_width or len(text_lines) != self.num_lines:
            self.num_lines = len(text_lines)
            self.surf_width = longest_surf_width
            surf_height = 16 * self.num_lines + 8

            # Blit background
            BGSurf = MenuFunctions.CreateBaseMenuSurf((self.surf_width + 16, surf_height), 'BaseMenuBackgroundOpaque')
            if self.num_lines == 1:
                BGSurf.blit(GC.IMAGESDICT['Shimmer1'], (BGSurf.get_width() - 1 - GC.IMAGESDICT['Shimmer1'].get_width(), 4))
            elif self.num_lines == 2:
                BGSurf.blit(GC.IMAGESDICT['Shimmer2'], (BGSurf.get_width() - 1 - GC.IMAGESDICT['Shimmer2'].get_width(), 4))
            self.BGSurf = Engine.create_surface((BGSurf.get_width(), BGSurf.get_height() + 3), transparent=True, convert=True)
            self.BGSurf.blit(BGSurf, (0, 3))
            gem = GC.IMAGESDICT['BlueCombatGem']
            self.BGSurf.blit(gem, (BGSurf.get_width()//2 - gem.get_width()//2, 0))
            # Now make translucent
            self.BGSurf = Image_Modification.flickerImageTranslucent(self.BGSurf, 20)

        temp_surf = self.BGSurf.copy()
        for index, line in enumerate(text_lines):
            position = temp_surf.get_width()//2 - GC.FONT['text_white'].size(line)[0]//2, 16 * index + 6
            GC.FONT['text_white'].blit(line, temp_surf, position)

        return temp_surf
Ejemplo n.º 9
0
 def draw(self, surf, topleft, white=False, cooldown=False):
     ItemSurf = self.image
     if white:
         ItemSurf = Image_Modification.flickerImageWhite(
             ItemSurf.convert_alpha(), abs(255 - Engine.get_time() % 510))
         # ItemSurf = Image_Modification.transition_image_white(ItemSurf)
     surf.blit(ItemSurf, topleft)
Ejemplo n.º 10
0
 def drawInvalid(self, surf):
     size_of_text = GC.FONT['text_white'].size("Invalid Choice!")
     width = size_of_text[0]
     height = size_of_text[1]
     pop_up_surf = MenuFunctions.CreateBaseMenuSurf((width + 16 - width%8, height + 16 - height%8))
     surf.blit(Image_Modification.flickerImageTranslucent(GC.IMAGESDICT['BlackBackground'].copy(), 60), (0, 0))
     topleft = (GC.WINWIDTH//2 - pop_up_surf.get_width()//2, GC.WINHEIGHT//2 - pop_up_surf.get_height()//2)
     surf.blit(pop_up_surf, topleft)
     position = (GC.WINWIDTH//2 - width//2, GC.WINHEIGHT//2 - height//2)
     GC.FONT['text_white'].blit(cf.WORDS["Invalid Choice"], surf, position)
Ejemplo n.º 11
0
 def drawInvalid(self, surf):
     size_of_text = FONT['text_white'].size("Invalid Choice!")
     width = size_of_text[0]
     height = size_of_text[1]
     pop_up_surf = MenuFunctions.CreateBaseMenuSurf((width + 16 - width%8, height + 16 - height%8))
     surf.blit(Image_Modification.flickerImageTranslucent(IMAGESDICT['BlackBackground'].copy(), 60), (0, 0))
     pop_up_rect = pop_up_surf.get_rect()
     pop_up_rect.center = (WINWIDTH/2, WINHEIGHT/2)
     surf.blit(pop_up_surf, pop_up_rect)
     position = (WINWIDTH/2 - width/2, WINHEIGHT/2 - height/2)
     FONT['text_white'].blit("Invalid Choice!", surf, position)
Ejemplo n.º 12
0
 def draw(self, surf, position):
     pos = (position[0] * GC.TILEWIDTH, position[1] * GC.TILEHEIGHT)
     surf.blit(self.image, pos)
     if self.new_image:
         self.fade += self.transition_speed
         new_image = Image_Modification.flickerImageTranslucentColorKey(self.new_image, 100 - self.fade)
         surf.blit(new_image, pos)
         if self.fade >= 100: # Done
             self.image_name = self.new_image_name
             self.position = self.new_position
             self.loadSprites()
             self.reset_transition()
Ejemplo n.º 13
0
    def draw(self, surf):
        currentTime = Engine.get_time()
        time_passed = currentTime - self.start_time
        if cf.OPTIONS['debug'] and time_passed < 0:
            logger.error('This phase has a negative time_passed! %s %s %s', time_passed, currentTime, self.start_time)
        max_opaque = 160

        # Blit the banner
        # position
        if time_passed < 100:
            offset = self.topleft[0] + 100 - time_passed
            trans = 100 - time_passed
        elif time_passed > self.display_time - 100:
            offset = self.topleft[0] + self.display_time - 100 - time_passed 
            trans = -(self.display_time - 100 - time_passed)
        else:
            offset = self.topleft[0]
            trans = 0
        # transparency
        image = Image_Modification.flickerImageTranslucent(self.image.copy(), trans)
        surf.blit(image, (offset, self.topleft[1]))
        
        # === Handle the transition
        most_dark_surf = Engine.subsurface(self.transition, (8*self.transition_size[0], 0, self.transition_size[0], self.transition_size[1])).copy()
        half_display_time = self.display_time//2
        # If we're in the first half
        if time_passed < half_display_time:
            transition_space = Engine.create_surface((GC.WINWIDTH, GC.WINHEIGHT//2 - 75//2 + time_passed//(half_display_time//20)), transparent=True)
            # Make more transparent based on time.
            alpha = int(max_opaque * time_passed/float(half_display_time))
            Engine.fill(most_dark_surf, (255, 255, 255, alpha), None, Engine.BLEND_RGBA_MULT)
        # If we're in the second half
        else:
            # Clamp time_passed at display time
            time_passed = min(self.display_time, time_passed)
            pos = (GC.WINWIDTH, GC.WINHEIGHT//2 - 75//2 + 40//2 - (time_passed - half_display_time)//(half_display_time//20))
            transition_space = Engine.create_surface(pos, transparent=True)
            # Make less transparent based on time.
            alpha = int(max_opaque - max_opaque*(time_passed - half_display_time)/float(half_display_time))
            alpha = min(255, max(0, alpha))
            Engine.fill(most_dark_surf, (255, 255, 255, alpha), None, Engine.BLEND_RGBA_MULT)
        # transition_space.convert_alpha()
        # Tile
        for x in range(0, transition_space.get_width(), 16):
            for y in range(0, transition_space.get_height(), 16):
                transition_space.blit(most_dark_surf, (x, y))

        # Now blit transition space
        surf.blit(transition_space, (0, 0))
        # Other transition_space
        surf.blit(transition_space, (0, GC.WINHEIGHT - transition_space.get_height()))
Ejemplo n.º 14
0
 def draw(self, surf, gameStateObj=None, blend=None):
     if self.on and self.frameCount >= 0 and Engine.get_time() > self.start_time:
         # The animation is too far to the right. Must move left. (" - 32")
         image = self.image
         x, y = self.position
         if self.ignore_map:
             topleft = x, y
         else:
             topleft = (x-gameStateObj.cameraOffset.x-1)*GC.TILEWIDTH, (y-gameStateObj.cameraOffset.y)*GC.TILEHEIGHT
         if blend:
             image = Image_Modification.change_image_color(image, blend)
         if self.tint:
             Engine.blit(surf, image, topleft, image.get_rect(), Engine.BLEND_RGB_ADD)
         else:
             surf.blit(image, topleft)
Ejemplo n.º 15
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 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)
Ejemplo n.º 16
0
 def draw(self, surf):
     surf.blit(Image_Modification.flickerImageTranslucent(self.sprite, self.transparency), (self.x, self.y))
Ejemplo n.º 17
0
 def draw(self, surf):
     surf.blit(
         Image_Modification.flickerImageTranslucent(self.sprite,
                                                    self.transparency),
         (self.x, self.y))
Ejemplo n.º 18
0
 def draw(self, surf):
     self.update()
     image = Image_Modification.flickerImageTranslucent(self.sprite.copy(), self.trans_value)
     surf.blit(image, (0, 0))
Ejemplo n.º 19
0
    def draw(self, surf, shake=(0, 0), range_offset=0, pan_offset=0):
        if self.state != 'Inert':
            # Screen flash
            if self.background and not self.blend:
                Engine.blit(surf, self.background, (0, 0), None,
                            Engine.BLEND_RGB_ADD)

            # Handle under children
            for child in self.under_children:
                child.draw(surf, (0, 0), range_offset, pan_offset)

            if self.current_frame is not None:
                image, offset = self.get_image(self.current_frame, shake,
                                               range_offset, pan_offset,
                                               self.static)
                # Move the animations in at the beginning and out at the end
                if self.entrance:
                    progress = (self.init_speed - self.entrance) / float(
                        self.init_speed)
                    new_size = (int(progress * image.get_width()),
                                int(progress * image.get_height()))
                    image = Engine.transform_scale(image, new_size)
                    if self.flash_color and self.flash_image:  # Make sure that flash image uses resized image
                        self.flash_image = image
                    diff_x = offset[0] - self.init_position[0]
                    diff_y = offset[1] - self.init_position[1]
                    offset = int(self.init_position[0] + progress * diff_x), \
                        int(self.init_position[1] + progress * diff_y)

                # Self flash
                if self.flash_color:
                    if not self.flash_image or isinstance(
                            self.flash_color, list):
                        if self.flash_color == 'gray':
                            self.flash_image = Image_Modification.gray_image(
                                image.convert_alpha())
                        elif isinstance(self.flash_color, list):
                            self.flash_image = Image_Modification.flicker_image(
                                image.convert_alpha(),
                                self.flash_color[self.flash_frames %
                                                 len(self.flash_color)])
                        else:
                            self.flash_image = Image_Modification.flicker_image(
                                image.convert_alpha(), self.flash_color)
                    self.flash_frames -= 1
                    image = self.flash_image
                    # If done
                    if self.flash_frames <= 0:
                        self.flash_color = None
                        self.flash_frames = 0
                        self.flash_image = None

                if self.opacity != 255:
                    if self.blend:
                        image = Image_Modification.flickerImageTranslucentBlend(
                            image, self.opacity)
                    else:
                        image = Image_Modification.flickerImageTranslucent255(
                            image.convert_alpha(), self.opacity)

                if self.background and self.blend:
                    old_bg = self.background.copy()
                    Engine.blit(old_bg, image, offset)
                    Engine.blit(surf, old_bg, (0, 0), None, self.blend)
                else:
                    Engine.blit(surf, image, offset, None, self.blend)

            # Handle children
            for child in self.children:
                child.draw(surf, (0, 0), range_offset, pan_offset)

            # Update and draw animations
            self.animations = [
                animation for animation in self.animations
                if not animation.update()
            ]
            for animation in self.animations:
                animation.draw(surf)

            # Screen flash
            if self.foreground:
                Engine.blit(surf, self.foreground, (0, 0), None,
                            Engine.BLEND_RGB_ADD)
                self.foreground_frames -= 1
                # If done
                if self.foreground_frames <= 0:
                    self.foreground = None
                    self.foreground_frames = 0

            if self.background:
                self.background_frames -= 1
                # If done
                if self.background_frames <= 0:
                    self.background = None
                    self.background_frames = 0
Ejemplo n.º 20
0
    def draw(self, surf, talk=False):
        current_time = pygame.time.get_ticks()
        """Assumes image has already been developed."""
        image = self.create_image(self.state)
        x, y = self.unit.position
        left = x * TILEWIDTH + self.spriteOffset[0]
        top = y * TILEHEIGHT + self.spriteOffset[1]

        # Active Skill Icon
        if not self.unit.isDying and any(status.active and status.active.required_charge and status.active.current_charge >= status.active.required_charge for status in self.unit.status_effects):
            active_icon = ICONDICT["ActiveSkill"]
            active_icon = active_icon.subsurface(pygame.Rect(SPRITECOUNTER.count*32, 0, 32, 32))
            iconRect = active_icon.get_rect()
            iconRect.topleft = (left - max(0, (active_icon.get_width() - 16)/2), top - max(0, (active_icon.get_height() - 16)/2))
            surf.blit(active_icon, iconRect)

        if self.unit.isDying:
            image = Image_Modification.flickerImageTranslucentColorKey(image, self.unit.deathCounter/2)
        elif self.unit.flickerWhite:
            total_time = self.unit.flickerWhite[1]
            starting_time = self.unit.flickerWhite[0]
            time_passed = current_time - starting_time
            if time_passed >= total_time:
                self.unit.end_flicker_white()
            else:
                whiteness = (total_time/2 - abs(time_passed - total_time/2))*255.0/(total_time/2)
                #image = Image_Modification.flickerImageWhiteColorKey(image, whiteness)
                image = Image_Modification.flickerImageWhite(image.convert_alpha(), whiteness)
        elif any(status.unit_translucent for status in self.unit.status_effects):
            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 he should be
        spaceRect = pygame.Rect(left - max(0, (image.get_width() - 16)/2), top - max(0, image.get_height() - 16), TILEWIDTH, TILEHEIGHT)
        surf.blit(image, spaceRect)
        # Health Bar
        if self.state in ['gray', 'passive'] and not self.unit.isDying:
            if (OPTIONS['HP Map Team'] == 'All') or (OPTIONS['HP Map Team'] == 'Ally' and self.unit.team in ['player', 'other']) or (OPTIONS['HP Map Team'] == 'Enemy' and self.unit.team.startswith('enemy')):
                if(OPTIONS['HP Map Cull'] == 'All') or (OPTIONS['HP Map Cull'] == 'Wounded' and self.unit.currenthp < self.unit.stats['HP']):
                    health_outline = IMAGESDICT['Map_Health_Outline']
                    health_bar = IMAGESDICT['Map_Health_Bar']
                    if(self.unit.currenthp == int(self.unit.stats['HP'])):
                        cut_off = 13
                    else:
                        cut_off = int((self.unit.currenthp/float(self.unit.stats['HP']))*12)
                    surf.blit(health_outline, (left, top+13))
                    health_bar = health_bar.subsurface((0, 0, cut_off, 1))
                    surf.blit(health_bar, (left+1, top+14))
        # Extra Icons
        if 'Boss' in self.unit.tags and self.state in ['gray', 'passive'] and int((current_time%4000)/400) in [0, 2, 4, 6, 8]: # Essentially an every 400 millisecond timer
            bossIcon = ICONDICT['BossIcon']
            surf.blit(bossIcon, (left, top))
        if self.unit.TRV:
            if self.unit.TRV.team == 'player':
                rescueIcon = ICONDICT['BlueRescueIcon']
            else: # self.TRV.team == 'other':
                rescueIcon = ICONDICT['GreenRescueIcon']
            iconRect = rescueIcon.get_rect()
            iconRect.topleft = (left - max(0, (rescueIcon.get_width() - 16)/2), top - max(0, (rescueIcon.get_height() - 16)/2))
            surf.blit(rescueIcon, iconRect)

        # =======
        # Status Aura Icon
        if not self.unit.isDying and any(status.aura for status in self.unit.status_effects):
            aura_icon_name = self.unit.team + 'AuraIcon'
            aura_icon = IMAGESDICT[aura_icon_name] if aura_icon_name in IMAGESDICT else IMAGESDICT['AuraIcon']
            aura_icon = aura_icon.subsurface(pygame.Rect(0, SPRITECOUNTER.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
                spaceRect = pygame.Rect((x-1) * TILEWIDTH + self.spriteOffset[0], (y-1) * TILEHEIGHT + self.spriteOffset[1], status.always_animation.image.get_width(), status.always_animation.image.get_height())
                surf.blit(status.always_animation.image, spaceRect)

        if self.unit.useWarp:
            num_frames = 12
            fps = 200/num_frames
            # Warp out
            if self.unit.isDying:
                frame = (self.unit.deathCounter-20)/fps
            else: # Warp in
                frame = ((current_time - self.unit.useWarp)/fps)
            if frame >= 0 and frame < num_frames:
                warp_anim = IMAGESDICT['Warp'].subsurface(pygame.Rect(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)
            elif frame >= num_frames:
                self.unit.useWarp = False

        if talk:
            frame = (current_time/100)%8
            topleft = (left + 6, top - 12)
            surf.blit(IMAGESDICT['TalkMarker'].subsurface(pygame.Rect(frame*8, 0, 8, 16)), topleft)
Ejemplo n.º 21
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))
Ejemplo n.º 22
0
    def draw(self, surf, gameStateObj):
        currentTime = Engine.get_time()
        # if should be displaying exp bar OR should be displaying level Up screen
        if self.state.getState() in [
                'exp_wait', 'exp_leave', 'exp0', 'exp100', 'init',
                'prepare_promote'
        ]:
            if self.exp_bar:
                self.exp_bar.draw(surf)

        elif self.state.getState() == 'levelUp':
            self.levelUpAnimation.draw(surf, gameStateObj)
            """
            marker1 = self.animationMarker[0]
            marker2 = self.animationMarker[1]
            LvlSurf = Engine.subsurface(self.levelUpAnimation, (marker2*78, marker1*16, 78, 16))
            x, y = self.unit.position
            topleft = (x-gameStateObj.cameraOffset.x-2)*GC.TILEWIDTH, (y-gameStateObj.cameraOffset.y-1)*GC.TILEHEIGHT
            surf.blit(LvlSurf, topleft)
            """

        elif self.state.getState() == 'levelScreen':
            # Highlight underline -- yellow, blue
            new_color = Image_Modification.color_transition2((88, 16, -40),
                                                             (-80, -32, 40))
            # Scroll out
            if currentTime - self.state_time > self.LEVELUPWAIT + (
                    self.get_num_sparks() + 1) * self.SPARKTIME + 300:
                self.unit_scroll_offset += 10
                self.screen_scroll_offset += 20
                self.animations = []
            else:  # scroll in
                if self.unit_scroll_offset:
                    self.lastSparkUpdate = currentTime - 300  # add 300 extra milliseconds of waiting at beginning
                self.unit_scroll_offset -= 10
                self.unit_scroll_offset = max(0, self.unit_scroll_offset)
                self.screen_scroll_offset -= 20
                self.screen_scroll_offset = max(0, self.screen_scroll_offset)

            DisplayWidth = self.levelUpScreen.get_width()
            DisplayHeight = self.levelUpScreen.get_height()
            # Level up screen
            LevelUpSurface = Engine.create_surface(
                (DisplayWidth, DisplayHeight), transparent=True, convert=True)
            # Create background
            LevelSurf = self.levelUpScreen
            LevelUpSurface.blit(LevelSurf, (0, 0))

            # Render top banner text
            long_name = gameStateObj.metaDataObj['class_dict'][
                self.unit.klass]['long_name']
            GC.FONT['text_white'].blit(long_name, LevelUpSurface, (12, 3))
            GC.FONT['text_yellow'].blit(
                cf.WORDS['Lv'], LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 12, 3))
            if self.first_spark_flag or self.force_level:
                level = str(self.unit.level)
            elif self.unit.level == 1:
                level = str(self.prev_level)
            else:
                level = str(self.unit.level - 1)
            GC.FONT['text_blue'].blit(level, LevelUpSurface,
                                      (LevelUpSurface.get_width() / 2 + 50 -
                                       GC.FONT['text_blue'].size(level)[0], 3))

            # Blit first spark
            if self.force_level and not self.first_spark_flag:
                self.first_spark_flag = True
                self.lastSparkUpdate = currentTime
            elif self.screen_scroll_offset == 0 and not self.first_spark_flag and currentTime - self.lastSparkUpdate > self.SPARKTIME + 500:
                position = (87, 27)
                spark_animation = CustomObjects.Animation(self.statupanimation,
                                                          position, (11, 1),
                                                          animation_speed=32,
                                                          ignore_map=True)
                self.animations.append(spark_animation)
                self.first_spark_flag = True
                self.lastSparkUpdate = currentTime
                # Sound
                GC.SOUNDDICT['Level_Up_Level'].play()

            # Add sparks to animation list one at a time
            if self.first_spark_flag and currentTime - self.lastSparkUpdate > self.SPARKTIME:
                self.sparkCounter += 1
                self.sparkUp = True  # Whether the sparkCounter was actually incremented or not
                if self.sparkCounter > 7:
                    self.sparkCounter = 7
                    self.sparkUp = False
                else:
                    while self.levelup_list[self.sparkCounter] == 0:
                        self.sparkCounter += 1
                        self.sparkUp = True
                        if self.sparkCounter > 7:
                            self.sparkCounter = 7
                            self.sparkUp = False
                            break

                if self.sparkUp:
                    self.underline_offset = 36  # for underline growing
                    # Add animations and Sound
                    # Animations
                    if self.sparkCounter >= 4:
                        position = (88,
                                    (self.sparkCounter - 4) * GC.TILEHEIGHT +
                                    61)
                    else:
                        position = (24, self.sparkCounter * GC.TILEHEIGHT + 61)
                    arrow_animation = CustomObjects.Animation(
                        self.uparrow, (position[0] + 31, position[1] - 37),
                        (10, 1),
                        animation_speed=32,
                        ignore_map=True,
                        hold=True)
                    self.arrow_animations.append(arrow_animation)
                    spark_animation = CustomObjects.Animation(
                        self.statupanimation,
                        position, (11, 1),
                        animation_speed=32,
                        ignore_map=True)
                    self.animations.append(spark_animation)
                    # Only 1-7 are supported increases for a levelup right now
                    # assert 8 > self.levelup_list[self.sparkCounter] > 0, "%s %s"%(self.levelup_list, self.levelup_list[self.sparkCounter])
                    if 1 <= self.levelup_list[self.sparkCounter] <= 4:
                        row = Engine.subsurface(
                            self.numbers,
                            (0,
                             (self.levelup_list[self.sparkCounter] - 1) * 24,
                             10 * 28, 24))
                        number_animation = CustomObjects.Animation(
                            row, (position[0] + 29, position[1] + 23), (10, 1),
                            animation_speed=32,
                            ignore_map=True,
                            hold=True)
                    else:
                        row = Engine.subsurface(
                            self.numbers, (0, (Utility.clamp(
                                self.levelup_list[self.sparkCounter], 1, 7) -
                                               1) * 24, 2 * 28, 24))
                        number_animation = CustomObjects.Animation(
                            row, (position[0] + 29, position[1] + 23), (2, 1),
                            animation_speed=32,
                            ignore_map=True,
                            hold=True)
                    number_animation.frameCount = -5  # delay this animation for 5 frames
                    self.animations.append(number_animation)
                    # Sound
                    GC.SOUNDDICT['Stat Up'].play()

                self.lastSparkUpdate = currentTime  # Reset the last update time.

            # HP, Str, Mag, Skl, Spd, Luck, Def, Res
            new_underline_surf = Image_Modification.change_image_color(
                self.statunderline, new_color)
            for num in range(len(self.levelup_list[0:self.sparkCounter + 1])):
                if self.levelup_list[
                        num] > 0:  # IE it should be updated, since it leveled up
                    if num == self.sparkCounter:
                        rect = (self.underline_offset, 0,
                                new_underline_surf.get_width() -
                                self.underline_offset, 3)
                        new_underline_surf = Engine.subsurface(
                            new_underline_surf, rect)
                        self.underline_offset -= 6
                        self.underline_offset = max(0, self.underline_offset)
                        if num >= 4:
                            topleft = (76 + self.underline_offset // 2,
                                       45 + GC.TILEHEIGHT * (num - 4))
                        else:
                            topleft = (12 + self.underline_offset // 2,
                                       45 + GC.TILEHEIGHT * (num))
                    else:
                        if num >= 4:
                            topleft = (76, 45 + GC.TILEHEIGHT * (num - 4))
                        else:
                            topleft = (12, 45 + GC.TILEHEIGHT * (num))
                    LevelUpSurface.blit(new_underline_surf, topleft)

            # Update and draw arrow animations
            self.arrow_animations = [
                animation for animation in self.arrow_animations
                if not animation.update(gameStateObj)
            ]
            for animation in self.arrow_animations:
                animation.draw(LevelUpSurface, gameStateObj, blend=new_color)
            # Update and draw number animations
            self.number_animations = [
                animation for animation in self.number_animations
                if not animation.update(gameStateObj)
            ]
            for animation in self.number_animations:
                animation.draw(LevelUpSurface, gameStateObj, blend=new_color)

            GC.FONT['text_yellow'].blit('HP', LevelUpSurface, (10, 35))
            GC.FONT['text_yellow'].blit(cf.WORDS['STR'], LevelUpSurface,
                                        (10, GC.TILEHEIGHT + 35))
            GC.FONT['text_yellow'].blit(cf.WORDS['MAG'], LevelUpSurface,
                                        (10, GC.TILEHEIGHT * 2 + 35))
            GC.FONT['text_yellow'].blit(cf.WORDS['SKL'], LevelUpSurface,
                                        (10, GC.TILEHEIGHT * 3 + 35))
            GC.FONT['text_yellow'].blit(
                cf.WORDS['SPD'], LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 8, 35))
            GC.FONT['text_yellow'].blit(
                cf.WORDS['LCK'], LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 8, GC.TILEHEIGHT + 35))
            GC.FONT['text_yellow'].blit(
                cf.WORDS['DEF'], LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 8, GC.TILEHEIGHT * 2 + 35))
            GC.FONT['text_yellow'].blit(
                cf.WORDS['RES'], LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 8, GC.TILEHEIGHT * 3 + 35))

            hp_text = self.unit.stats['HP'].base_stat - (
                self.levelup_list[0] if self.sparkCounter < 0 else 0)
            str_text = self.unit.stats['STR'].base_stat - (
                self.levelup_list[1] if self.sparkCounter < 1 else 0)
            mag_text = self.unit.stats['MAG'].base_stat - (
                self.levelup_list[2] if self.sparkCounter < 2 else 0)
            skl_text = self.unit.stats['SKL'].base_stat - (
                self.levelup_list[3] if self.sparkCounter < 3 else 0)
            spd_text = self.unit.stats['SPD'].base_stat - (
                self.levelup_list[4] if self.sparkCounter < 4 else 0)
            lck_text = self.unit.stats['LCK'].base_stat - (
                self.levelup_list[5] if self.sparkCounter < 5 else 0)
            def_text = self.unit.stats['DEF'].base_stat - (
                self.levelup_list[6] if self.sparkCounter < 6 else 0)
            res_text = self.unit.stats['RES'].base_stat - (
                self.levelup_list[7] if self.sparkCounter < 7 else 0)

            GC.FONT['text_blue'].blit(
                str(hp_text), LevelUpSurface,
                (50 - GC.FONT['text_blue'].size(str(hp_text))[0], 35))
            GC.FONT['text_blue'].blit(
                str(str_text), LevelUpSurface,
                (50 - GC.FONT['text_blue'].size(str(str_text))[0],
                 GC.TILEHEIGHT + 35))
            GC.FONT['text_blue'].blit(
                str(mag_text), LevelUpSurface,
                (50 - GC.FONT['text_blue'].size(str(mag_text))[0],
                 GC.TILEHEIGHT * 2 + 35))
            GC.FONT['text_blue'].blit(
                str(skl_text), LevelUpSurface,
                (50 - GC.FONT['text_blue'].size(str(skl_text))[0],
                 GC.TILEHEIGHT * 3 + 35))
            GC.FONT['text_blue'].blit(
                str(spd_text), LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 48 -
                 GC.FONT['text_blue'].size(str(spd_text))[0], 35))
            GC.FONT['text_blue'].blit(
                str(lck_text), LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 48 -
                 GC.FONT['text_blue'].size(str(lck_text))[0],
                 GC.TILEHEIGHT + 35))
            GC.FONT['text_blue'].blit(
                str(def_text), LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 48 -
                 GC.FONT['text_blue'].size(str(def_text))[0],
                 GC.TILEHEIGHT * 2 + 35))
            GC.FONT['text_blue'].blit(
                str(res_text), LevelUpSurface,
                (LevelUpSurface.get_width() / 2 + 48 -
                 GC.FONT['text_blue'].size(str(res_text))[0],
                 GC.TILEHEIGHT * 3 + 35))
            """
            # HP, Str, Mag, Skl, Spd, Luck, Def, Res
            for num in range(len(self.levelup_list[0:self.sparkCounter])):
                if self.levelup_list[num] != 0: # IE it should be updated, since it leveled up
                    # Blit number
                    if num >= 4:
                        topleft = (LevelUpSurface.get_width()/2+50, GC.TILEHEIGHT * (num - 4) + 33)
                    else:
                        topleft = (52, GC.TILEHEIGHT * num + 33)
                    change = str(self.levelup_list[num])
                    if self.levelup_list[num] > 0:
                        change = '+' + change
                    GC.FONT['stat_white'].blit(change, LevelUpSurface, topleft)
            """
            pos = (6 - self.screen_scroll_offset,
                   GC.WINHEIGHT - 8 - LevelUpSurface.get_height())
            surf.blit(LevelUpSurface, pos)

            # Blit unit's pic
            BigPortraitSurf = self.unit.bigportrait
            pos = (GC.WINWIDTH - BigPortraitSurf.get_width() - 4,
                   GC.WINHEIGHT + self.unit_scroll_offset -
                   BigPortraitSurf.get_height())
            surf.blit(BigPortraitSurf, pos)

        # Update and draw animations
        self.animations = [
            animation for animation in self.animations
            if not animation.update(gameStateObj)
        ]
        for animation in self.animations:
            animation.draw(surf, gameStateObj)
Ejemplo n.º 23
0
 def draw(self, surf):
     self.update()
     image = Image_Modification.flickerImageTranslucent(Engine.copy_surface(self.sprite), self.trans_value)
     surf.blit(image, (0, 0))
    def draw(self, surf):
        currentTime = Engine.get_time()
        time_passed = min(currentTime - self.start_time, self.display_time)
        if cf.OPTIONS['debug'] and time_passed < 0:
            logger.error('This phase has a negative time_passed! %s %s %s',
                         time_passed, currentTime, self.start_time)
        max_opaque = 118

        # Blit the banner
        # position
        if time_passed < self.begin_time:
            diff = time_passed / float(self.begin_time)
            offset = self.topleft[0] + self.begin_time * (1 - diff)
            trans = 100. * (1 - diff)**2
        elif time_passed < self.begin_time + self.main_time:
            offset = self.topleft[0]
            trans = 0
        else:  # 367 milliseconds
            diff = (time_passed -
                    (self.begin_time + self.main_time)) / float(self.end_time)
            offset = self.topleft[0] - self.end_time * diff
            trans = 100. * diff**2

        # transparency
        image = Image_Modification.flickerImageTranslucent(
            self.image.copy(), trans)
        surf.blit(image, (offset, self.topleft[1]))

        transition_space1 = self.transition_space.copy()
        transition_space2 = self.transition_space.copy()

        # === Handle the transition
        half_display_time = self.display_time // 2
        if time_passed < half_display_time:
            diff = time_passed / float(half_display_time)
            height = (GC.WINHEIGHT // 2 - 16) * diff
            alpha = int(max_opaque *
                        math.sqrt(time_passed / float(half_display_time)))
        else:
            diff = -(half_display_time -
                     time_passed) / float(half_display_time)
            height = (GC.WINHEIGHT // 2 - 16) * (1 - diff)
            alpha = int(max_opaque - max_opaque *
                        ((time_passed - half_display_time) /
                         float(half_display_time))**2)
            alpha = Utility.clamp(alpha, 0, 255)

        if time_passed < half_display_time:
            t = int(2 +
                    diff * 16)  # Starts a little ways along at the beginning
        else:
            t = int(diff * 16)

        for x in range(0, GC.WINWIDTH, 16):
            for y in range(0, 64, 16):
                i, j = x / 16, y / 16
                k = int(t * 1.5 - (i - j % 2) / 2 + j / 2 - 4)
                if time_passed < half_display_time:
                    frame = Utility.clamp(8 - abs(max(k, 8) - 8), 0, 8)
                else:
                    frame = Utility.clamp(k, 0, 8)
                # frame = Utility.clamp(min(k, 8) + min(8 - k, 0), 0, 8)
                square_surf = Engine.subsurface(
                    self.transition, (frame * 16, 0, 16, 16)).copy()
                transition_space1.blit(square_surf, (x, y))

        for x in range(0, GC.WINWIDTH, 16):
            for y in range(0, 64, 16):
                i, j = x / 16, y / 16
                k = int(t * 1.5 - (i - j % 2) / 2 + j / 2 - 1)
                if time_passed < half_display_time:
                    frame = Utility.clamp(8 - abs(max(k, 8) - 8), 0, 8)
                else:
                    frame = Utility.clamp(k, 0, 8)
                # frame = Utility.clamp(min(k, 8) + min(8 - k, 0), 0, 8)
                square_surf = Engine.subsurface(
                    self.transition, (frame * 16, 0, 16, 16)).copy()
                transition_space2.blit(square_surf, (x, y))

        # height = 64  # remove later
        transition_space1 = Engine.subsurface(transition_space1,
                                              (0, 0, GC.WINWIDTH, height))
        transition_space2 = Engine.subsurface(
            transition_space2, (0, self.transition_space.get_height() - height,
                                GC.WINWIDTH, height))

        # Fill with correct alpha
        # alpha = 255  # Remove later
        Engine.fill(transition_space1, (255, 255, 255, alpha), None,
                    Engine.BLEND_RGBA_MULT)
        Engine.fill(transition_space2, (255, 255, 255, alpha), None,
                    Engine.BLEND_RGBA_MULT)
        # Now blit transition space
        surf.blit(transition_space1, (0, 0))
        # Other transition_space
        surf.blit(transition_space2,
                  (0, GC.WINHEIGHT - transition_space2.get_height()))
Ejemplo n.º 25
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 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)