forked from x4nth055/pythoncode-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe.py
More file actions
21 lines (18 loc) · 679 Bytes
/
pipe.py
File metadata and controls
21 lines (18 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import pygame
class Pipe(pygame.sprite.Sprite):
def __init__(self, pos, width, height, flip):
super().__init__()
self.width = width
img_path = 'assets/terrain/pipe.png'
self.image = pygame.image.load(img_path)
self.image = pygame.transform.scale(self.image, (width, height))
if flip:
flipped_image = pygame.transform.flip(self.image, False, True)
self.image = flipped_image
self.rect = self.image.get_rect(topleft = pos)
# update object position due to world scroll
def update(self, x_shift):
self.rect.x += x_shift
# removes the pipe in the game screen once it is not shown in the screen anymore
if self.rect.right < (-self.width):
self.kill()