-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.py
More file actions
32 lines (26 loc) · 1.05 KB
/
Copy pathpipe.py
File metadata and controls
32 lines (26 loc) · 1.05 KB
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
import random
class pipe:
"""The pipe class. A pipe pair is an obstacle,
which will be displayed on the screen"""
def __init__(self, WIDTH, HEIGHT, distanceToOldPipe):
"""The constructor of a pipe pair.
A pipe pair is the obstacle the bird has to fly through.
INPUT: WIDTH: The screen width.
The new pipe will be initialized to the right of it.
HEIGHT: The screen height.
Defines where the pipe will be initialized.
distanceToOldPipe: Since pipes are initialized with a random
distance, it must keep a minimum distance to an existing
pipe on screen or else the pipes can not be flown through
OUTPUT: None"""
top = random.randint(0,HEIGHT-100)
# We wanna show something on the lower end.
self.uppery = random.randint(0,HEIGHT-140)
self.lowery = self.uppery + 120
#randomize distance of pipes so the bird can learn better
self.x = distanceToOldPipe/4 + WIDTH + random.randint(0,15)
def moveLeft(self):
"""When a frame is processed, the pipe moves to the left
INPUT: None
OUTPUT: None"""
self.x -= 4