Exemplo n.º 1
0
    def create_from_xml(self,wing,nb_players_total,human_players,match):
        self.wing=wing #-wing for target, +wing for own goal
        if (self.team_node==0):
            self.team_node=self.read_xml(self.xml_filename)

        #read all the animations
        xmldoc = minidom.parse("data/player_animations.xml")
        animations_node = xmldoc.getElementsByTagName('animations')[0]
        all_anims=animations_node.getElementsByTagName('anim')
        for anim_node in all_anims:
            anim_name=anim_node.getElementsByTagName('name')[0].childNodes[0].data
            anim_speed=float(anim_node.getElementsByTagName('speed')[0].childNodes[0].data)
            self.ref_anim_body_img[anim_name]=[]
            self.ref_anim_head_name[anim_name]=[]
            self.ref_anim_head_shift[anim_name]=[]
            self.ref_anim_speed[anim_name]=anim_speed
            all_imgs=anim_node.getElementsByTagName('img')
            for img_node in all_imgs:
                img_filename=img_node.getElementsByTagName('img_name')[0].childNodes[0].data
                img_headfilename=img_node.getElementsByTagName('head_img')[0].childNodes[0].data
                img_head_x=int(img_node.getElementsByTagName('head_x')[0].childNodes[0].data)
                img_head_y=int(img_node.getElementsByTagName('head_y')[0].childNodes[0].data)
                self.ref_anim_body_img[anim_name].append(coloringimage(img_filename,self.top_color,self.bottom_color))
                self.ref_anim_head_name[anim_name].append(img_headfilename)
                self.ref_anim_head_shift[anim_name].append((img_head_x,img_head_y))

 
        players_node = self.team_node.getElementsByTagName('players')[0]
        GK_node = players_node.getElementsByTagName('playerGK')[0]
        
        #add the GK
        self.players.append(Player_GK(self))
        self.players[0].read_xml(GK_node,match.field)
        
        player_rank=0
        
        #add human players
        for id_human in human_players:
            match.human_players[id_human] = Player_Human(self,id_human,"data/"+str(id_human)+".png")
            self.players.append(match.human_players[id_human])#add the player to the team
            self.players_ordered_dist_to_ball.append(match.human_players[id_human])#add the player to closest to ball order
            player_node=players_node.getElementsByTagName('player')[player_rank]
            player_rank=player_rank+1
            self.players[-1].read_xml(player_node,match.field)

        #add the other players
        for i in range(nb_players_total-len(human_players)):
            self.players.append(Player_CPU(self))
            player_node=players_node.getElementsByTagName('player')[player_rank]
            player_rank=player_rank+1
            self.players[-1].read_xml(player_node,match.field)
            #adjust speed to change difficulty (8:hard = normal speed)
            self.players[-1].speed/=(1.0+(8-Player_CPU.difficulty)/10.0)

        self.players_ordered_dist_to_ball[:]=self.players[1:]
Exemplo n.º 2
0
    def __init__(self, west_top_color, west_bottom_color, east_top_color, east_bottom_color):
        self.half_length = 100
        self.half_width = 50
        self.z = 0.0

        self.goal_half_width = {}  # -1: west goal, +1: east goal
        self.goal_height = {}
        self.goal_latitude = {}

        self.goal_half_width[-1] = 22  # west goal
        self.goal_height[-1] = 15
        self.goal_latitude[-1] = 0  # where the goal center is inside field width
        self.goal_half_width[1] = 22  # east goal
        self.goal_height[1] = 15
        self.goal_latitude[1] = 0  # where the goal center is inside field width
        self.bounce_damp = 0.6  # 1=perfect
        self.roll_damp = 0.9  # 1=perfect

        self.flag_back_image_west = coloringimage("../flag_back.png", west_top_color, west_bottom_color)
        self.flag_front_image_west = coloringimage("../flag_front.png", west_top_color, west_bottom_color)
        self.flag_back_image_east = coloringimage("../flag_back.png", east_top_color, east_bottom_color)
        self.flag_front_image_east = coloringimage("../flag_front.png", east_top_color, east_bottom_color)
