forked from BAaboe/FlappyGoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.py
52 lines (36 loc) · 1.4 KB
/
Pipe.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
import Window
import pygame
from pygame.locals import*
import random
class Pipe:
def __init__(self, wd: Window.Window()):
self.wd = wd
self.width = 100
self.heigth = 600
self.pipeDistance = 200
self.ySpawnRange = (self.heigth/10*2, self.heigth/10*9)
self.downPipeX = self.wd.width
self.downPipeY = random.randint(self.ySpawnRange[0], self.ySpawnRange[1])
self.upPipeX = self.downPipeX
self.upPipeY = self.downPipeY - self.pipeDistance - self.heigth
self.image = pygame.image.load("./assets/pipe.png")
self.downPipe = pygame.transform.scale(self.image, (self.width, self.heigth))
self.upPipe = pygame.transform.rotate(self.downPipe, 180)
self.upRect = self.upPipe.get_rect()
self.downRect = self.downPipe.get_rect()
self.speed = 5
def move(self):
self.upPipeX -= self.speed
self.downPipeX -= self.speed
self.downRect.x = self.downPipeX
self.downRect.y = self.downPipeY
self.upRect.x = self.upPipeX
self.upRect.y = self.upPipeY
def update(self):
self.move()
self.draw()
def draw(self):
self.wd.window.blit(self.upPipe, (self.upPipeX, self.upPipeY))
self.wd.window.blit(self.downPipe, (self.downPipeX, self.downPipeY))
def isOutOfScreen(self):
return self.downPipeX <= 0 - self.width