예제 #1
0
    def update(self):
        # Combined movement vector
        for sprite in goals:

            d = sprite.pos - self.pos()
            dmag = d.length()

            if dmag < 25:
                self.kill()
                sprite.number += 1

        desired_vector = float(self.Coh) * self.vcoh() + float(
            self.Rep) * self.vrep() + float(self.Al) * self.val(
            ) + n * self.q * self.noise() + Dinformed * (
                self.target -
                self.pos()).normalize() + S * L / (N + L) * self.leader()
        new_vector = self.vector + desired_vector

        if new_vector.length() == 0:
            new_vector = zero
        else:
            new_vector = new_vector.normalize()

        new_vector *= normal_speed + self.q * max_speed

        self.rect.x += new_vector.x
        self.rect.y += new_vector.y

        self.vector = new_vector

        self.noisex = noise(7)
        self.noisey = noise(7)

        pygame.draw.circle(self.image, (0, 255, 0), (7, 7), 7, 0)

        if wrap == True:
            if self.rect.left > width:  # Allow movement across screen borders
                self.rect.right = 0
            if self.rect.right < 0:
                self.rect.left = width
            if self.rect.bottom > height:
                self.rect.top = 0
            if self.rect.top < 0:
                self.rect.bottom = height
        else:
            if self.rect.right > width:
                self.rect.right = width
            if self.rect.left < 0:
                self.rect.left = 0
            if self.rect.bottom > height:
                self.rect.bottom = height
            if self.rect.top < 0:
                self.rect.top = 0

        self.noisex = noise(7)
        self.noisey = noise(7)

        self.memory.append(self.q)

        self.q += self.total_reception() * (self.qstar() - self.q)
예제 #2
0
 def __init__ (self):                                                        # Define initial variables
     
     pygame.sprite.Sprite.__init__(self)                                         
     self.image = pygame.Surface((14,14),pygame.SRCALPHA,32)                     # Determine size
     self.image = self.image.convert_alpha()                                     # Make background transparent
     
     pygame.draw.circle(self.image, (0,0,0), (7,7), 7, 0)
     
     self.rect = self.image.get_rect()                                           # Determine rect
     
     if Divide == True:                                                          # Set initial positions
         self.rect.center = (rnd.randint(x-100,x+100),rnd.randint(y-100,y+100))
     elif Room == True:
         self.rect.center = (rnd.randint(447,993),rnd.randint(height/2-145,height/2+145))
     else:
         self.rect.center = (rnd.randint(100,width-100),rnd.randint(100,height-100))
     
     self.vector=pygame.math.Vector2(rnd.randint(-7,7),rnd.randint(-7,7))        # Set random initial velocity
     
     self.noisex=noise(7)
     self.noisey=noise(7)
     
     self.stop = False
     
     self.q=rnd.randint(lowerlimit,100)/100    # Level of emotion
     
     self.E=1    # Expression
     self.d=6    # Openness
 
     
     self.memory=[self.q]
예제 #3
0
파일: Boid.py 프로젝트: bennetwindt/BOIDS
 def update (self):           
                                            # Combined movement vector
     if Divide == True:                                                      # Picking one particular goal if informed sprite
         if self in informed:
             for sprite in goals:
                 if sprite.rect.left < self.rect.left:
                     targetx=sprite.pos.x
                     targety=sprite.pos.y
                     
                     target=pygame.math.Vector2(targetx,targety)                       
                     
     if self in informed:
         desired_vector = C*self.vcoh()+R*self.vrep()+A*self.val()+n*self.noise() + Dinformed*(target-self.pos()).normalize() + S*L/(N+L)*self.leader()
         new_vector = self.vector + desired_vector
     else:
         desired_vector = C*self.vcoh()+R*self.vrep()+A*self.val()+n*self.noise() + D*self.direct() + S*L/(N+L)*self.leader()
         new_vector = self.vector + desired_vector
     
     if new_vector.length() == 0:
         new_vector=zero
     else:
         new_vector=new_vector.normalize()
     
     new_vector *= s
     
     self.rect.x += new_vector.x
     self.rect.y += new_vector.y
     
     self.vector=new_vector
     
     self.noisex=noise(7)
     self.noisey=noise(7)
     
     if self in leaders:
         pygame.draw.circle(self.image, (0,0,255), (7,7), 7, 0)
     elif self in informed:
         pygame.draw.circle(self.image, (0,255,0), (7,7), 7, 0)
     
     if wrap == True:
         if self.rect.left > width:                                              # Allow movement across screen borders
             self.rect.right = 0
         if self.rect.right < 0:
             self.rect.left = width
         if self.rect.bottom > height:
             self.rect.top = 0
         if self.rect.top < 0:
             self.rect.bottom = height
     else:
         if self.rect.right > width:
             self.rect.right = width
         if self.rect.left < 0:
             self.rect.left = 0
         if self.rect.bottom > height:
             self.rect.bottom = height
         if self.rect.top < 0:
             self.rect.top = 0
