From bb1581ebad32c3b0fa0e3d3c2e4194d47b9d85aa Mon Sep 17 00:00:00 2001 From: pwb8f3ix9 <2533327493@qq.com> Date: Fri, 31 May 2024 22:09:18 +0800 Subject: [PATCH] ADD file via upload --- Pipe.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Pipe.py diff --git a/Pipe.py b/Pipe.py new file mode 100644 index 0000000..b6e9c39 --- /dev/null +++ b/Pipe.py @@ -0,0 +1,26 @@ +''' +Function: + 定义管道类 +Author: + Charles +微信公众号: + Charles的皮卡丘 +''' +import random +import pygame + + +'''管道类''' +class Pipe(pygame.sprite.Sprite): + def __init__(self, image, position, **kwargs): + pygame.sprite.Sprite.__init__(self) + self.image = image + self.rect = self.image.get_rect() + self.mask = pygame.mask.from_surface(self.image) + self.rect.left, self.rect.top = position + self.used_for_score = False + @staticmethod + def randomPipe(cfg, image): + base_y = 0.79 * cfg.SCREENHEIGHT + up_y = int(base_y * 0.2) + random.randrange(0, int(base_y * 0.6 - cfg.PIPE_GAP_SIZE)) + return {'top': (cfg.SCREENWIDTH+10, up_y-image.get_height()), 'bottom': (cfg.SCREENWIDTH+10, up_y+cfg.PIPE_GAP_SIZE)} \ No newline at end of file