From 6c98f7f7f1bfde529ca79d5a902fbc9ffdfc6f0d Mon Sep 17 00:00:00 2001 From: pl3g9npaj <18798213833@163.com> Date: Sun, 7 Nov 2021 08:29:31 +0800 Subject: [PATCH] ADD file via upload --- bazi.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bazi.py diff --git a/bazi.py b/bazi.py new file mode 100644 index 0000000..9d1b471 --- /dev/null +++ b/bazi.py @@ -0,0 +1,40 @@ +import pygame +from pygame.sprite import Sprite + +class Bazi(Sprite): + """创建一个代表靶子的类.""" + + def __init__(self, ai_settings, screen): + """初始化靶子,并设置其起始位置""" + super(Bazi, self).__init__() + self.screen = screen + self.ai_settings = ai_settings + + # 加载外来图像,并设置其rect属性 + self.image = pygame.image.load('images/bazi.png') + self.rect = self.image.get_rect() + + # 在屏幕左上角启动每个新靶子 + self.rect.x = self.rect.width + self.rect.y = self.rect.height + + # 存储靶子的准确位置 + self.x = float(self.rect.x) + + def check_edges(self): + """如果靶子在屏幕边缘,则返回True。""" + screen_rect = self.screen.get_rect() + if self.rect.right >= screen_rect.right: + return True + elif self.rect.left <= 0: + return True + + def update(self): + """靶子的移动(向左或者向右)""" + self.x += (self.ai_settings.bazi_speed_factor * + self.ai_settings.fleet_direction) + self.rect.x = self.x + + def blitme(self): + """在当前位置绘制靶子""" + self.screen.blit(self.image, self.rect)