예제 #4
0
    def __init__(self, spawn):  # Define initial variables

        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((14, 14), pygame.SRCALPHA,
                                    32)  # Determine size
        self.image = self.image.convert_alpha()  # Make background transparent

        pygame.draw.circle(self.image, (0, 0, 0), (7, 7), 7, 0)

        self.rect = self.image.get_rect()  # Determine rect

        if Divide == True:  # Set initial positions
            self.rect.center = (rnd.randint(x - 100, x + 100),
                                rnd.randint(y - 100, y + 100))
        if Bottleneck == True:
            self.rect.center = (rnd.randint(x - 300, x - 100),
                                rnd.randint(y - 100, y + 100))
        elif Room == True:
            self.rect.center = (rnd.randint(447, 993),
                                rnd.randint(height / 2 - 145,
                                            height / 2 + 145))
        elif Blackett == True:
            if spawn == (0, 0):
                p = (width / 2 - 720, height / 2 - 450)
                self.rect.center = (rnd.randint(p[0] + 400, p[0] + 690),
                                    rnd.randint(p[1] + 115, p[1] + 340))
            else:
                p = (width / 2 - 720, height / 2 - 450)
                self.rect.center = (p[0] + spawn[0], p[1] + spawn[1])
        else:
            self.rect.center = (rnd.randint(100, width - 100),
                                rnd.randint(100, height - 100))

        self.vector = pygame.math.Vector2(rnd.randint(-7, 7), rnd.randint(
            -7, 7))  # Set random initial velocity

        self.noisex = noise(7)
        self.noisey = noise(7)

        self.stop = False
        self.q = rnd.randint(lowerlimit, 100) / 100  # Level of emotion

        self.E = 1  # Expression
        self.d = 6  # Openness

        self.Coh = C
        self.Al = A
        self.Rep = R

        self.RC = cohesionradius
        self.RA = alignmentradius
        self.RR = repulsionradius

        self.memory = [self.q]
예제 #5
0
    def __init__(self, spawn):  # Define initial variables

        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.Surface((14, 14), pygame.SRCALPHA,
                                    32)  # Determine size
        self.image = self.image.convert_alpha()  # Make background transparent

        pygame.draw.circle(self.image, (0, 0, 0), (7, 7), 7, 0)

        self.rect = self.image.get_rect()  # Determine rect

        if Divide == True:  # Set initial positions
            self.rect.center = (rnd.randint(x - 100, x + 100),
                                rnd.randint(y - 100, y + 100))
        elif Room == True:
            self.rect.center = (rnd.randint(447, 993),
                                rnd.randint(height / 2 - 145,
                                            height / 2 + 145))
        elif Blackett == True:
            if spawn == (0, 0):
                p = (width / 2 - 720, height / 2 - 450)
                self.rect.center = (rnd.randint(p[0] + 400, p[0] + 690),
                                    rnd.randint(p[1] + 115, p[1] + 340))
            else:
                self.rect.center = spawn
        else:
            self.rect.center = (rnd.randint(100, width - 100),
                                rnd.randint(100, height - 100))

        self.vector = pygame.math.Vector2(rnd.randint(-7, 7), rnd.randint(
            -7, 7))  # Set random initial velocity

        self.noisex = noise(7)
        self.noisey = noise(7)

        self.stop = False

        # Picking one particular goal if informed sprite
        for sprite in goals:
            if sprite.rect.left < self.rect.left:
                targetx = sprite.pos.x
                targety = sprite.pos.y
                self.target = pygame.math.Vector2(targetx, targety)

        self.q = rnd.randint(lowerlimit, 100) / 100  # Level of emotion

        self.E = 1  # Expression
        self.d = 6  # Openness

        self.Coh = C
        self.Al = A
        self.Rep = R

        self.memory = [self.q]
예제 #6
0
    def update (self):           
    # Combined movement vector

        desired_vector = n*self.q*self.noise() + D*self.direct() + R*self.vrep()
        new_vector = self.vector + desired_vector
        
        if new_vector.length() == 0:
            new_vector=zero
        else:
            new_vector=new_vector.normalize()
        
        new_vector *= s
        
        self.rect.x += new_vector.x
        self.rect.y += new_vector.y
        
        self.vector=new_vector
        
        self.noisex=noise(7)
        self.noisey=noise(7)
        
        pygame.draw.circle(self.image, (0,0,255), (7,7), 7, 0)

        if wrap == True:
            if self.rect.left > width:                                              # Allow movement across screen borders
                self.rect.right = 0
            if self.rect.right < 0:
                self.rect.left = width
            if self.rect.bottom > height:
                self.rect.top = 0
            if self.rect.top < 0:
                self.rect.bottom = height
        else:
            if self.rect.right > width:
                self.rect.right = width
            if self.rect.left < 0:
                self.rect.left = 0
            if self.rect.bottom > height:
                self.rect.bottom = height
            if self.rect.top < 0:
                self.rect.top = 0
        
               
        self.noisex=noise(7)
        self.noisey=noise(7)
    
        self.memory.append(self.q)
        
        self.q += self.total_reception()*(self.qstar()-self.q)
예제 #7
0
    def update(self):
        # Combined movement vector

        desired_vector = N / (N + L) * (
            float(self.Coh) * self.vcoh() + float(self.Al) * self.val()
        ) + float(self.Rep) * self.vrep() + n * self.q * self.noise(
        ) + D * self.direct() + S * L / (N + L) * self.leader()
        new_vector = self.vector + desired_vector

        if new_vector.length() == 0:
            new_vector = zero
        else:
            new_vector = new_vector.normalize()

        self.memory.append(self.q)

        self.q += self.total_reception() * (self.qstar() - self.q)

        new_vector *= normal_speed + self.q * max_speed

        self.rect.x += new_vector.x
        self.rect.y += new_vector.y

        self.vector = new_vector

        if wrap == True:
            if self.rect.left > width:  # Allow movement across screen borders
                self.rect.right = 0
            if self.rect.right < 0:
                self.rect.left = width
            if self.rect.bottom > height:
                self.rect.top = 0
            if self.rect.top < 0:
                self.rect.bottom = height
        else:
            if self.rect.right > width:
                self.rect.right = width
            if self.rect.left < 0:
                self.rect.left = 0
            if self.rect.bottom > height:
                self.rect.bottom = height
            if self.rect.top < 0:
                self.rect.top = 0

        self.noisex = noise(7)
        self.noisey = noise(7)