-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
55 lines (41 loc) · 1.18 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Pygame
import pygame as pg
# Classes
from boid import Boid
from hoik import Hoik
from obstacle import Obstacle
WIDTH = 1400
HEIGHT = 1000
def main(WIDTH, HEIGHT):
pg.init()
screen = pg.display.set_mode((WIDTH, HEIGHT))
screen.fill("BLACK")
pg.display.set_caption("Boids")
clock = pg.time.Clock()
# Create boids, hoiks and obstacles
boids = [Boid(WIDTH, HEIGHT) for i in range(100)]
hoiks = [Hoik(WIDTH, HEIGHT) for i in range(2)]
obstacles = [Obstacle(WIDTH, HEIGHT) for i in range(4)]
running = True
while running:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
screen.fill((0, 0, 0))
# Boid loop
for boid in boids:
boid.draw(screen)
boid.update(boids, hoiks, obstacles)
# Hoik loop
for hoik in hoiks:
hoik.draw(screen)
hoik.update(boids, hoiks)
# Obstacle loop
for obstacle in obstacles:
obstacle.draw(screen)
# Update the screen
pg.display.flip()
clock.tick(60)
pg.quit()
if __name__ == "__main__":
main(WIDTH, HEIGHT)