From cadf2a6bf43c6f861e117e6bb083d16e9c206327 Mon Sep 17 00:00:00 2001 From: lijiawei <1827956161@qq.com> Date: Sat, 1 Jun 2024 18:42:24 +0800 Subject: [PATCH] commit0601 --- Sun.py | 23 +++++++++++++++++++++++ Sun2.py | 24 ++++++++++++++++++++++++ SunFlower.py | 34 ++++++++++++++++++++++++++++++++++ WallNut.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 Sun.py create mode 100644 Sun2.py create mode 100644 SunFlower.py create mode 100644 WallNut.py diff --git a/Sun.py b/Sun.py new file mode 100644 index 0000000..bfb266f --- /dev/null +++ b/Sun.py @@ -0,0 +1,23 @@ +import os + +import pygame +import random + +from common_func import get_base_path + + +class Sun(pygame.sprite.Sprite): + def __init__(self, rect): + super(Sun, self).__init__() + self.image = pygame.image.load(os.path.join(get_base_path(), 'images/Sun/Sun_01.png')).convert_alpha() + self.images = [ + pygame.image.load(os.path.join(get_base_path(), 'images/Sun/Sun_{:02d}.png'.format(i))).convert_alpha() + for i in range(1, 14)] + self.rect = self.images[1].get_rect() + offset_top = random.randint(-25, 25) + offset_left = random.randint(-25, 25) + self.rect.top = rect.top + offset_top + self.rect.left = rect.left + offset_left + + def update(self, *args): + self.image = self.images[args[0] % len(self.images)] diff --git a/Sun2.py b/Sun2.py new file mode 100644 index 0000000..2c228a0 --- /dev/null +++ b/Sun2.py @@ -0,0 +1,24 @@ +import os + +import pygame +import random + +from common_func import get_base_path + + +class Sun2(pygame.sprite.Sprite): + def __init__(self): + super(Sun2, self).__init__() + self.image = pygame.image.load(os.path.join(get_base_path(), 'images/Sun/Sun_01.png')).convert_alpha() + self.images = [ + pygame.image.load(os.path.join(get_base_path(), 'images/Sun/Sun_{:02d}.png'.format(i))).convert_alpha() + for i in range(1, 14)] + self.rect = self.images[1].get_rect() + self.rect.left = random.randint(50, 720) + self.rect.top = -50 + self.speed = 2 + + def update(self, *args): + self.image = self.images[args[0] % len(self.images)] + if self.rect.bottom < 560: + self.rect.top += self.speed diff --git a/SunFlower.py b/SunFlower.py new file mode 100644 index 0000000..b2636cb --- /dev/null +++ b/SunFlower.py @@ -0,0 +1,34 @@ +import os + +import pygame + +print(os.getcwd()) + + +class SunFlower(pygame.sprite.Sprite): + def __init__(self, last_time, rect): + + super(SunFlower, self).__init__() + self.image = pygame.image.load(os.path.join(os.getcwd(), 'images/SunFlower/SunFlower00.png')).convert_alpha() + self.images = [pygame.image.load( + f"{os.path.join(os.getcwd(), 'images/SunFlower/SunFlower{:02d}.png')}".format(i)).convert_alpha() for i + in range(0, 25)] + self.rect = self.images[0].get_rect() + self.energy = 60 + self.rect.left = rect[0] + self.rect.top = rect[1] + self.last_time = last_time + self.zombies = set() + + def update(self, *args): + for zombie in self.zombies: + if not zombie.Alive: + self.energy += 0 + else: + self.energy -= 1 + if self.energy <= 0: + for zombie in self.zombies: + zombie.GO = False + self.kill() + + self.image = self.images[args[0] % len(self.images)] diff --git a/WallNut.py b/WallNut.py new file mode 100644 index 0000000..e3b2fe1 --- /dev/null +++ b/WallNut.py @@ -0,0 +1,43 @@ +import os + +import pygame + +from common_func import get_base_path + + +class WallNut(pygame.sprite.Sprite): + def __init__(self, rect): + + super(WallNut, self).__init__() + self.image = pygame.image.load(os.path.join(get_base_path(), 'images/WallNut/WallNut00.png')).convert_alpha() + self.images = [pygame.image.load( + os.path.join(get_base_path(), 'images/WallNut/WallNut{:02d}.png'.format(i))).convert_alpha() for i in + range(0, 17)] + self.Imgs2 = [pygame.image.load( + os.path.join(get_base_path(), 'images/WallNut/WallNut2_{:02d}.png'.format(i))).convert_alpha() for i in + range(0, 17)] + self.Imgs3 = [pygame.image.load( + os.path.join(get_base_path(), 'images/WallNut/WallNut3_{:02d}.png'.format(i))).convert_alpha() for i in + range(0, 17)] + self.rect = self.images[0].get_rect() + self.rect.left = rect[0] + self.rect.top = rect[1] + self.energy = 333 + self.zombies = set() + + def update(self, *args): + for zombie in self.zombies: + if not zombie.Alive: + self.energy += 0 + else: + self.energy -= 1 + if self.energy <= 0: + for zombie in self.zombies: + zombie.GO = False + self.kill() + elif self.energy >= 222: + self.image = self.images[args[0] % len(self.images)] + elif 111 <= self.energy < 222: + self.image = self.Imgs2[args[0] % len(self.Imgs2)] + else: + self.image = self.Imgs3[args[0] % len(self.Imgs3)]