Beispiel #1
0
 def hide_layer(self, line, grid_manager=None):
     layer = int(line[1])
     # Image layer
     if len(self.layers) > layer:
         transition = line[2] if len(line) > 2 else None
         if transition == 'fade' or transition == 'destroy':
             self.layers[layer].show = False
             if transition == 'destroy':
                 for sprite in self.layers[layer]:
                     x, y = sprite.position
                     self.animations.append(
                         CustomObjects.Animation(
                             GC.IMAGESDICT['Snag'], (x, y - 1), (5, 13),
                             animation_speed=DESTRUCTION_ANIM_TIME //
                             (13 * 5)))
         else:
             self.layers[layer].show = False
             self.layers[layer].fade = 0
     # Terrain layer
     if len(self.terrain_layers) > layer:
         self.terrain_layers[layer].show = False
         self.true_tiles = None  # Reset tiles
         self.true_opacity_map = None
         if grid_manager:
             self.handle_grid_manager_with_layer(layer, grid_manager)
 def hide_layer(self, line):
     layer = int(line[1])
     transition = line[2] if len(line) > 2 else None
     if transition == 'fade' or transition == 'destroy':
         self.layers[layer].show = False
         if transition == 'destroy':
             for sprite in self.layers[layer]:
                 x, y = sprite.position
                 self.animations.append(
                     CustomObjects.Animation(
                         GC.IMAGESDICT['Snag'], (x, y - 1), (5, 13),
                         animation_speed=DESTRUCTION_ANIM_TIME / (13 * 5)))
     else:
         self.layers[layer].show = False
         self.layers[layer].fade = 0
Beispiel #3
0
 def no_damage(self):
     # print('No Damage!')
     if self.right:
         position = (52, 21)
     else:
         position = (110, 21)  # Enemy's position
     team = self.owner.right.team if self.right else self.owner.left.team
     image = GC.IMAGESDICT['NoDamageBlue' if team ==
                           'player' else 'NoDamageRed']
     anim = CustomObjects.Animation(image,
                                    position, (5, 5),
                                    ignore_map=True,
                                    set_timing=(1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                1, 1, 1, 1, 1, 1, 1, 1, 1,
                                                1, 1, 1, 1, 1, 1, 48))
     self.animations.append(anim)
     # Also offset self by [-1, -2, -3, -2, -1]
     self.lr_offset = [-1, -2, -3, -2, -1]
