delta_time += clock.tick() / 1000.0 if (delta_time > (1 / max_fps)): delta_time = delta_time - (1 / max_fps) screen.fill((0, 0, 0)) screen.blit(background_image,[0,0]) for boid in flock: neighbourhood = [] for neighbour in flock: if neighbour == boid: continue d = boid.distance(neighbour) if boid.is_neighbour(neighbour, 100.0, (120.0 * pi) / 180.0): neighbourhood.append(neighbour) # follow rules boid.alignment(neighbourhood, weight_alignement) boid.cohesion(neighbourhood, weight_cohesion) boid.separation(neighbourhood, 60.0, weight_cohesion) for obstacle in obstacles: d = boid.distance(obstacle) if d < 80: boid.avoid(obstacle, weight_avoid) obstacle.draw() boid.goal(mouse_x, mouse_y, weight_goal, goal_on) boid.update(5) boid.draw() pygame.display.update() pygame.quit()