Exemplo n.º 1
0
    def update(self):
        self.v = helperfunctions.truncate(self.v + self.steering,
                                          self.max_speed, self.min_speed)
        self.pos += self.v * self.dT

        # Update the partition key if necessary
        if bool(p.USE_PARTITIONS):
            self.partition_key = self.swarm.update_partition(self)
Exemplo n.º 2
0
    def update_actions(self):

        #avoid any obstacles in the environment
        for obstacle in self.flock.objects.obstacles:
            collide = pygame.sprite.collide_mask(self, obstacle)
            if bool(collide):
                self.avoid_obstacle(obstacle.pos, self.flock.object_loc)

        align_force, cohesion_force, separate_force = self.neighbor_forces()

        #combine the vectors in one
        steering_force = align_force * p.ALIGNMENT_WEIGHT + cohesion_force * p.COHESION_WEIGHT + separate_force * p.SEPARATION_WEIGHT

        #adjust the direction of the boid
        self.steering += helperfunctions.truncate(steering_force / self.mass,
                                                  p.MAX_FORCE)
Exemplo n.º 3
0
 def update(self):
     self.v = helperfunctions.truncate(self.v + self.steering,
                                       self.max_speed, self.min_speed)
     self.pos += self.v * self.dT