Beispiel #4
0
 def change_tile_sprites(self, coord, image_filename, transition=None):
     image = self.loose_tile_sprites[image_filename]
     size = image.get_width()//GC.TILEWIDTH, image.get_height()//GC.TILEHEIGHT
     for x in range(coord[0], coord[0] + size[0]):
         for y in range(coord[1], coord[1] + size[1]):
             pos = (x - coord[0], y - coord[1])
             self.tile_sprites[(x, y)] = TileSprite(None, (x, y), self)
             if transition:
                 self.tile_sprites[(x, y)].new_image_name = image_filename
                 self.tile_sprites[(x, y)].new_position = pos
                 self.tile_sprites[(x, y)].loadNewSprites()
                 if transition == 'destroy':
                     # To be moved to global during next update
                     self.animations.append(CustomObjects.Animation(GC.IMAGESDICT['Snag'], (x, y - 1), (5, 13), animation_speed=DESTRUCTION_ANIM_TIME//(13*5)))
             else:
                 self.tile_sprites[(x, y)].image_name = image_filename
                 self.tile_sprites[(x, y)].position = pos
                 self.tile_sprites[(x, y)].loadSprites()
Beispiel #5
0
 def parse_line(self, line):
     # print(self.right, line)
     self.base_state = False
     # === TIMING AND IMAGES ===
     if line[0] == 'f':
         self.frame_count = 0
         self.num_frames = self.get_frames(line[1])
         self.current_frame = self.frame_directory[line[2]]
         self.processing = False
         if line[2] == 'Stand':
             self.base_state = True
         if len(line) > 3 and line[3]:  # Under frame
             self.under_frame = self.frame_directory[line[3]]
         else:
             self.under_frame = None
         self.over_frame = None
         if len(line) > 4 and line[4]:
             self.personal_offset = tuple(
                 int(num) for num in line[4].split(','))
     elif line[0] == 'of':
         self.frame_count = 0
         self.num_frames = self.get_frames(line[1])
         self.under_frame = None
         self.processing = False
         self.over_frame = self.frame_directory[line[2]]
         if len(line) > 3:  # Current frame
             self.current_frame = self.frame_directory[line[3]]
         else:
             self.current_frame = None
     elif line[0] == 'uf':
         self.frame_count = 0
         self.num_frames = self.get_frames(line[1])
         self.current_frame = None
         self.over_frame = None
         self.under_frame = self.frame_directory[line[2]]
         self.processing = False
         if len(line) > 3:
             self.personal_offset = tuple(
                 int(num) for num in line[3].split(','))
     elif line[0] == 'wait':
         self.frame_count = 0
         self.num_frames = self.get_frames(line[1])
         self.current_frame = None
         self.under_frame = None
         self.over_frame = None
         self.processing = False
     # === SFX ===
     elif line[0] == 'sound':
         sound = random.choice(line[1:])
         GC.SOUNDDICT[sound].play()
     elif line[0] == 'stop_sound':
         sound = random.choice(line[1:])
         GC.SOUNDDICT[sound].stop()
     # === COMBAT HIT ===
     elif line[0] == 'start_hit':
         if 'no_shake' not in line:
             if self.owner.outcome() == 2:
                 self.owner.shake(4)  # Critical
             elif self.owner.def_damage() > 0:
                 self.owner.shake(1)
             else:  # No Damage -- Hit spark handles anim
                 self.owner.shake(2)
         self.owner.start_hit('no_sound' not in line)
         # Also offset partner by [-1, -2, -3, -2, -1]
         if self.partner:
             self.partner.lr_offset = [-1, -2, -3, -2, -1]
     elif line[0] == 'wait_for_hit':
         if self.wait_for_hit:
             if len(line) > 1:
                 self.current_frame = self.frame_directory[line[1]]
             else:
                 self.current_frame = None
             if len(line) > 2:
                 self.under_frame = self.frame_directory[line[2]]
             else:
                 self.under_frame = None
             self.over_frame = None
             self.state = 'Wait'
             self.processing = False
             self.base_state = True
     elif line[0] == 'spell_hit':
         # To handle ruin item
         if not self.item.half or self.owner.def_damage() > 0:
             self.owner.start_hit('no_sound' not in line,
                                  self.owner.outcome() == 0)
             self.state = 'Wait'
             self.processing = False
             if self.owner.def_damage() > 0:
                 if 'no_shake' not in line:
                     if self.owner.outcome() == 2:  # Crit
                         self.owner.shake(4)
                     else:
                         self.owner.shake(3)
             elif self.owner.def_damage() == 0:
                 if 'no_shake' not in line:
                     self.owner.shake(2)
                 if self.item and (self.item.weapon or
                                   (self.item.spell and self.item.damage)):
                     self.no_damage()
     elif line[0] == 'miss':
         if self.right:
             position = (72, 21)
         else:
             position = (128, 21)  # Enemy's position
         team = self.owner.right.team if self.right else self.owner.left.team
         image = GC.IMAGESDICT['MissBlue' if team ==
                               'player' else 'MissRed']
         anim = CustomObjects.Animation(image,
                                        position, (5, 4),
                                        ignore_map=True,
                                        set_timing=(1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 1, 1, 1, 1, 1,
                                                    1, 1, 1, 23))
         self.animations.append(anim)
         if not self.item.half:  # Spell hit handles this
             self.owner.start_hit('no_sound' not in line, True)  # Miss
         if self.partner:
             self.partner.dodge()
     # === FLASHING ===
     elif line[0] == 'parent_tint_loop':
         num_frames = self.get_frames(line[1])
         color = [
             tuple([int(num) for num in color.split(',')])
             for color in line[2:]
         ]
         if self.parent:
             self.parent.flash(num_frames, color)
     elif line[0] == 'parent_tint':
         num_frames = self.get_frames(line[1])
         color = tuple([int(num) for num in line[2].split(',')])
         if self.parent:
             self.parent.flash(num_frames, color)
     elif line[0] == 'enemy_tint':
         num_frames = self.get_frames(line[1])
         color = tuple([int(num) for num in line[2].split(',')])
         if self.partner:
             self.partner.flash(num_frames, color)
     elif line[0] == 'enemy_gray':
         num_frames = self.get_frames(line[1])
         if self.partner:
             self.partner.flash(num_frames, 'gray')
     elif line[0] == 'enemy_flash_white':
         num_frames = self.get_frames(line[1])
         if self.partner:
             self.partner.flash(num_frames, (248, 248, 248))
     elif line[0] == 'self_flash_white':
         num_frames = self.get_frames(line[1])
         self.flash(num_frames, (248, 248, 248))
     elif line[0] == 'screen_flash_white':
         num_frames = self.get_frames(line[1])
         if len(line) > 2:
             fade_out = self.get_frames(line[2])
         else:
             fade_out = 0
         self.owner.flash_color(num_frames, fade_out, color=(248, 248, 248))
     elif line[0] == 'screen_blend':
         num_frames = self.get_frames(line[1])
         color = tuple(int(num) for num in line[2].split(','))
         self.owner.flash_color(num_frames, color=color)
     elif line[0] == 'foreground_blend':
         self.foreground_frames = self.get_frames(line[1])
         color = tuple([int(num) for num in line[2].split(',')])
         self.foreground = GC.IMAGESDICT['BlackBackground'].copy()
         self.foreground.fill(color)
     elif line[0] == 'background_blend':
         self.background_frames = self.get_frames(line[1])
         color = tuple([int(num) for num in line[2].split(',')])
         self.background = GC.IMAGESDICT['BlackBackground'].copy()
         self.background.fill(color)
     elif line[0] == 'darken':
         self.owner.darken()
     elif line[0] == 'lighten':
         self.owner.lighten()
     elif line[0] == 'platform_shake':
         self.owner.platform_shake()
     elif line[0] == 'screen_shake':
         self.owner.shake(1)
     # === ANIMATIONS ===
     elif line[0] == 'hit_spark':
         if self.owner.def_damage() > 0:
             if self.right:
                 position = (-110, -30)
             else:
                 position = (-40, -30)  # Enemy's position
             image = GC.IMAGESDICT['HitSpark']
             anim = CustomObjects.Animation(image,
                                            position, (3, 5),
                                            14,
                                            ignore_map=True,
                                            set_timing=(-1, 2, 2, 2, 2, 2,
                                                        2, 1, 1, 1, 1, 1, 1,
                                                        1, 1))
             self.animations.append(anim)
         else:  # No Damage
             self.no_damage()
     elif line[0] == 'crit_spark':
         if self.owner.def_damage() > 0:
             image = GC.IMAGESDICT['CritSpark']
             if not self.right:
                 image = Engine.flip_horiz(
                     image
                 )  # If on the left, then need to swap so enemy can have it
             anim = CustomObjects.Animation(image, (-40, -30), (3, 5),
                                            15,
                                            ignore_map=True,
                                            set_timing=(-1, 1, 1, 1, 1, 1,
                                                        1, 1, 1, 1, 1, 1, 1,
                                                        1, 1, 1))
             self.animations.append(anim)
         else:  # No Damage
             self.no_damage()
     # === EFFECTS ===
     elif line[0] == 'effect':
         image, script = GC.ANIMDICT.get_effect(line[1], self.palette_name)
         # print('Effect', script)
         child_effect = BattleAnimation(self.unit, image, script,
                                        self.palette_name, self.item)
         child_effect.awake(self.owner,
                            self.partner,
                            self.right,
                            self.at_range,
                            parent=self)
         if len(line) > 2:
             child_effect.effect_offset = tuple(
                 int(num) for num in line[2].split(','))
         child_effect.start_anim(self.current_pose)
         self.children.append(child_effect)
     elif line[0] == 'under_effect':
         image, script = GC.ANIMDICT.get_effect(line[1], self.palette_name)
         # print('Effect', script)
         child_effect = BattleAnimation(self.unit, image, script,
                                        self.palette_name, self.item)
         child_effect.awake(self.owner,
                            self.partner,
                            self.right,
                            self.at_range,
                            parent=self)
         if len(line) > 2:
             child_effect.effect_offset = tuple(
                 int(num) for num in line[2].split(','))
         child_effect.start_anim(self.current_pose)
         self.under_children.append(child_effect)
     elif line[0] == 'enemy_effect':
         image, script = GC.ANIMDICT.get_effect(line[1], self.palette_name)
         child_effect = BattleAnimation(self.partner.unit, image, script,
                                        self.palette_name, self.item)
         # Opposite effects
         child_effect.awake(self.owner,
                            self.parent,
                            not self.right,
                            self.at_range,
                            parent=self.parent.partner)
         if len(line) > 2:
             child_effect.effect_offset = tuple(
                 int(num) for num in line[2].split(','))
         child_effect.start_anim(self.current_pose)
         self.partner.children.append(child_effect)
     elif line[0] == 'enemy_under_effect':
         image, script = GC.ANIMDICT.get_effect(line[1], self.palette_name)
         child_effect = BattleAnimation(self.partner.unit, image, script,
                                        self.palette_name, self.item)
         # Opposite effects
         child_effect.awake(self.owner,
                            self.parent,
                            not self.right,
                            self.at_range,
                            parent=self.parent.partner)
         if len(line) > 2:
             child_effect.effect_offset = tuple(
                 int(num) for num in line[2].split(','))
         child_effect.start_anim(self.current_pose)
         self.partner.under_children.append(child_effect)
     elif line[0] == 'clear_all_effects':
         self.clear_all_effects()
     elif line[0] == 'blend':
         if self.blend:
             self.blend = None
         else:
             self.blend = Engine.BLEND_RGB_ADD
     elif line[0] == 'spell':
         if len(line) > 1:
             item_id = line[1]
         else:
             item_id = self.item.id
         image, script = GC.ANIMDICT.get_effect(item_id, self.palette_name)
         child_effect = BattleAnimation(self.unit, image, script,
                                        self.palette_name, self.item)
         child_effect.awake(self.owner,
                            self.partner,
                            self.right,
                            self.at_range,
                            parent=self)
         child_effect.start_anim(self.current_pose)
         self.children.append(child_effect)
     elif line[0] == 'static':
         self.static = not self.static
     elif line[0] == 'over_static':
         self.over_static = not self.over_static
     elif line[0] == 'under_static':
         self.under_static = not self.under_static
     elif line[0] == 'ignore_pan':
         self.ignore_pan = not self.ignore_pan
     elif line[0] == 'opacity':
         self.opacity = int(line[1])
     elif line[0] == 'set_parent_opacity':
         self.parent.opacity = int(line[1])
     # === LOOPING ===
     elif line[0] == 'start_loop':
         if self.end_next_loop > 0:
             self.end_next_loop -= 1
         else:
             self.loop = Loop(self.script_index)
     elif line[0] == 'end_loop':
         if self.loop:
             self.loop.end_index = self.script_index
             self.script_index = self.loop.start_index  # re-loop
     elif line[0] == 'end_parent_loop':
         self.parent.end_loop()
     elif line[0] == 'end_child_loop':
         for child in self.children:
             child.end_loop()
         for child in self.under_children:
             child.end_loop()
     elif line[0] == 'defer':
         num_frames = int(line[1])
         rest_of_line = line[2:]
         self.deferred_commands.append((num_frames, rest_of_line))
     # === CONDITIONALS ===
     elif line[0] == 'if_range':
         if not self.at_range:
             self.script_index += int(line[1])
     elif line[0] == 'nif_range':
         if self.at_range:
             self.script_index += int(line[1])
     # === MOVEMENT ===
     elif line[0] == 'pan':
         self.pan_away = not self.pan_away
         if self.pan_away:
             self.owner.pan_away()
         else:
             self.owner.pan_back()
     else:
         print('%s is not supported command' % (line[0]))
Beispiel #6
0
def HandleStatusUpkeep(status, unit, gameStateObj):
    oldhp = unit.currenthp
    if status.time:
        status.time.decrement()
        logger.info('Time Status %s to %s at %s. Time left: %s', status.id,
                    unit.name, unit.position, status.time.time_left)
        if status.time.time_left <= 0:
            return "Remove"  # Don't process. Status has no more effect on unit

    elif status.remove_range:
        p_unit = gameStateObj.get_unit_from_id(status.parent_id)
        if not p_unit or not p_unit.position or not unit.position or Utility.calculate_distance(
                p_unit.position, unit.position) > status.remove_range:
            return "Remove"

    if status.hp_percentage:
        hp_change = int(
            int(unit.stats['HP']) * status.hp_percentage.percentage / 100.0)
        old_hp = unit.currenthp
        unit.change_hp(hp_change)
        # unit.currenthp += hp_change
        # unit.currenthp = Utility.clamp(unit.currenthp, 0, unit.stats['HP'])
        if unit.currenthp > old_hp:
            GC.SOUNDDICT['heal'].play()

    if status.upkeep_stat_change:
        unit.apply_stat_change(status.upkeep_stat_change.stat_change)
        status.upkeep_stat_change.count += 1

    if status.rhythm_stat_change:
        status.rhythm_stat_change.count += 1
        if status.rhythm_stat_change.count > status.rhythm_stat_change.limit:
            status.rhythm_stat_change.count = 0
            unit.apply_stat_change(status.rhythm_stat_change.reset)
        else:
            unit.apply_stat_change(status.rhythm_stat_change.change)

    if status.upkeep_animation and unit.currenthp != oldhp:
        stota = status.upkeep_animation
        if not stota.sprite:
            logger.error('Missing upkeep animation sprite for %s', status.name)
        else:
            anim = CustomObjects.Animation(
                stota.sprite, (unit.position[0], unit.position[1] - 1),
                (stota.x, stota.y),
                stota.num_frames,
                on=False)
            gameStateObj.allanimations.append(anim)

    if status.upkeeps_movement:
        if unit.team.startswith('enemy'):
            gameStateObj.boundary_manager._remove_unit(unit, gameStateObj)
            if unit.position:
                gameStateObj.boundary_manager._add_unit(unit, gameStateObj)

    unit.change_hp(0)  # Just check bounds
    # if unit.currenthp > int(unit.stats['HP']):
    #     unit.currenthp = int(unit.stats['HP'])
    if unit.movement_left > int(unit.stats['MOV']):
        unit.movement_left = max(0, int(unit.stats['MOV']))

    return oldhp, unit.currenthp
Beispiel #7
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)
Beispiel #8
0
    def __init__(self,
                 gameStateObj,
                 unit,
                 exp,
                 force_level=None,
                 force_promote=False,
                 in_combat=False):
        self.unit = unit
        # if cf.OPTIONS['debug']:
        #     print('LevelUpScreen: ', exp)

        self.expNew = min(100, exp)
        self.expOld = self.unit.exp
        self.expSet = self.expOld

        self.force_level = force_level or force_promote
        self.in_combat = in_combat
        self.prev_level = self.unit.level
        self.new_wexp = None  # For promotion

        # spriting
        self.levelUpScreen = GC.IMAGESDICT['LevelScreen']
        if self.in_combat:
            topleft = (0, 6)
            timing = [1 for _ in range(19)] + [10, 1, 1, 1, 1, 1] + [
                2 for _ in range(15)
            ] + [-1] + [1 for _ in range(12)]
            self.levelUpAnimation = CustomObjects.Animation(
                GC.IMAGESDICT['LevelUpBattle'],
                topleft, (5, 11),
                52,
                ignore_map=True,
                set_timing=timing)
        else:
            if unit.position:
                x, y = unit.position
                topleft = (x - gameStateObj.cameraOffset.x -
                           2) * GC.TILEWIDTH, (y - gameStateObj.cameraOffset.y
                                               - 1) * GC.TILEHEIGHT
            else:
                topleft = GC.WINWIDTH // 2, GC.WINHEIGHT // 2
            timing = [1 for _ in range(24)] + [44]
            self.levelUpAnimation = CustomObjects.Animation(
                GC.IMAGESDICT['LevelUpMap'],
                topleft, (5, 5),
                ignore_map=True,
                set_timing=timing)
        self.statupanimation = GC.IMAGESDICT['StatUpSpark']
        self.statunderline = GC.IMAGESDICT['StatUnderline']
        self.uparrow = GC.IMAGESDICT['LevelUpArrow']
        self.numbers = GC.IMAGESDICT['LevelUpNumber']

        self.exp_bar = None

        self.levelup_list = force_level
        self.sparkCounter = -1  # Where we are in the levelScreen spark display section
        self.lastSparkUpdate = Engine.get_time()
        self.first_spark_flag = False
        self.unit_scroll_offset = 80
        self.screen_scroll_offset = self.levelUpScreen.get_width() + 32
        self.underline_offset = 0
        self.state = CustomObjects.StateMachine('init')
        self.animations, self.arrow_animations, self.number_animations = [], [], []
        if force_level:
            # Need to prevent from going over max
            current_stats = list(self.unit.stats.values())
            klass = gameStateObj.metaDataObj['class_dict'][self.unit.klass]
            for index, stat in enumerate(self.levelup_list):
                self.levelup_list[index] = min(
                    stat, klass['max'][index] - current_stats[index].base_stat)
            self.unit.apply_levelup(self.levelup_list, exp == 0)
            self.state.changeState('levelScreen')
            self.state_time = Engine.get_time()
        if force_promote:
            self.state.changeState('item_promote')
            self.state_time = Engine.get_time()

        # TIMING
        self.total_time_for_exp = self.expNew * GC.FRAMERATE  # exp rate is 16
        self.level_up_sound_played = False
        self.SPARKTIME = 320
        self.LEVELUPWAIT = 1660