Exemplo n.º 3
0
    def read_xml(self, xml_file):
        self.xml_filename=xml_file
        xmldoc = minidom.parse(xml_file)
        self.team_node = xmldoc.getElementsByTagName('team')[0]
        self.image=pygame.image.load(self.team_node.getElementsByTagName('img')[0].childNodes[0].data)
        self.name=self.team_node.getElementsByTagName('name')[0].childNodes[0].data
        #colors:
        r=g=b=128
        r=int(self.team_node.getElementsByTagName('top_color')[0].getElementsByTagName('r')[0].childNodes[0].data)
        g=int(self.team_node.getElementsByTagName('top_color')[0].getElementsByTagName('g')[0].childNodes[0].data)
        b=int(self.team_node.getElementsByTagName('top_color')[0].getElementsByTagName('b')[0].childNodes[0].data)
        self.top_color=(r,g,b)
        r=int(self.team_node.getElementsByTagName('bottom_color')[0].getElementsByTagName('r')[0].childNodes[0].data)
        g=int(self.team_node.getElementsByTagName('bottom_color')[0].getElementsByTagName('g')[0].childNodes[0].data)
        b=int(self.team_node.getElementsByTagName('bottom_color')[0].getElementsByTagName('b')[0].childNodes[0].data)
        self.bottom_color=(r,g,b)
 
        self.outfit_img=(coloringimage("outfit.png",self.top_color,self.bottom_color))
        
        #get avg caract.
        self.avg_speed=0
        self.avg_health=0
        self.avg_max_energy=0 #before speed decreases
        self.avg_resistance=0 #before going KO
        self.avg_control=0 #before being hurt by ball
        self.avg_kick=0 #for shooting
        self.avg_punch=0 #for attacking
        self.avg_jump_hight=0 
        self.avg_agressivity=0 
        self.avg_precision=0 #for GK and pass
        self.avg_listening=0

        players_node = self.team_node.getElementsByTagName('players')[0]
        all_players=players_node.getElementsByTagName('player')
        all_players.append(players_node.getElementsByTagName('playerGK')[0])
        nbr_players=0
        for player_node in all_players:
            self.avg_speed+=float(player_node.getElementsByTagName('speed')[0].childNodes[0].data)
            self.avg_health+=float(player_node.getElementsByTagName('health')[0].childNodes[0].data)
            self.avg_max_energy+=float(player_node.getElementsByTagName('max_energy')[0].childNodes[0].data)
            self.avg_resistance+=float(player_node.getElementsByTagName('resistance')[0].childNodes[0].data)
            self.avg_control+=float(player_node.getElementsByTagName('control')[0].childNodes[0].data)
            self.avg_kick+=float(player_node.getElementsByTagName('kick')[0].childNodes[0].data)
            self.avg_punch+=float(player_node.getElementsByTagName('punch')[0].childNodes[0].data)
            self.avg_jump_hight+=float(player_node.getElementsByTagName('jump_hight')[0].childNodes[0].data) 
            self.avg_agressivity+=float(player_node.getElementsByTagName('agressivity')[0].childNodes[0].data)
            self.avg_precision+=float(player_node.getElementsByTagName('precision')[0].childNodes[0].data)
            self.avg_listening+=float(player_node.getElementsByTagName('listening')[0].childNodes[0].data)
            nbr_players+=1

        self.avg_speed/=nbr_players
        self.avg_health/=nbr_players
        self.avg_max_energy/=nbr_players
        self.avg_resistance/=nbr_players
        self.avg_control/=nbr_players
        self.avg_kick/=nbr_players
        self.avg_punch/=nbr_players
        self.avg_jump_hight/=nbr_players
        self.avg_agressivity/=nbr_players
        self.avg_precision/=nbr_players
        self.avg_listening/=nbr_players

        return self.team_node
Exemplo n.º 4
0
    def read_xml(self, xml_file):
        self.xml_filename = xml_file
        xmldoc = minidom.parse(xml_file)
        self.team_node = xmldoc.getElementsByTagName('team')[0]
        self.image = pygame.image.load(
            self.team_node.getElementsByTagName('img')[0].childNodes[0].data)
        self.name = self.team_node.getElementsByTagName(
            'name')[0].childNodes[0].data
        #colors:
        r = g = b = 128
        r = int(
            self.team_node.getElementsByTagName('top_color')
            [0].getElementsByTagName('r')[0].childNodes[0].data)
        g = int(
            self.team_node.getElementsByTagName('top_color')
            [0].getElementsByTagName('g')[0].childNodes[0].data)
        b = int(
            self.team_node.getElementsByTagName('top_color')
            [0].getElementsByTagName('b')[0].childNodes[0].data)
        self.top_color = (r, g, b)
        r = int(
            self.team_node.getElementsByTagName('bottom_color')
            [0].getElementsByTagName('r')[0].childNodes[0].data)
        g = int(
            self.team_node.getElementsByTagName('bottom_color')
            [0].getElementsByTagName('g')[0].childNodes[0].data)
        b = int(
            self.team_node.getElementsByTagName('bottom_color')
            [0].getElementsByTagName('b')[0].childNodes[0].data)
        self.bottom_color = (r, g, b)

        self.outfit_img = (coloringimage("outfit.png", self.top_color,
                                         self.bottom_color))

        #get avg caract.
        self.avg_speed = 0
        self.avg_health = 0
        self.avg_max_energy = 0  #before speed decreases
        self.avg_resistance = 0  #before going KO
        self.avg_control = 0  #before being hurt by ball
        self.avg_kick = 0  #for shooting
        self.avg_punch = 0  #for attacking
        self.avg_jump_hight = 0
        self.avg_agressivity = 0
        self.avg_precision = 0  #for GK and pass
        self.avg_listening = 0

        players_node = self.team_node.getElementsByTagName('players')[0]
        all_players = players_node.getElementsByTagName('player')
        all_players.append(players_node.getElementsByTagName('playerGK')[0])
        nbr_players = 0
        for player_node in all_players:
            self.avg_speed += float(
                player_node.getElementsByTagName('speed')
                [0].childNodes[0].data)
            self.avg_health += float(
                player_node.getElementsByTagName('health')
                [0].childNodes[0].data)
            self.avg_max_energy += float(
                player_node.getElementsByTagName('max_energy')
                [0].childNodes[0].data)
            self.avg_resistance += float(
                player_node.getElementsByTagName('resistance')
                [0].childNodes[0].data)
            self.avg_control += float(
                player_node.getElementsByTagName('control')
                [0].childNodes[0].data)
            self.avg_kick += float(
                player_node.getElementsByTagName('kick')[0].childNodes[0].data)
            self.avg_punch += float(
                player_node.getElementsByTagName('punch')
                [0].childNodes[0].data)
            self.avg_jump_hight += float(
                player_node.getElementsByTagName('jump_hight')
                [0].childNodes[0].data)
            self.avg_agressivity += float(
                player_node.getElementsByTagName('agressivity')
                [0].childNodes[0].data)
            self.avg_precision += float(
                player_node.getElementsByTagName('precision')
                [0].childNodes[0].data)
            self.avg_listening += float(
                player_node.getElementsByTagName('listening')
                [0].childNodes[0].data)
            nbr_players += 1

        self.avg_speed /= nbr_players
        self.avg_health /= nbr_players
        self.avg_max_energy /= nbr_players
        self.avg_resistance /= nbr_players
        self.avg_control /= nbr_players
        self.avg_kick /= nbr_players
        self.avg_punch /= nbr_players
        self.avg_jump_hight /= nbr_players
        self.avg_agressivity /= nbr_players
        self.avg_precision /= nbr_players
        self.avg_listening /= nbr_players

        return self.team_node
