-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipes.py
34 lines (30 loc) · 1.13 KB
/
pipes.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
import pygame
from globals import *
from pipe import Pipe
from random import randint
class Pipes(pygame.sprite.Group):
def __init__(self, bird):
pygame.sprite.Group.__init__(self)
self.counter = 288 / PIPE_DENSITY
if ZPIPES == 0:
self.color = randint(0,1)
else:
self.color = ZPIPES - 1
self.gap = randint(PIPEGAP_MIN + PIPE_BUFFER, 400 - PIPE_BUFFER)
self.bird = bird
self.add(Pipe(self.gap, self.color, 0, self.bird))
self.add(Pipe(self.gap, self.color, 1, self.bird))
self.alive = True
def update(self):
if self.alive:
self.counter -= 60 / TICKRATE
if self.counter < 0:
self.gap = randint(PIPEGAP_MIN + PIPE_BUFFER, 400 - PIPE_BUFFER)
self.add(Pipe(self.gap, self.color, 0, self.bird))
self.add(Pipe(self.gap, self.color, 1, self.bird))
self.counter = 288 / PIPE_DENSITY
pygame.sprite.Group.update(self)
def die(self):
for pipe in pygame.sprite.Group.sprites(self):
self.alive = False
pipe.die()