Example #1
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