Exemplo n.º 5
0
    def create_from_xml(self, wing, nb_players_total, human_players, match):
        self.wing = wing  #-wing for target, +wing for own goal
        if (self.team_node == 0):
            self.team_node = self.read_xml(self.xml_filename)

        #read all the animations
        xmldoc = minidom.parse("data/player_animations.xml")
        animations_node = xmldoc.getElementsByTagName('animations')[0]
        all_anims = animations_node.getElementsByTagName('anim')
        for anim_node in all_anims:
            anim_name = anim_node.getElementsByTagName(
                'name')[0].childNodes[0].data
            anim_speed = float(
                anim_node.getElementsByTagName('speed')[0].childNodes[0].data)
            self.ref_anim_body_img[anim_name] = []
            self.ref_anim_head_name[anim_name] = []
            self.ref_anim_head_shift[anim_name] = []
            self.ref_anim_speed[anim_name] = anim_speed
            all_imgs = anim_node.getElementsByTagName('img')
            for img_node in all_imgs:
                img_filename = img_node.getElementsByTagName(
                    'img_name')[0].childNodes[0].data
                img_headfilename = img_node.getElementsByTagName(
                    'head_img')[0].childNodes[0].data
                img_head_x = int(
                    img_node.getElementsByTagName('head_x')
                    [0].childNodes[0].data)
                img_head_y = int(
                    img_node.getElementsByTagName('head_y')
                    [0].childNodes[0].data)
                self.ref_anim_body_img[anim_name].append(
                    coloringimage(img_filename, self.top_color,
                                  self.bottom_color))
                self.ref_anim_head_name[anim_name].append(img_headfilename)
                self.ref_anim_head_shift[anim_name].append(
                    (img_head_x, img_head_y))

        players_node = self.team_node.getElementsByTagName('players')[0]
        GK_node = players_node.getElementsByTagName('playerGK')[0]

        #add the GK
        self.players.append(Player_GK(self))
        self.players[0].read_xml(GK_node, match.field)

        player_rank = 0

        #add human players
        for id_human in human_players:
            match.human_players[id_human] = Player_Human(
                self, id_human, "data/" + str(id_human) + ".png")
            self.players.append(
                match.human_players[id_human])  #add the player to the team
            self.players_ordered_dist_to_ball.append(
                match.human_players[id_human]
            )  #add the player to closest to ball order
            player_node = players_node.getElementsByTagName(
                'player')[player_rank]
            player_rank = player_rank + 1
            self.players[-1].read_xml(player_node, match.field)

        #add the other players
        for i in range(nb_players_total - len(human_players)):
            self.players.append(Player_CPU(self))
            player_node = players_node.getElementsByTagName(
                'player')[player_rank]
            player_rank = player_rank + 1
            self.players[-1].read_xml(player_node, match.field)
            #adjust speed to change difficulty (8:hard = normal speed)
            self.players[-1].speed /= (1.0 +
                                       (8 - Player_CPU.difficulty) / 10.0)

        self.players_ordered_dist_to_ball[:] = self.players[1:]