def render_characters_in_combat(self, screen_ins, contextDTO): # render the character if not contextDTO.get_active_team(): return characters = contextDTO.get_active_team().get_teammembers() idx = 0 for temp_char in characters: idx = idx + 1 if not temp_char: continue # resize character stand image calc_h = Image_Util.calculate_character_combat_height_by_screen_size( self.__size_h) calc_w = Image_Util.calculate_character_combat_width_by_height( temp_char.get_stand_image(), calc_h) calc_in_fight_h = Image_Util.calculate_character_in_fight_height_by_screen_size( self.__size_h) temp_char.resize_character_images_by_height( calc_h, calc_in_fight_h) temp_prof_rate = temp_char.get_character_profession_rate() # re-calculate character stand image position (x, y ) = Image_Util.calculate_character_combat_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) self.__character_combat_properties[idx]['position'] = (x, y) self.__character_combat_properties[idx]['image_size'] = (0, 0, calc_w, calc_h) if contextDTO.get_contextDTO_InCombat().get_current_selection() and \ contextDTO.get_contextDTO_InCombat().get_current_selection().get_character_name() == temp_char.get_character_name(): # skip the fighting character if contextDTO.get_contextDTO_InCombat().get_is_fight_in_round( ): continue new_w, new_h = temp_char.get_stand_select_image().get_size() screen_ins.blit(temp_char.get_stand_select_image(), (x, y), (0, 0, new_w, new_h)) elif contextDTO.get_contextDTO_InCombat().get_current_target() and \ contextDTO.get_contextDTO_InCombat().get_current_target().get_character_name() == temp_char.get_character_name(): # skip the fighting character if contextDTO.get_contextDTO_InCombat().get_is_fight_in_round( ): continue else: new_w, new_h = temp_char.get_stand_image().get_size() screen_ins.blit(temp_char.get_stand_image(), (x, y), (0, 0, new_w, new_h))
def get_cover_skill(self, cursor_x, cursor_y, contextDTO): if not contextDTO.get_contextDTO_InCombat().get_current_selection() or \ not contextDTO.get_contextDTO_InCombat().get_current_selection().get_active_skills(): return active_skills = contextDTO.get_contextDTO_InCombat( ).get_current_selection().get_active_skills() temp_pos_x = [] idx = 0 for idx in [0, 1, 2, 3]: temp_pos_x.append( Image_Util.calculate_skill_in_fight_positionX_by_screen_size( self.__size_w, idx)) temp_pos_y = Image_Util.calculate_skill_in_fight_positionY_by_screen_size( self.__size_h + self.__pos_y) temp_size = Image_Util.calculate_skill_in_fight_size_by_screen_size( self.__size_h + self.__pos_y) if (temp_pos_x[0] < cursor_x < temp_pos_x[0] + temp_size) and ( temp_pos_y < cursor_y < temp_pos_y + temp_size) and active_skills[0]: if not contextDTO.get_contextDTO_InCombat( ).get_current_select_skill(): contextDTO.get_contextDTO_InCombat().set_current_cover_skill( active_skills[0]) elif (temp_pos_x[1] < cursor_x < temp_pos_x[1] + temp_size) and ( temp_pos_y < cursor_y < temp_pos_y + temp_size) and active_skills[1]: if not contextDTO.get_contextDTO_InCombat( ).get_current_select_skill(): contextDTO.get_contextDTO_InCombat().set_current_cover_skill( active_skills[1]) elif (temp_pos_x[2] < cursor_x < temp_pos_x[2] + temp_size) and ( temp_pos_y < cursor_y < temp_pos_y + temp_size) and active_skills[2]: if not contextDTO.get_contextDTO_InCombat( ).get_current_select_skill(): contextDTO.get_contextDTO_InCombat().set_current_cover_skill( active_skills[2]) elif (temp_pos_x[3] < cursor_x < temp_pos_x[3] + temp_size) and ( temp_pos_y < cursor_y < temp_pos_y + temp_size) and active_skills[3]: if not contextDTO.get_contextDTO_InCombat( ).get_current_select_skill(): contextDTO.get_contextDTO_InCombat().set_current_cover_skill( active_skills[3]) else: contextDTO.get_contextDTO_InCombat().set_current_cover_skill(None)
def wake_up_controller(self, contextDTO=None, resourceDTO=None): super().wake_up_controller(contextDTO, resourceDTO) # generate map temp_map = self.generate_map( contextDTO.get_contextDTO_InMap().get_map_type(), contextDTO.get_contextDTO_InMap().get_map_size()) # arrange map background and items self.arrange_map_background_and_items( temp_map, contextDTO.get_contextDTO_InMap().get_map_type(), resourceDTO) # backup the map into contextDTO contextDTO.get_contextDTO_InMap().set_map(temp_map) # initial map position positionDTO = Position_DTO() positionDTO.set_map_cell(temp_map.get_entrence()) positionDTO.set_cell_position(Map_Util.DEFAULT_CELL_SIZE[0]) positionDTO.set_move_direction(MoveDirection_Enum.DIRECTION_EAST) contextDTO.get_contextDTO_InMap().set_map_position(positionDTO) # resize character image calc_h = Image_Util.calculate_character_move_height_by_screen_size( contextDTO.get_screen_height()) for temp_char in contextDTO.get_active_team().get_teammembers(): if temp_char: temp_char.resize_character_images_by_height(calc_h, 1)
def render_image(self, screen_ins, screen_w, screen_h, contextDTO=None): if screen_w and screen_h: self.__size_w = screen_w self.__size_h = Image_Util.calculate_bottom_bar_height_by_screen_size( screen_h) self.__pos_y = Image_Util.calculate_bottom_bar_positionY_by_screen_size( screen_h) self.__image = pygame.transform.scale( self.__image, (self.__size_w, self.__size_h)) screen_ins.blit(self.__image, (0, self.__pos_y), (0, 0, self.__size_w, self.__size_h)) # render skills self.render_skills(screen_ins, contextDTO)
def resize_character_images_by_height(self, size_h, calc_in_fight_h): # retrieve profession image rage rate = self.get_character_enemy_type_rate() idx1 = 0 for img in self.__enemy_images: # fighting image if idx1 == 2: calc_in_fight_w = Image_Util.calculate_character_move_width_by_height( self.__profession_images[idx1], calc_in_fight_h) self.__enemy_images[idx1] = pygame.transform.scale( img, (round(calc_in_fight_w * rate), round(calc_in_fight_h * rate))) else: size_w = Image_Util.calculate_character_move_width_by_height( self.__profession_images[idx1], size_h) self.__enemy_images[idx1] = pygame.transform.scale( img, (round(size_w * rate), round(size_h * rate))) idx1 = idx1 + 1
def __init__(self, size_w=None, size_h=None): # size self.__size_w = 1280 self.__size_h = 250 # position self.__pos_x = 0 self.__pos_y = 470 # images self.__image = pygame.image.load( Materials_Constant.bottom_bar_image_filename).convert_alpha() if size_w and size_h: self.__size_w = size_w self.__size_h = Image_Util.calculate_bottom_bar_height_by_screen_size( size_h) self.__pos_y = Image_Util.calculate_bottom_bar_positionY_by_screen_size( size_h) self.__image = pygame.transform.scale( self.__image, (self.__size_w, self.__size_h))
def render_image(self, screen_ins, screen_w, screen_h, contextDTO=None): if screen_w and screen_h: self.__size_w = screen_w self.__size_h = Image_Util.calculate_top_bar_height_by_screen_size( screen_h) self.__image = pygame.transform.scale( self.__image, (self.__size_w, self.__size_h)) screen_ins.blit(self.__image, (0, 0), (0, 0, self.__size_w, self.__size_h))
def render_skills(self, screen_ins, contextDTO=None): if not contextDTO or not contextDTO.get_contextDTO_InCombat( ).get_current_selection(): return False, 'Invalid character, no skills load!' active_skills = contextDTO.get_contextDTO_InCombat( ).get_current_selection().get_active_skills() # render the skill bar idx = 0 for active_skill in active_skills: temp_pos_x = Image_Util.calculate_skill_in_fight_positionX_by_screen_size( self.__size_w, idx) temp_pos_y = Image_Util.calculate_skill_in_fight_positionY_by_screen_size( self.__size_h + self.__pos_y) temp_size = Image_Util.calculate_skill_in_fight_size_by_screen_size( self.__size_h + self.__pos_y) if contextDTO.get_contextDTO_InCombat().get_current_select_skill() and \ contextDTO.get_contextDTO_InCombat().get_current_select_skill().get_skill_name() == active_skill.get_skill_name(): active_skill_image = active_skill.get_skill_image_select() elif contextDTO.get_contextDTO_InCombat().get_current_cover_skill() and \ contextDTO.get_contextDTO_InCombat().get_current_cover_skill().get_skill_name() == active_skill.get_skill_name(): active_skill_image = active_skill.get_skill_image_select() else: active_skill_image = active_skill.get_skill_image() active_skill_image = pygame.transform.scale( active_skill_image, (temp_size, temp_size)) idx = idx + 1 screen_ins.blit(active_skill_image, (temp_pos_x, temp_pos_y), (0, 0, temp_size, temp_size))
def render_fighting(self, screen_ins, contextDTO): # image timer current_time = time.time() * 1000.0 # in fight if contextDTO.get_contextDTO_InCombat().get_is_fight_in_round() and \ contextDTO.get_contextDTO_InCombat().get_fighting_timer() > 0 and \ current_time - contextDTO.get_contextDTO_InCombat().get_fighting_timer() <= Scene_Constant.FIGHTING_TIMER_MAX: ''' Calculate attack result @todo: remove self.__is_fighting_in_round for skill calculation testing ''' if not contextDTO.get_contextDTO_InCombat().get_is_fight_calculate( ): Fight_Util.calculate_fighting(contextDTO.get_contextDTO_InCombat().get_current_selection(), \ contextDTO.get_contextDTO_InCombat().get_current_target(), \ contextDTO.get_contextDTO_InCombat().get_current_select_skill()) contextDTO.get_contextDTO_InCombat().set_is_fight_calculate( True) # render the character if contextDTO.get_active_team(): characters = contextDTO.get_active_team().get_teammembers() idx = 0 for temp_char in characters: idx = idx + 1 if not temp_char: continue if contextDTO.get_contextDTO_InCombat().get_current_selection() and \ contextDTO.get_contextDTO_InCombat().get_current_selection().get_character_name() == temp_char.get_character_name(): temp_prof_rate = temp_char.get_character_profession_rate( ) ( calc_w, calc_h ) = Image_Util.calculate_character_in_fight_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) screen_ins.blit( contextDTO.get_contextDTO_InCombat( ).get_current_selection().get_fighting_image(), (calc_w, calc_h)) break if contextDTO.get_contextDTO_InCombat().get_current_target() and \ contextDTO.get_contextDTO_InCombat().get_current_target().get_character_name() == temp_char.get_character_name(): temp_prof_rate = temp_char.get_character_profession_rate( ) ( calc_w, calc_h ) = Image_Util.calculate_character_in_fight_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) screen_ins.blit( contextDTO.get_contextDTO_InCombat( ).get_current_target().get_fighting_image(), (calc_w, calc_h)) break # render the enemy if contextDTO.get_contextDTO_InCombat().get_active_enemies(): enemies = contextDTO.get_contextDTO_InCombat( ).get_active_enemies().get_teammembers() idx = 0 for temp_char in enemies: idx = idx + 1 if not temp_char: continue if contextDTO.get_contextDTO_InCombat().get_current_selection() and \ contextDTO.get_contextDTO_InCombat().get_current_selection().get_character_name() == temp_char.get_character_name(): temp_prof_rate = temp_char.get_character_enemy_type_rate( ) ( calc_w, calc_h ) = Image_Util.calculate_enemy_in_fight_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) screen_ins.blit( contextDTO.get_contextDTO_InCombat( ).get_current_selection().get_fighting_image(), (calc_w, calc_h)) break if contextDTO.get_contextDTO_InCombat().get_current_target() and \ contextDTO.get_contextDTO_InCombat().get_current_target().get_character_name() == temp_char.get_character_name(): temp_prof_rate = temp_char.get_character_enemy_type_rate( ) ( calc_w, calc_h ) = Image_Util.calculate_enemy_in_fight_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) screen_ins.blit( contextDTO.get_contextDTO_InCombat( ).get_current_target().get_fighting_image(), (calc_w, calc_h)) break # render the skill effect if contextDTO.get_contextDTO_InCombat().get_current_select_skill(): effect_img = contextDTO.get_contextDTO_InCombat( ).get_current_select_skill().get_effect_image() screen_ins.blit( effect_img, Image_Util.calculate_skill_effect_size_by_screen_size( self.__size_w, self.__size_h)) else: if contextDTO.get_contextDTO_InCombat().get_fighting_timer() > 0 and \ current_time - contextDTO.get_contextDTO_InCombat().get_fighting_timer() > Scene_Constant.FIGHTING_TIMER_MAX: # release select skill contextDTO.get_contextDTO_InCombat().set_current_select_skill( None) # initialize fighting in round properties contextDTO.get_contextDTO_InCombat().set_is_fight_in_round(False) contextDTO.get_contextDTO_InCombat().set_fighting_timer(0) contextDTO.get_contextDTO_InCombat().set_is_fight_calculate(False)
def render_characters_in_move(self, screen_ins, contextDTO, character_moving_timer): new_moving_timer = 0 # render the character if not contextDTO.get_active_team(): return new_moving_timer characters = contextDTO.get_active_team().get_teammembers() # character move characters_move = contextDTO.get_contextDTO_InMap( ).get_characters_move() if character_moving_timer > 0: if not characters_move: # initialize characters_move characters_move = {} for temp_char in characters: if not temp_char: continue # random a pace index for character's moving random_pace_idx = random.randint(1, 4) characters_move[ temp_char.get_character_name()] = random_pace_idx contextDTO.get_contextDTO_InMap().set_characters_move( characters_move) else: for temp_char in characters: if not temp_char: continue character_name = temp_char.get_character_name() if not character_name in characters_move.keys(): # random a pace index for character's moving random_pace_idx = random.randint(1, 4) characters_move[ temp_char.get_character_name()] = random_pace_idx contextDTO.get_contextDTO_InMap().set_characters_move( characters_move) idx = 0 for temp_char in characters: idx = idx + 1 if not temp_char: continue character_name = temp_char.get_character_name() character_img = temp_char.get_stand_image() # get move image if necessary if character_moving_timer > 0: current_time = time.time() * 1000 current_pace_idx = characters_move[character_name] if not current_pace_idx: current_pace_idx = random.randint(1, 4) if current_time - character_moving_timer <= Scene_Constant.MOVE_PACE_TIMER_MAX: character_img = temp_char.get_moving_image( current_pace_idx) else: character_img, current_pace_idx = temp_char.get_next_moving_image_and_idx( current_pace_idx) new_moving_timer = current_time characters_move[character_name] = current_pace_idx contextDTO.get_contextDTO_InMap().set_characters_move( characters_move) else: contextDTO.get_contextDTO_InMap().set_characters_move(None) # re-calculate character stand image position calc_w, calc_h = character_img.get_size() temp_prof_rate = temp_char.get_character_profession_rate() (x, y) = Image_Util.calculate_character_move_position_by_screen_size( self.__size_w, self.__size_h, idx, temp_prof_rate) self.__character_move_properties[idx]['position'] = (x, y) self.__character_move_properties[idx]['image_size'] = (0, 0, calc_w, calc_h) # render characters in move screen_ins.blit(character_img, (x, y), (0, 0, calc_w, calc_h)) return new_moving_timer
def render_map_items(self, screen_ins, contextDTO): current_map = contextDTO.get_contextDTO_InMap().get_map() current_position = contextDTO.get_contextDTO_InMap().get_map_position() current_cell = current_position.get_map_cell() current_cell_position = current_position.get_cell_position() current_direction = current_position.get_move_direction() next_cell = Map_Util.get_next_cell_in_map_by_direction( current_cell, current_direction, current_map) prev_cell = Map_Util.get_prev_cell_in_map_by_direction( current_cell, current_direction, current_map) if current_position: " if next cell is in screen's range " if current_cell_position > ( 100 - Scene_Constant.SCENE_CELL_WIDTH) and next_cell: "get all the next cell items" next_cell_items = next_cell.get_cell_items() for cell_item_obj in next_cell_items: next_cell_item_image = cell_item_obj.get_item_image() "recalculate the item size" cell_item_w, cell_item_h = Image_Util.calculate_map_item_size_by_screen_size( \ next_cell_item_image, cell_item_obj.get_item_size(), self.__size_h) next_cell_item_image = pygame.transform.scale( next_cell_item_image, (cell_item_w, cell_item_h)) "re-assign the item position of next cell" next_item_posx = cell_item_obj.get_item_position() is_show_item, item_pos_x = \ Image_Util.calculate_map_item_position_in_next_cell(next_item_posx, current_cell_position, self.__size_w) # render the item if is_show_item: screen_ins.blit(next_cell_item_image, (item_pos_x, 0), (0, 0, cell_item_w, cell_item_h)) "get all the current cell items" cell_items = current_cell.get_cell_items() for cell_item_obj in cell_items: cell_item_image = cell_item_obj.get_item_image() "recalculate the item size" cell_item_w, cell_item_h = Image_Util.calculate_map_item_size_by_screen_size( \ cell_item_image, cell_item_obj.get_item_size(), self.__size_h) cell_item_image = pygame.transform.scale( cell_item_image, (cell_item_w, cell_item_h)) "re-assign the item position of current cell" current_item_posx = cell_item_obj.get_item_position() is_show_item, item_pos_x = \ Image_Util.calculate_map_item_position_in_current_cell(current_item_posx, cell_item_w, current_cell_position, self.__size_w) # render the item if is_show_item: screen_ins.blit(cell_item_image, (item_pos_x, 0), (0, 0, cell_item_w, cell_item_h)) " if previous cell is existing " if prev_cell: "get all the previous cell items" prev_cell_items = prev_cell.get_cell_items() for cell_item_obj in prev_cell_items: prev_cell_item_image = cell_item_obj.get_item_image() "recalculate the item size" cell_item_w, cell_item_h = Image_Util.calculate_map_item_size_by_screen_size( \ prev_cell_item_image, cell_item_obj.get_item_size(), self.__size_h) "verify if the item of previous cell still be in the screen" prev_item_posx = cell_item_obj.get_item_position() is_show_item, item_pos_x = \ Image_Util.calculate_map_item_position_in_prev_cell(prev_item_posx, cell_item_w, current_cell_position, self.__size_w) # render the item if is_show_item: prev_cell_item_image = pygame.transform.scale( prev_cell_item_image, (cell_item_w, cell_item_h)) screen_ins.blit(prev_cell_item_image, (item_pos_x, 0), (0, 0, cell_item_w, cell_item_h))