From e88fe031a190829c8a8e1f1987eab6b6951bdf74 Mon Sep 17 00:00:00 2001 From: lijiawei <1827956161@qq.com> Date: Mon, 3 Jun 2024 20:38:09 +0800 Subject: [PATCH] commit0602 --- Bullet.py | 22 ++++++++++++++++++++++ BulletJXC.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 Bullet.py create mode 100644 BulletJXC.py diff --git a/Bullet.py b/Bullet.py new file mode 100644 index 0000000..7cfd2c7 --- /dev/null +++ b/Bullet.py @@ -0,0 +1,22 @@ +import os + +import pygame + +from common_func import get_base_path + + +class Bullet(pygame.sprite.Sprite): + def __init__(self, peashooter_rect, background_size): + super(Bullet, self).__init__() + self.image = pygame.image.load(os.path.join(get_base_path(), 'images/BulletPea1.png')).convert_alpha() + self.rect = self.image.get_rect() + self.rect.left = peashooter_rect[0] + 65 + self.rect.top = peashooter_rect[1] + 13 + self.width = background_size[0] + self.speed = 6 + + def update(self, *args, **kwargs) -> None: + if self.rect.right < self.width: + self.rect.left += self.speed + else: + self.kill() diff --git a/BulletJXC.py b/BulletJXC.py new file mode 100644 index 0000000..cec5c93 --- /dev/null +++ b/BulletJXC.py @@ -0,0 +1,28 @@ +import os + +import pygame + +from common_func import get_base_path + + +class BulletJXC(pygame.sprite.Sprite): + def __init__(self, jxc_rect, background_size, life1): + super(BulletJXC, self).__init__() + self.image = pygame.image.load(os.path.join(get_base_path(), 'images/bullet_0.png')).convert_alpha() + self.rect = self.image.get_rect() + self.rect.left = jxc_rect[0] + 50 + self.rect.top = jxc_rect[1] + self.width = background_size[0] + self.life2 = int(life1 / 120) - int(jxc_rect[1] / 200) - 4 + self.speed = 10 + self.life2 + self.a = 0 + + def update(self, *args, **kwargs) -> None: + if self.rect.right < self.width: + self.rect.left += self.speed + if self.a < 100: + y = 12 - self.a + self.rect.top -= int(y) + self.a += 0.5 + else: + self.kill()