-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.py
83 lines (59 loc) · 1.94 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import random
import pygame
PIPE_GAP = 100
MIN_Y = 400
PIPE_HEIGHT = 320
PIPE_WIDTH = 50
PLAYING_FIELD = 400
PIPE_IMAGES = [
[
pygame.image.load("content/lower.png"),
pygame.transform.rotate(pygame.image.load("content/lower.png"), 180)
],
[
pygame.image.load("content/upper.png"),
pygame.transform.rotate(pygame.image.load("content/upper.png"), 180)
]
]
PIPE_LOWER = random.randrange(PIPE_GAP + 30, MIN_Y - 30)
PIPE_UPPER = PIPE_LOWER - PIPE_GAP - PIPE_HEIGHT
class LowerPipe(pygame.sprite.Sprite):
def __init__(self, index=0):
pygame.sprite.Sprite.__init__(self)
self.index = index
self.x = 298
self.y = PIPE_LOWER
self.x_vel = -3
self.image = PIPE_IMAGES[self.index][0]
self.surface = pygame.surface.Surface((288, 512), pygame.SRCALPHA)
self.rect = self.surface.get_rect()
self.mask = pygame.mask.from_surface(self.surface)
def draw(self, output):
self.surface.fill((0, 0, 0, 0))
self.image = PIPE_IMAGES[self.index][0]
self.surface.blit(self.image, (self.x, self.y))
self.image = self.surface
self.mask = pygame.mask.from_surface(self.surface)
output.blit(self.surface, (self.surface.get_rect().x, self.surface.get_rect().y))
def update(self):
self.x += self.x_vel
class UpperPipe(pygame.sprite.Sprite):
def __init__(self, index=1):
pygame.sprite.Sprite.__init__(self)
self.index = index
self.x = 298
self.y = PIPE_UPPER
self.x_vel = -3
self.image = PIPE_IMAGES[self.index][1]
self.surface = pygame.surface.Surface((288, 512), pygame.SRCALPHA)
self.rect = self.surface.get_rect()
self.mask = pygame.mask.from_surface(self.surface)
def draw(self, output):
self.surface.fill((0, 0, 0, 0))
self.image = PIPE_IMAGES[self.index][1]
self.surface.blit(self.image, (self.x, self.y))
self.image = self.surface
self.mask = pygame.mask.from_surface(self.surface)
output.blit(self.surface, (self.surface.get_rect().x, self.surface.get_rect().y))
def update(self):
self.x += self.x_vel