-
Notifications
You must be signed in to change notification settings - Fork 0
/
environment.py
46 lines (32 loc) · 999 Bytes
/
environment.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
import arcade
from population import *
from pipe import *
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
class Environment(arcade.Window):
population: Population
pipes: list
def __init__(self, population: Population, pipes: list):
self.population = population
self.pipes = pipes
super().__init__(width=SCREEN_WIDTH, height=SCREEN_HEIGHT)
def on_draw(self):
arcade.start_render()
self.population.on_draw()
for pipe in self.pipes:
pipe.on_draw()
def on_update(self, dt):
self.population.on_update(dt, self.pipes)
for pipe in self.pipes:
for bird in self.population.birds:
bird.check_collision(pipe)
if pipe.on_update(dt):
pipe.randomize(SCREEN_HEIGHT)
if __name__ == '__main__':
pipe = Pipe(500, 100)
pipe.randomize(SCREEN_HEIGHT, SCREEN_WIDTH + 50)
env = Environment(
Population(10),
[pipe]
)
arcade.run()