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()