main
lijiawei 6 months ago
parent 0a33a4d988
commit f7c6ed874e

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

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

@ -0,0 +1,44 @@
import os
import pygame
from common_func import get_base_path
class JXC(pygame.sprite.Sprite):
def __init__(self, rect):
super(JXC, self).__init__()
self.image = pygame.image.load(os.path.join(get_base_path(), 'images/jxc/JXC_00.png')).convert_alpha()
self.images1 = [
pygame.image.load(os.path.join(get_base_path(), 'images/jxc/JXC_{:02d}.png'.format(i))).convert_alpha() for i
in range(0, 31)]
self.images2 = [
pygame.image.load(os.path.join(get_base_path(), 'images/jxc/JXC_{:02d}.png'.format(i))).convert_alpha() for i
in range(31, 69)]
self.rect = self.images1[0].get_rect()
self.rect.left = rect[0]
self.rect.top = rect[1]
self.energy = 60
self.zombies = set()
self.attack = False
self.att = 0
def update(self, *args):
if not self.attack:
self.image = self.images1[args[0] % len(self.images1)]
elif self.attack:
if self.att < 38:
self.image = self.images2[self.att]
self.att += 1
else:
self.att = 0
self.attack = False
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()

@ -0,0 +1,32 @@
import os
import pygame
from common_func import get_base_path
class Peashooter(pygame.sprite.Sprite):
def __init__(self, rect):
super(Peashooter, self).__init__()
self.image = pygame.image.load(
os.path.join(get_base_path(), 'images/Peashooter/Peashooter_00.png')).convert_alpha()
self.images = [pygame.image.load(
os.path.join(get_base_path(), 'images/Peashooter/Peashooter_{:02d}.png'.format(i))).convert_alpha() for i in
range(0, 25)]
self.rect = self.images[0].get_rect()
self.rect.left = rect[0]
self.rect.top = rect[1]
self.energy = 60
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,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