Ejemplo n.º 1
0
    def update_screen(self):
        pygame.draw.rect(self.screen, self.background, (0,0)+self.size) #recrée un fond
    
           #dessine l'absice et l'ordonnée
        pygame.draw.line(self.screen, (255,0,0),self.offset((0,-1e4)), self.offset((0, 1e4)))
        pygame.draw.line(self.screen, (255,0,0),self.offset((-1e4,0)), self.offset((1e4, 0)))
            
        #on dessine le but : 
        if(self.environment.goal_has_def()):
            P=[]
            for p in self.environment.goal.list_Points:
                P.append(self.offset_Point(p.x_scal(self.zoom)))
            pygame.draw.polygon(self.screen, (255,0,0), P,0)
                
            #dessine les obstacles
        for obj in self.environment.objects:
            points=obj.list_Points
            P=[]
            for point in points:
                P.append(self.offset_Point(point.x_scal(self.zoom)))
            pygame.draw.polygon(self.screen, (255,255,255), P,7)
            
            #draw all drones by circle 
    
        for drone in self.environment.drones:
            pygame.draw.circle(self.screen, drone.color, self.offset_Point(drone.position.x_scal(self.zoom)), drone.radius*self.zoom)
                
                #draw radar
            if(self.displayRadar):
                for i in range(drone.radar.nb_rays):
                    ray=Vector(1,0)
                    ray.setCap(drone.radar.angles_[i]+drone.speed.cap())
                    ray.setNorm(drone.radar.rays[i])
                    pygame.draw.line(self.screen, (0,200,0), self.offset_Point(drone.position.x_scal(self.zoom)), 
                                self.offset_Point(drone.position.add(ray).x_scal(self.zoom)), 1)
                    
                  
                    
    
                #drow speed vector
            pygame.draw.line(self.screen, (143,202,90), self.offset_Point(drone.position.x_scal(self.zoom)), 
                                 self.offset_Point(drone.position.add(drone.speed).x_scal(self.zoom)), 2)


        if(self.eventDisplay.pause):
            police = pygame.font.Font(None,60)
            texte = police.render("Pause",True,pygame.Color("#FFFF00"))
            a,b=texte.get_size()
            self.screen.blit(texte, (self.size[0]/2-a/2, (self.size[1]-b)/3))

        #on dessine le polygone en cours
        if(len(self.new_clique_Object)>0):
            P=[]
            for point in self.new_clique_Object:
                P.append(self.offset_Point(point.x_scal(self.zoom)))
            P.append(self.pos_souris)
            pygame.draw.lines(self.screen, (255,255,255), False, P,2)
Ejemplo n.º 2
0
    def update(self, list_Objects: list = [], list_Drones: list = []) -> None:
        """Update the Radar : with the two lists, this simulates a radar like a Lidar

        Args:
            list_Objects (list, Object): Object. Defaults to [].
            list_Drones (list, Drone): Drone. Defaults to [].
        """
        for I in range(self.nb_rays):
            tetha_i = self.angles_[I]  #angle of Ith rays
            vdir = Vector(1, 0)
            vdir.setCap(tetha_i)

            A = Vector(0, 0)
            B = vdir.copy()
            B.setNorm(self.ranges_[I])  #radius of the Ith rays

            D0 = droite(vdir, A)

            list_points = [B]

            for obj in list_Objects:
                if (len(obj.list_Points) > 1):
                    C = obj.list_Points[0]
                    for i in range(1, len(obj.list_Points)):
                        D = obj.list_Points[i]
                        P = Point_Intersection_SS(A, B, C, D)
                        C = D
                        if (P):
                            list_points.append(P)
                    D = obj.list_Points[0]
                    P = Point_Intersection_SS(A, B, C, D)
                    if (P):
                        list_points.append(P)

            for drone in list_Drones:
                if (drone.position.norm_2() > 0.1):
                    r = Points_Intersection_SC(
                        A, B,
                        (drone.position.x, drone.position.y, drone.radius))
                    if (r):
                        for p in r:
                            list_points.append(p)

            list_distance = [point.norm_2() for point in list_points]

            self.rays[I] = min(list_distance)