main
lijiawei 6 months ago
parent 35b817d951
commit cadf2a6bf4

@ -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)]

@ -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

@ -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)]

@ -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)]
Loading…
Cancel
Save