diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af9cb95 --- /dev/null +++ b/.gitignore @@ -0,0 +1,107 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# add +.idea/ \ No newline at end of file diff --git a/Bullet.py b/Bullet.py new file mode 100644 index 0000000..98a2d9a --- /dev/null +++ b/Bullet.py @@ -0,0 +1,19 @@ +import pygame + +class Bullet(pygame.sprite.Sprite): + def __init__(self, wdrect,bg_size): + super(Bullet, self).__init__() + self.image = pygame.image.load('material/images/Bullet_1.png').convert_alpha() + self.rect = self.image.get_rect() + + #定义子弹的初始化位置 + self.rect.left = wdrect[0] + 45 + self.rect.top = wdrect[1] + self.width = bg_size[0] + self.speed = 5 + + def update(self, *args): + if self.rect.right < self.width: + self.rect.left += self.speed + else: + self.kill() diff --git a/FlagZombie.py b/FlagZombie.py new file mode 100644 index 0000000..b7ae0c1 --- /dev/null +++ b/FlagZombie.py @@ -0,0 +1,25 @@ +import random +import pygame + +from Zombie import Zombie + + +class FlagZombie(Zombie): + def __init__(self): + super(FlagZombie,self).__init__() + self.image = pygame.image.load('material/images/FlagZombie_0.png').convert_alpha() + self.images = [pygame.image.load('material/images/FlagZombie_{}.png'.format(i)).convert_alpha() for i in range(0,12)] + + # self.rect = self.images[0].get_rect() + # self.rect.top = 25 + random.randrange(0,4)*125 + self.energy = 10 + # self.rect.left = 1000 + self.speed = 4 + + # def update(self, *args): + # if self.energy > 0: + # self.image = self.images[args[0] % len(self.images)] + # if self.rect.left > 250: + # self.rect.left -= self.speed + # else: + # self.kill() diff --git a/Peashooter.py b/Peashooter.py new file mode 100644 index 0000000..3a1bd08 --- /dev/null +++ b/Peashooter.py @@ -0,0 +1,28 @@ +import pygame + +class Peashooter(pygame.sprite.Sprite): + def __init__(self): + super(Peashooter,self).__init__() + self.image = pygame.image.load('material/images/Peashooter_00.png').convert_alpha() + self.images = [pygame.image.load('material/images/Peashooter_{:02d}.png'.format(i)).convert_alpha() for i in range(0,13)] + + self.rect = self.images[0].get_rect() + self.rect.top = 100 + self.rect.left = 250 + self.energy = 3*15 + self.zombies = set() + + def update(self, *args): + + for zombie in self.zombies: + if zombie.isAlive == False: + continue + + self.energy -= 1 + + if self.energy <= 0: + for zombie in self.zombies: + zombie.isMeetWallNut = False + self.kill() + + self.image = self.images[args[0] % len(self.images)] diff --git a/Player.py b/Player.py new file mode 100644 index 0000000..591e663 --- /dev/null +++ b/Player.py @@ -0,0 +1,23 @@ +import pygame +import os + +WIDTH = 360 +HEIGHT = 480 + + +game_folder = os.path.dirname(__file__) +img_path = os.path.join(game_folder,'img') +player_img = pygame.image.load(os.path.join(img_path,'a.png')).convert_alpha() + +class Player(pygame.sprite.Sprite): + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.image = player_img + # self.image.fill((0, 255, 0)) + self.rect = self.image.get_rect() + self.rect.center = (WIDTH / 2, HEIGHT / 2) + + def update(self): + self.rect.x += 5 + if self.rect.left > WIDTH: + self.rect.right = 0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..877a957 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +### 配套教程 + +[B站视频教程](https://www.bilibili.com/video/BV1EK4y187Kf) +[简书图片教程](https://www.jianshu.com/nb/33278365) + +### 下载体验 + +链接:https://pan.baidu.com/s/1Icu2UkkHYfERhVU0USjHmw +提取码:yftf diff --git a/Sun.py b/Sun.py new file mode 100644 index 0000000..2aa3bb9 --- /dev/null +++ b/Sun.py @@ -0,0 +1,23 @@ +import random + +import pygame + +class Sun(pygame.sprite.Sprite): + def __init__(self,rect): + super(Sun,self).__init__() + self.image = pygame.image.load('material/images/Sun_1.png').convert_alpha() + self.images = [pygame.image.load('material/images/Sun_{}.png'.format(i)).convert_alpha() for i in range(1,18)] + + self.rect = self.images[0].get_rect() + + offsetTop = random.randint(-50,50) + offsetLeft = random.randint(-50,50) + + self.rect.top = rect.top + offsetTop + self.rect.left = rect.left + offsetLeft + + def update(self, *args): + + + self.image = self.images[args[0] % len(self.images)] + diff --git a/SunFlower.py b/SunFlower.py new file mode 100644 index 0000000..b8394d9 --- /dev/null +++ b/SunFlower.py @@ -0,0 +1,28 @@ +import pygame + +class SunFlower(pygame.sprite.Sprite): + def __init__(self,lasttime): + super(SunFlower, self).__init__() + self.image = pygame.image.load('material/images/SunFlower_00.png').convert_alpha() + self.images = [pygame.image.load('material/images/SunFlower_{:02d}.png'.format(i)).convert_alpha() for i in range(0,13)] + + self.rect = self.images[0].get_rect() + self.rect.top = 250 + self.rect.left = 450 + self.lasttime = lasttime + self.energy = 3*15 + self.zombies = set() + + def update(self, *args): + for zombie in self.zombies: + if zombie.isAlive == False: + continue + + self.energy -= 1 + + if self.energy <= 0: + for zombie in self.zombies: + zombie.isMeetWallNut = 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..a408f7f --- /dev/null +++ b/WallNut.py @@ -0,0 +1,44 @@ +import pygame + +class WallNut(pygame.sprite.Sprite): + def __init__(self): + super(WallNut, self).__init__() + self.image = pygame.image.load('material/images/WallNut_00.png').convert_alpha() + self.images = [pygame.image.load('material/images/WallNut_{:02d}.png'.format(i)).convert_alpha() for i in range(0,13)] + self.crackedImgs = [ + pygame.transform.smoothscale(pygame.image.load("material/images/Wallnut_body.png").convert_alpha(), + (self.image.get_rect().width, self.image.get_rect().height)), + pygame.transform.smoothscale( + pygame.image.load("material/images/Wallnut_cracked1.png").convert_alpha(), + (self.image.get_rect().width, self.image.get_rect().height)), + pygame.transform.smoothscale( + pygame.image.load("material/images/Wallnut_cracked2.png").convert_alpha(), + (self.image.get_rect().width, self.image.get_rect().height))] + self.rect = self.images[0].get_rect() + self.rect.top = 200 + self.rect.left = 250 + + self.energy = 8*15 + self.zombies = set() + + def update(self, *args): + for zombie in self.zombies: + if zombie.isAlive == False: + continue + + self.energy -= 1 + + if self.energy <= 0: + for zombie in self.zombies: + zombie.isMeetWallNut = False + self.kill() + + + if self.energy == 8*15: + self.image = self.images[args[0] % len(self.images)] + elif 6*15 <= self.energy < 8*15: + self.image = self.crackedImgs[0] + elif 3 * 15 <= self.energy < 6 * 15: + self.image = self.crackedImgs[1] + else: + self.image = self.crackedImgs[2] diff --git a/Zombie.py b/Zombie.py new file mode 100644 index 0000000..445e460 --- /dev/null +++ b/Zombie.py @@ -0,0 +1,39 @@ +import random + +import pygame + +class Zombie(pygame.sprite.Sprite): + def __init__(self): + super(Zombie,self).__init__() + self.image = pygame.image.load('material/images/Zombie_0.png').convert_alpha() + self.images = [pygame.image.load('material/images/Zombie_{}.png'.format(i)).convert_alpha() for i in range(0,22)] + self.dieimages = [pygame.image.load('material/images/ZombieDie_{}.png'.format(i)).convert_alpha() for i in range(0,10)] + self.attack_images = [pygame.image.load('material/images/ZombieAttack_{}.png'.format(i)).convert_alpha() for i in + range(0, 21)] + self.rect = self.images[0].get_rect() + self.rect.top = 25 + random.randrange(0,4)*125 + self.energy = 6 + self.rect.left = 1000 + self.speed = 5 + self.dietimes = 0 + self.isMeetWallNut = False + self.isAlive = True + + def update(self, *args): + if self.energy > 0: + if self.isMeetWallNut: + self.image = self.attack_images[args[0] % len(self.attack_images)] + else: + self.image = self.images[args[0] % len(self.images)] + if self.rect.left > 250 and not self.isMeetWallNut: + self.rect.left -= self.speed + else: + if self.dietimes < 20: + self.image = self.dieimages[self.dietimes//2] + self.dietimes += 1 + else: + if self.dietimes > 30: + self.isAlive = False + self.kill() + else: + self.dietimes += 1 diff --git a/material/images/1.png b/material/images/1.png new file mode 100644 index 0000000..0bb0bae Binary files /dev/null and b/material/images/1.png differ diff --git a/material/images/2.png b/material/images/2.png new file mode 100644 index 0000000..85c0c12 Binary files /dev/null and b/material/images/2.png differ diff --git a/material/images/3.png b/material/images/3.png new file mode 100644 index 0000000..1f8255f Binary files /dev/null and b/material/images/3.png differ diff --git a/material/images/4.png b/material/images/4.png new file mode 100644 index 0000000..cda30f9 Binary files /dev/null and b/material/images/4.png differ diff --git a/material/images/5.png b/material/images/5.png new file mode 100644 index 0000000..d451b90 Binary files /dev/null and b/material/images/5.png differ diff --git a/material/images/6.png b/material/images/6.png new file mode 100644 index 0000000..feeac7e Binary files /dev/null and b/material/images/6.png differ diff --git a/material/images/Bullet_1.png b/material/images/Bullet_1.png new file mode 100644 index 0000000..13506b3 Binary files /dev/null and b/material/images/Bullet_1.png differ diff --git a/material/images/FlagZombieAttack_0.png b/material/images/FlagZombieAttack_0.png new file mode 100644 index 0000000..9d6b4a1 Binary files /dev/null and b/material/images/FlagZombieAttack_0.png differ diff --git a/material/images/FlagZombieAttack_1.png b/material/images/FlagZombieAttack_1.png new file mode 100644 index 0000000..8c8e861 Binary files /dev/null and b/material/images/FlagZombieAttack_1.png differ diff --git a/material/images/FlagZombieAttack_10.png b/material/images/FlagZombieAttack_10.png new file mode 100644 index 0000000..4002b07 Binary files /dev/null and b/material/images/FlagZombieAttack_10.png differ diff --git a/material/images/FlagZombieAttack_2.png b/material/images/FlagZombieAttack_2.png new file mode 100644 index 0000000..0678523 Binary files /dev/null and b/material/images/FlagZombieAttack_2.png differ diff --git a/material/images/FlagZombieAttack_3.png b/material/images/FlagZombieAttack_3.png new file mode 100644 index 0000000..6288f9c Binary files /dev/null and b/material/images/FlagZombieAttack_3.png differ diff --git a/material/images/FlagZombieAttack_4.png b/material/images/FlagZombieAttack_4.png new file mode 100644 index 0000000..484a227 Binary files /dev/null and b/material/images/FlagZombieAttack_4.png differ diff --git a/material/images/FlagZombieAttack_5.png b/material/images/FlagZombieAttack_5.png new file mode 100644 index 0000000..d7d5936 Binary files /dev/null and b/material/images/FlagZombieAttack_5.png differ diff --git a/material/images/FlagZombieAttack_6.png b/material/images/FlagZombieAttack_6.png new file mode 100644 index 0000000..c2c68df Binary files /dev/null and b/material/images/FlagZombieAttack_6.png differ diff --git a/material/images/FlagZombieAttack_7.png b/material/images/FlagZombieAttack_7.png new file mode 100644 index 0000000..5a85555 Binary files /dev/null and b/material/images/FlagZombieAttack_7.png differ diff --git a/material/images/FlagZombieAttack_8.png b/material/images/FlagZombieAttack_8.png new file mode 100644 index 0000000..88cbc5f Binary files /dev/null and b/material/images/FlagZombieAttack_8.png differ diff --git a/material/images/FlagZombieAttack_9.png b/material/images/FlagZombieAttack_9.png new file mode 100644 index 0000000..7729754 Binary files /dev/null and b/material/images/FlagZombieAttack_9.png differ diff --git a/material/images/FlagZombie_0.png b/material/images/FlagZombie_0.png new file mode 100644 index 0000000..4c9c906 Binary files /dev/null and b/material/images/FlagZombie_0.png differ diff --git a/material/images/FlagZombie_1.png b/material/images/FlagZombie_1.png new file mode 100644 index 0000000..2e9ee09 Binary files /dev/null and b/material/images/FlagZombie_1.png differ diff --git a/material/images/FlagZombie_10.png b/material/images/FlagZombie_10.png new file mode 100644 index 0000000..2bffc8c Binary files /dev/null and b/material/images/FlagZombie_10.png differ diff --git a/material/images/FlagZombie_11.png b/material/images/FlagZombie_11.png new file mode 100644 index 0000000..b0e2656 Binary files /dev/null and b/material/images/FlagZombie_11.png differ diff --git a/material/images/FlagZombie_2.png b/material/images/FlagZombie_2.png new file mode 100644 index 0000000..0d14f70 Binary files /dev/null and b/material/images/FlagZombie_2.png differ diff --git a/material/images/FlagZombie_3.png b/material/images/FlagZombie_3.png new file mode 100644 index 0000000..123498b Binary files /dev/null and b/material/images/FlagZombie_3.png differ diff --git a/material/images/FlagZombie_4.png b/material/images/FlagZombie_4.png new file mode 100644 index 0000000..6fd048e Binary files /dev/null and b/material/images/FlagZombie_4.png differ diff --git a/material/images/FlagZombie_5.png b/material/images/FlagZombie_5.png new file mode 100644 index 0000000..cfcc993 Binary files /dev/null and b/material/images/FlagZombie_5.png differ diff --git a/material/images/FlagZombie_6.png b/material/images/FlagZombie_6.png new file mode 100644 index 0000000..57190e4 Binary files /dev/null and b/material/images/FlagZombie_6.png differ diff --git a/material/images/FlagZombie_7.png b/material/images/FlagZombie_7.png new file mode 100644 index 0000000..56cdffb Binary files /dev/null and b/material/images/FlagZombie_7.png differ diff --git a/material/images/FlagZombie_8.png b/material/images/FlagZombie_8.png new file mode 100644 index 0000000..fd72dcb Binary files /dev/null and b/material/images/FlagZombie_8.png differ diff --git a/material/images/FlagZombie_9.png b/material/images/FlagZombie_9.png new file mode 100644 index 0000000..725e120 Binary files /dev/null and b/material/images/FlagZombie_9.png differ diff --git a/material/images/GameOver.png b/material/images/GameOver.png new file mode 100644 index 0000000..b7d48a5 Binary files /dev/null and b/material/images/GameOver.png differ diff --git a/material/images/Help.png b/material/images/Help.png new file mode 100644 index 0000000..35efacc Binary files /dev/null and b/material/images/Help.png differ diff --git a/material/images/NormalCard_1.png b/material/images/NormalCard_1.png new file mode 100644 index 0000000..6cdb0bd Binary files /dev/null and b/material/images/NormalCard_1.png differ diff --git a/material/images/NormalCard_2.png b/material/images/NormalCard_2.png new file mode 100644 index 0000000..728da74 Binary files /dev/null and b/material/images/NormalCard_2.png differ diff --git a/material/images/NormalCard_3.png b/material/images/NormalCard_3.png new file mode 100644 index 0000000..9ced1d9 Binary files /dev/null and b/material/images/NormalCard_3.png differ diff --git a/material/images/NormalCard_4.png b/material/images/NormalCard_4.png new file mode 100644 index 0000000..820b4ee Binary files /dev/null and b/material/images/NormalCard_4.png differ diff --git a/material/images/NormalCard_5.png b/material/images/NormalCard_5.png new file mode 100644 index 0000000..57d1e9f Binary files /dev/null and b/material/images/NormalCard_5.png differ diff --git a/material/images/Peashooter.gif b/material/images/Peashooter.gif new file mode 100644 index 0000000..1fff4c4 Binary files /dev/null and b/material/images/Peashooter.gif differ diff --git a/material/images/Peashooter_00.png b/material/images/Peashooter_00.png new file mode 100644 index 0000000..4e6c221 Binary files /dev/null and b/material/images/Peashooter_00.png differ diff --git a/material/images/Peashooter_01.png b/material/images/Peashooter_01.png new file mode 100644 index 0000000..3eb1e3b Binary files /dev/null and b/material/images/Peashooter_01.png differ diff --git a/material/images/Peashooter_02.png b/material/images/Peashooter_02.png new file mode 100644 index 0000000..1e4d802 Binary files /dev/null and b/material/images/Peashooter_02.png differ diff --git a/material/images/Peashooter_03.png b/material/images/Peashooter_03.png new file mode 100644 index 0000000..ca8e12c Binary files /dev/null and b/material/images/Peashooter_03.png differ diff --git a/material/images/Peashooter_04.png b/material/images/Peashooter_04.png new file mode 100644 index 0000000..48189b7 Binary files /dev/null and b/material/images/Peashooter_04.png differ diff --git a/material/images/Peashooter_05.png b/material/images/Peashooter_05.png new file mode 100644 index 0000000..8a8d9ca Binary files /dev/null and b/material/images/Peashooter_05.png differ diff --git a/material/images/Peashooter_06.png b/material/images/Peashooter_06.png new file mode 100644 index 0000000..4a85651 Binary files /dev/null and b/material/images/Peashooter_06.png differ diff --git a/material/images/Peashooter_07.png b/material/images/Peashooter_07.png new file mode 100644 index 0000000..d5e13bf Binary files /dev/null and b/material/images/Peashooter_07.png differ diff --git a/material/images/Peashooter_08.png b/material/images/Peashooter_08.png new file mode 100644 index 0000000..01ca538 Binary files /dev/null and b/material/images/Peashooter_08.png differ diff --git a/material/images/Peashooter_09.png b/material/images/Peashooter_09.png new file mode 100644 index 0000000..823e553 Binary files /dev/null and b/material/images/Peashooter_09.png differ diff --git a/material/images/Peashooter_10.png b/material/images/Peashooter_10.png new file mode 100644 index 0000000..76d6600 Binary files /dev/null and b/material/images/Peashooter_10.png differ diff --git a/material/images/Peashooter_11.png b/material/images/Peashooter_11.png new file mode 100644 index 0000000..12ed0e3 Binary files /dev/null and b/material/images/Peashooter_11.png differ diff --git a/material/images/Peashooter_12.png b/material/images/Peashooter_12.png new file mode 100644 index 0000000..31ed739 Binary files /dev/null and b/material/images/Peashooter_12.png differ diff --git a/material/images/SeedBank.png b/material/images/SeedBank.png new file mode 100644 index 0000000..2ce77c8 Binary files /dev/null and b/material/images/SeedBank.png differ diff --git a/material/images/SunBack.png b/material/images/SunBack.png new file mode 100644 index 0000000..7ae71eb Binary files /dev/null and b/material/images/SunBack.png differ diff --git a/material/images/SunFlower_00.png b/material/images/SunFlower_00.png new file mode 100644 index 0000000..b3637f2 Binary files /dev/null and b/material/images/SunFlower_00.png differ diff --git a/material/images/SunFlower_01.png b/material/images/SunFlower_01.png new file mode 100644 index 0000000..bbeddab Binary files /dev/null and b/material/images/SunFlower_01.png differ diff --git a/material/images/SunFlower_02.png b/material/images/SunFlower_02.png new file mode 100644 index 0000000..16bae15 Binary files /dev/null and b/material/images/SunFlower_02.png differ diff --git a/material/images/SunFlower_03.png b/material/images/SunFlower_03.png new file mode 100644 index 0000000..59a5c49 Binary files /dev/null and b/material/images/SunFlower_03.png differ diff --git a/material/images/SunFlower_04.png b/material/images/SunFlower_04.png new file mode 100644 index 0000000..ba1c554 Binary files /dev/null and b/material/images/SunFlower_04.png differ diff --git a/material/images/SunFlower_05.png b/material/images/SunFlower_05.png new file mode 100644 index 0000000..edf68cb Binary files /dev/null and b/material/images/SunFlower_05.png differ diff --git a/material/images/SunFlower_06.png b/material/images/SunFlower_06.png new file mode 100644 index 0000000..945fc81 Binary files /dev/null and b/material/images/SunFlower_06.png differ diff --git a/material/images/SunFlower_07.png b/material/images/SunFlower_07.png new file mode 100644 index 0000000..73c3c10 Binary files /dev/null and b/material/images/SunFlower_07.png differ diff --git a/material/images/SunFlower_08.png b/material/images/SunFlower_08.png new file mode 100644 index 0000000..7e24f97 Binary files /dev/null and b/material/images/SunFlower_08.png differ diff --git a/material/images/SunFlower_09.png b/material/images/SunFlower_09.png new file mode 100644 index 0000000..afec52e Binary files /dev/null and b/material/images/SunFlower_09.png differ diff --git a/material/images/SunFlower_10.png b/material/images/SunFlower_10.png new file mode 100644 index 0000000..740e116 Binary files /dev/null and b/material/images/SunFlower_10.png differ diff --git a/material/images/SunFlower_11.png b/material/images/SunFlower_11.png new file mode 100644 index 0000000..4cba8a9 Binary files /dev/null and b/material/images/SunFlower_11.png differ diff --git a/material/images/SunFlower_12.png b/material/images/SunFlower_12.png new file mode 100644 index 0000000..2709795 Binary files /dev/null and b/material/images/SunFlower_12.png differ diff --git a/material/images/Sun_1.png b/material/images/Sun_1.png new file mode 100644 index 0000000..030a54f Binary files /dev/null and b/material/images/Sun_1.png differ diff --git a/material/images/Sun_10.png b/material/images/Sun_10.png new file mode 100644 index 0000000..287b7ac Binary files /dev/null and b/material/images/Sun_10.png differ diff --git a/material/images/Sun_11.png b/material/images/Sun_11.png new file mode 100644 index 0000000..24bd7bb Binary files /dev/null and b/material/images/Sun_11.png differ diff --git a/material/images/Sun_12.png b/material/images/Sun_12.png new file mode 100644 index 0000000..106943c Binary files /dev/null and b/material/images/Sun_12.png differ diff --git a/material/images/Sun_13.png b/material/images/Sun_13.png new file mode 100644 index 0000000..5d5724e Binary files /dev/null and b/material/images/Sun_13.png differ diff --git a/material/images/Sun_14.png b/material/images/Sun_14.png new file mode 100644 index 0000000..7db9499 Binary files /dev/null and b/material/images/Sun_14.png differ diff --git a/material/images/Sun_15.png b/material/images/Sun_15.png new file mode 100644 index 0000000..67c9de8 Binary files /dev/null and b/material/images/Sun_15.png differ diff --git a/material/images/Sun_16.png b/material/images/Sun_16.png new file mode 100644 index 0000000..0966846 Binary files /dev/null and b/material/images/Sun_16.png differ diff --git a/material/images/Sun_17.png b/material/images/Sun_17.png new file mode 100644 index 0000000..d779e8e Binary files /dev/null and b/material/images/Sun_17.png differ diff --git a/material/images/Sun_2.png b/material/images/Sun_2.png new file mode 100644 index 0000000..2895b91 Binary files /dev/null and b/material/images/Sun_2.png differ diff --git a/material/images/Sun_3.png b/material/images/Sun_3.png new file mode 100644 index 0000000..9a2a0b2 Binary files /dev/null and b/material/images/Sun_3.png differ diff --git a/material/images/Sun_4.png b/material/images/Sun_4.png new file mode 100644 index 0000000..5f1416e Binary files /dev/null and b/material/images/Sun_4.png differ diff --git a/material/images/Sun_5.png b/material/images/Sun_5.png new file mode 100644 index 0000000..a3c0e95 Binary files /dev/null and b/material/images/Sun_5.png differ diff --git a/material/images/Sun_6.png b/material/images/Sun_6.png new file mode 100644 index 0000000..25dd96a Binary files /dev/null and b/material/images/Sun_6.png differ diff --git a/material/images/Sun_7.png b/material/images/Sun_7.png new file mode 100644 index 0000000..a97bf00 Binary files /dev/null and b/material/images/Sun_7.png differ diff --git a/material/images/Sun_8.png b/material/images/Sun_8.png new file mode 100644 index 0000000..d2de4ab Binary files /dev/null and b/material/images/Sun_8.png differ diff --git a/material/images/Sun_9.png b/material/images/Sun_9.png new file mode 100644 index 0000000..1b2ec13 Binary files /dev/null and b/material/images/Sun_9.png differ diff --git a/material/images/Sunflower.gif b/material/images/Sunflower.gif new file mode 100644 index 0000000..77e5ffc Binary files /dev/null and b/material/images/Sunflower.gif differ diff --git a/material/images/Surface.png b/material/images/Surface.png new file mode 100644 index 0000000..8495a2e Binary files /dev/null and b/material/images/Surface.png differ diff --git a/material/images/Surface1.png b/material/images/Surface1.png new file mode 100644 index 0000000..83e11b4 Binary files /dev/null and b/material/images/Surface1.png differ diff --git a/material/images/TwinSunflower.gif b/material/images/TwinSunflower.gif new file mode 100644 index 0000000..616f227 Binary files /dev/null and b/material/images/TwinSunflower.gif differ diff --git a/material/images/WallNut.gif b/material/images/WallNut.gif new file mode 100644 index 0000000..7e30d13 Binary files /dev/null and b/material/images/WallNut.gif differ diff --git a/material/images/WallNut_00.png b/material/images/WallNut_00.png new file mode 100644 index 0000000..2e3e773 Binary files /dev/null and b/material/images/WallNut_00.png differ diff --git a/material/images/WallNut_01.png b/material/images/WallNut_01.png new file mode 100644 index 0000000..629af2b Binary files /dev/null and b/material/images/WallNut_01.png differ diff --git a/material/images/WallNut_02.png b/material/images/WallNut_02.png new file mode 100644 index 0000000..b74243a Binary files /dev/null and b/material/images/WallNut_02.png differ diff --git a/material/images/WallNut_03.png b/material/images/WallNut_03.png new file mode 100644 index 0000000..de4b2aa Binary files /dev/null and b/material/images/WallNut_03.png differ diff --git a/material/images/WallNut_04.png b/material/images/WallNut_04.png new file mode 100644 index 0000000..f6415ee Binary files /dev/null and b/material/images/WallNut_04.png differ diff --git a/material/images/WallNut_05.png b/material/images/WallNut_05.png new file mode 100644 index 0000000..bbad911 Binary files /dev/null and b/material/images/WallNut_05.png differ diff --git a/material/images/WallNut_06.png b/material/images/WallNut_06.png new file mode 100644 index 0000000..9e6485d Binary files /dev/null and b/material/images/WallNut_06.png differ diff --git a/material/images/WallNut_07.png b/material/images/WallNut_07.png new file mode 100644 index 0000000..b32ec06 Binary files /dev/null and b/material/images/WallNut_07.png differ diff --git a/material/images/WallNut_08.png b/material/images/WallNut_08.png new file mode 100644 index 0000000..76c9258 Binary files /dev/null and b/material/images/WallNut_08.png differ diff --git a/material/images/WallNut_09.png b/material/images/WallNut_09.png new file mode 100644 index 0000000..23d82bd Binary files /dev/null and b/material/images/WallNut_09.png differ diff --git a/material/images/WallNut_10.png b/material/images/WallNut_10.png new file mode 100644 index 0000000..2003f81 Binary files /dev/null and b/material/images/WallNut_10.png differ diff --git a/material/images/WallNut_11.png b/material/images/WallNut_11.png new file mode 100644 index 0000000..2f25f81 Binary files /dev/null and b/material/images/WallNut_11.png differ diff --git a/material/images/WallNut_12.png b/material/images/WallNut_12.png new file mode 100644 index 0000000..c0b773c Binary files /dev/null and b/material/images/WallNut_12.png differ diff --git a/material/images/Wallnut_body.png b/material/images/Wallnut_body.png new file mode 100644 index 0000000..6272ec8 Binary files /dev/null and b/material/images/Wallnut_body.png differ diff --git a/material/images/Wallnut_cracked1.png b/material/images/Wallnut_cracked1.png new file mode 100644 index 0000000..58ae4c7 Binary files /dev/null and b/material/images/Wallnut_cracked1.png differ diff --git a/material/images/Wallnut_cracked2.png b/material/images/Wallnut_cracked2.png new file mode 100644 index 0000000..8805559 Binary files /dev/null and b/material/images/Wallnut_cracked2.png differ diff --git a/material/images/ZombieAttack_0.png b/material/images/ZombieAttack_0.png new file mode 100644 index 0000000..7d8a709 Binary files /dev/null and b/material/images/ZombieAttack_0.png differ diff --git a/material/images/ZombieAttack_1.png b/material/images/ZombieAttack_1.png new file mode 100644 index 0000000..39b2e9c Binary files /dev/null and b/material/images/ZombieAttack_1.png differ diff --git a/material/images/ZombieAttack_10.png b/material/images/ZombieAttack_10.png new file mode 100644 index 0000000..e8cd348 Binary files /dev/null and b/material/images/ZombieAttack_10.png differ diff --git a/material/images/ZombieAttack_11.png b/material/images/ZombieAttack_11.png new file mode 100644 index 0000000..6cf81b5 Binary files /dev/null and b/material/images/ZombieAttack_11.png differ diff --git a/material/images/ZombieAttack_12.png b/material/images/ZombieAttack_12.png new file mode 100644 index 0000000..a88abe2 Binary files /dev/null and b/material/images/ZombieAttack_12.png differ diff --git a/material/images/ZombieAttack_13.png b/material/images/ZombieAttack_13.png new file mode 100644 index 0000000..4b14e05 Binary files /dev/null and b/material/images/ZombieAttack_13.png differ diff --git a/material/images/ZombieAttack_14.png b/material/images/ZombieAttack_14.png new file mode 100644 index 0000000..8d534db Binary files /dev/null and b/material/images/ZombieAttack_14.png differ diff --git a/material/images/ZombieAttack_15.png b/material/images/ZombieAttack_15.png new file mode 100644 index 0000000..7ef5ece Binary files /dev/null and b/material/images/ZombieAttack_15.png differ diff --git a/material/images/ZombieAttack_16.png b/material/images/ZombieAttack_16.png new file mode 100644 index 0000000..f865ce8 Binary files /dev/null and b/material/images/ZombieAttack_16.png differ diff --git a/material/images/ZombieAttack_17.png b/material/images/ZombieAttack_17.png new file mode 100644 index 0000000..bf862d6 Binary files /dev/null and b/material/images/ZombieAttack_17.png differ diff --git a/material/images/ZombieAttack_18.png b/material/images/ZombieAttack_18.png new file mode 100644 index 0000000..2c79f7a Binary files /dev/null and b/material/images/ZombieAttack_18.png differ diff --git a/material/images/ZombieAttack_19.png b/material/images/ZombieAttack_19.png new file mode 100644 index 0000000..ba51fb4 Binary files /dev/null and b/material/images/ZombieAttack_19.png differ diff --git a/material/images/ZombieAttack_2.png b/material/images/ZombieAttack_2.png new file mode 100644 index 0000000..28b7c67 Binary files /dev/null and b/material/images/ZombieAttack_2.png differ diff --git a/material/images/ZombieAttack_20.png b/material/images/ZombieAttack_20.png new file mode 100644 index 0000000..c85832f Binary files /dev/null and b/material/images/ZombieAttack_20.png differ diff --git a/material/images/ZombieAttack_3.png b/material/images/ZombieAttack_3.png new file mode 100644 index 0000000..0285bdd Binary files /dev/null and b/material/images/ZombieAttack_3.png differ diff --git a/material/images/ZombieAttack_4.png b/material/images/ZombieAttack_4.png new file mode 100644 index 0000000..ca725ee Binary files /dev/null and b/material/images/ZombieAttack_4.png differ diff --git a/material/images/ZombieAttack_5.png b/material/images/ZombieAttack_5.png new file mode 100644 index 0000000..65dad05 Binary files /dev/null and b/material/images/ZombieAttack_5.png differ diff --git a/material/images/ZombieAttack_6.png b/material/images/ZombieAttack_6.png new file mode 100644 index 0000000..9e6aaf1 Binary files /dev/null and b/material/images/ZombieAttack_6.png differ diff --git a/material/images/ZombieAttack_7.png b/material/images/ZombieAttack_7.png new file mode 100644 index 0000000..ce237f8 Binary files /dev/null and b/material/images/ZombieAttack_7.png differ diff --git a/material/images/ZombieAttack_8.png b/material/images/ZombieAttack_8.png new file mode 100644 index 0000000..cbbf419 Binary files /dev/null and b/material/images/ZombieAttack_8.png differ diff --git a/material/images/ZombieAttack_9.png b/material/images/ZombieAttack_9.png new file mode 100644 index 0000000..1f11a2f Binary files /dev/null and b/material/images/ZombieAttack_9.png differ diff --git a/material/images/ZombieDie_0.png b/material/images/ZombieDie_0.png new file mode 100644 index 0000000..9d10e8f Binary files /dev/null and b/material/images/ZombieDie_0.png differ diff --git a/material/images/ZombieDie_1.png b/material/images/ZombieDie_1.png new file mode 100644 index 0000000..60286af Binary files /dev/null and b/material/images/ZombieDie_1.png differ diff --git a/material/images/ZombieDie_2.png b/material/images/ZombieDie_2.png new file mode 100644 index 0000000..4b53947 Binary files /dev/null and b/material/images/ZombieDie_2.png differ diff --git a/material/images/ZombieDie_3.png b/material/images/ZombieDie_3.png new file mode 100644 index 0000000..13667b5 Binary files /dev/null and b/material/images/ZombieDie_3.png differ diff --git a/material/images/ZombieDie_4.png b/material/images/ZombieDie_4.png new file mode 100644 index 0000000..0ec7ebf Binary files /dev/null and b/material/images/ZombieDie_4.png differ diff --git a/material/images/ZombieDie_5.png b/material/images/ZombieDie_5.png new file mode 100644 index 0000000..2434fd6 Binary files /dev/null and b/material/images/ZombieDie_5.png differ diff --git a/material/images/ZombieDie_6.png b/material/images/ZombieDie_6.png new file mode 100644 index 0000000..10ab817 Binary files /dev/null and b/material/images/ZombieDie_6.png differ diff --git a/material/images/ZombieDie_7.png b/material/images/ZombieDie_7.png new file mode 100644 index 0000000..89f00b3 Binary files /dev/null and b/material/images/ZombieDie_7.png differ diff --git a/material/images/ZombieDie_8.png b/material/images/ZombieDie_8.png new file mode 100644 index 0000000..41a5356 Binary files /dev/null and b/material/images/ZombieDie_8.png differ diff --git a/material/images/ZombieDie_9.png b/material/images/ZombieDie_9.png new file mode 100644 index 0000000..34a36c1 Binary files /dev/null and b/material/images/ZombieDie_9.png differ diff --git a/material/images/Zombie_0.png b/material/images/Zombie_0.png new file mode 100644 index 0000000..7374d07 Binary files /dev/null and b/material/images/Zombie_0.png differ diff --git a/material/images/Zombie_0_hit.jpg b/material/images/Zombie_0_hit.jpg new file mode 100644 index 0000000..7436715 Binary files /dev/null and b/material/images/Zombie_0_hit.jpg differ diff --git a/material/images/Zombie_1.png b/material/images/Zombie_1.png new file mode 100644 index 0000000..33f6a2a Binary files /dev/null and b/material/images/Zombie_1.png differ diff --git a/material/images/Zombie_10.png b/material/images/Zombie_10.png new file mode 100644 index 0000000..2a824fc Binary files /dev/null and b/material/images/Zombie_10.png differ diff --git a/material/images/Zombie_11.png b/material/images/Zombie_11.png new file mode 100644 index 0000000..230036e Binary files /dev/null and b/material/images/Zombie_11.png differ diff --git a/material/images/Zombie_12.png b/material/images/Zombie_12.png new file mode 100644 index 0000000..0b7e980 Binary files /dev/null and b/material/images/Zombie_12.png differ diff --git a/material/images/Zombie_13.png b/material/images/Zombie_13.png new file mode 100644 index 0000000..f92fca2 Binary files /dev/null and b/material/images/Zombie_13.png differ diff --git a/material/images/Zombie_14.png b/material/images/Zombie_14.png new file mode 100644 index 0000000..4d28e18 Binary files /dev/null and b/material/images/Zombie_14.png differ diff --git a/material/images/Zombie_15.png b/material/images/Zombie_15.png new file mode 100644 index 0000000..4d28e18 Binary files /dev/null and b/material/images/Zombie_15.png differ diff --git a/material/images/Zombie_16.png b/material/images/Zombie_16.png new file mode 100644 index 0000000..465c8d8 Binary files /dev/null and b/material/images/Zombie_16.png differ diff --git a/material/images/Zombie_17.png b/material/images/Zombie_17.png new file mode 100644 index 0000000..a91f9b2 Binary files /dev/null and b/material/images/Zombie_17.png differ diff --git a/material/images/Zombie_18.png b/material/images/Zombie_18.png new file mode 100644 index 0000000..ab1fd30 Binary files /dev/null and b/material/images/Zombie_18.png differ diff --git a/material/images/Zombie_19.png b/material/images/Zombie_19.png new file mode 100644 index 0000000..ddbb66a Binary files /dev/null and b/material/images/Zombie_19.png differ diff --git a/material/images/Zombie_2.png b/material/images/Zombie_2.png new file mode 100644 index 0000000..6ca00cb Binary files /dev/null and b/material/images/Zombie_2.png differ diff --git a/material/images/Zombie_20.png b/material/images/Zombie_20.png new file mode 100644 index 0000000..b3b5df4 Binary files /dev/null and b/material/images/Zombie_20.png differ diff --git a/material/images/Zombie_21.png b/material/images/Zombie_21.png new file mode 100644 index 0000000..112043c Binary files /dev/null and b/material/images/Zombie_21.png differ diff --git a/material/images/Zombie_3.png b/material/images/Zombie_3.png new file mode 100644 index 0000000..e8588a0 Binary files /dev/null and b/material/images/Zombie_3.png differ diff --git a/material/images/Zombie_4.png b/material/images/Zombie_4.png new file mode 100644 index 0000000..e10945a Binary files /dev/null and b/material/images/Zombie_4.png differ diff --git a/material/images/Zombie_5.png b/material/images/Zombie_5.png new file mode 100644 index 0000000..6965abe Binary files /dev/null and b/material/images/Zombie_5.png differ diff --git a/material/images/Zombie_6.png b/material/images/Zombie_6.png new file mode 100644 index 0000000..3d4914f Binary files /dev/null and b/material/images/Zombie_6.png differ diff --git a/material/images/Zombie_7.png b/material/images/Zombie_7.png new file mode 100644 index 0000000..8fc2f8a Binary files /dev/null and b/material/images/Zombie_7.png differ diff --git a/material/images/Zombie_8.png b/material/images/Zombie_8.png new file mode 100644 index 0000000..7f8a3ad Binary files /dev/null and b/material/images/Zombie_8.png differ diff --git a/material/images/Zombie_9.png b/material/images/Zombie_9.png new file mode 100644 index 0000000..ac88d77 Binary files /dev/null and b/material/images/Zombie_9.png differ diff --git a/material/images/background1.jpg b/material/images/background1.jpg new file mode 100644 index 0000000..7800df8 Binary files /dev/null and b/material/images/background1.jpg differ diff --git a/material/images/background2.jpg b/material/images/background2.jpg new file mode 100644 index 0000000..2263114 Binary files /dev/null and b/material/images/background2.jpg differ diff --git a/material/images/game_pause_nor.png b/material/images/game_pause_nor.png new file mode 100644 index 0000000..4339ac6 Binary files /dev/null and b/material/images/game_pause_nor.png differ diff --git a/material/images/logo.jpg b/material/images/logo.jpg new file mode 100644 index 0000000..e76e984 Binary files /dev/null and b/material/images/logo.jpg differ diff --git a/material/images/result_win.png b/material/images/result_win.png new file mode 100644 index 0000000..cbc1acb Binary files /dev/null and b/material/images/result_win.png differ diff --git a/material/images/win.jpg b/material/images/win.jpg new file mode 100644 index 0000000..1b46b29 Binary files /dev/null and b/material/images/win.jpg differ diff --git a/material/music/02 - Crazy Dave (Intro Theme).mp3 b/material/music/02 - Crazy Dave (Intro Theme).mp3 new file mode 100644 index 0000000..6cedc98 Binary files /dev/null and b/material/music/02 - Crazy Dave (Intro Theme).mp3 differ diff --git a/material/music/18 - Crazy Dave IN-GAME.mp3 b/material/music/18 - Crazy Dave IN-GAME.mp3 new file mode 100644 index 0000000..d9c4954 Binary files /dev/null and b/material/music/18 - Crazy Dave IN-GAME.mp3 differ diff --git a/material/music/4918.mp3 b/material/music/4918.mp3 new file mode 100644 index 0000000..e968a28 Binary files /dev/null and b/material/music/4918.mp3 differ diff --git a/plant_vs_zoomie_game.py b/plant_vs_zoomie_game.py new file mode 100644 index 0000000..9755598 --- /dev/null +++ b/plant_vs_zoomie_game.py @@ -0,0 +1,41 @@ +import time + +import pygame + +pygame.init() + +WIDTH = 360 +HEIGHT = 480 + +screen = pygame.display.set_mode((WIDTH,HEIGHT)) +pygame.display.set_caption('plant_vs_zoomie') + +# Colors (R, G, B) +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +RED = (255, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) + +myfont = pygame.font.Font(None,60) +# textImgage = myfont.render('pygame',True,WHITE) + +FPS = 60 +clock = pygame.time.Clock() +running = True +count = 0 +start = time.time() +while running: + clock.tick(FPS) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + count += 1 + now = time.time() + fps = count / (now -start) + fpsImgage = myfont.render(str(fps), True, WHITE) + + screen.fill(BLACK) + screen.blit(fpsImgage,(100,100)) + pygame.display.flip() diff --git a/plant_vs_zoomie_game02.py b/plant_vs_zoomie_game02.py new file mode 100644 index 0000000..8f5e2ef --- /dev/null +++ b/plant_vs_zoomie_game02.py @@ -0,0 +1,63 @@ + +import pygame +import os +WIDTH = 360 +HEIGHT = 480 + +pygame.init() +screen = pygame.display.set_mode((WIDTH,HEIGHT)) +pygame.display.set_caption('plant_vs_zoomie') + + + + +game_folder = os.path.dirname(__file__) +img_path = os.path.join(game_folder,'img') +player_img = pygame.image.load(os.path.join(img_path,'a.png')).convert_alpha() + +class Player(pygame.sprite.Sprite): + def __init__(self): + pygame.sprite.Sprite.__init__(self) + self.image = player_img + # self.image.fill((0, 255, 0)) + self.rect = self.image.get_rect() + self.rect.center = (WIDTH / 2, HEIGHT / 2) + + def update(self): + self.rect.x += 5 + if self.rect.left > WIDTH: + self.rect.right = 0 + + + +# Colors (R, G, B) +BLACK = (0, 0, 0) +WHITE = (255, 255, 255) +RED = (255, 0, 0) +GREEN = (0, 255, 0) +BLUE = (0, 0, 255) + +# myfont = pygame.font.Font(None,60) +# textImgage = myfont.render('pygame',True,WHITE) + +all_sprites = pygame.sprite.Group() +player = Player() +all_sprites.add(player) + + + +FPS = 60 +clock = pygame.time.Clock() +running = True + +while running: + clock.tick(FPS) + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + all_sprites.update() + + screen.fill(BLACK) + all_sprites.draw(screen) + pygame.display.flip() diff --git a/plant_vs_zoomie_game_final.py b/plant_vs_zoomie_game_final.py new file mode 100644 index 0000000..22ea772 --- /dev/null +++ b/plant_vs_zoomie_game_final.py @@ -0,0 +1,272 @@ +import time + +import pygame +import os + +from Bullet import Bullet +from FlagZombie import FlagZombie +from Peashooter import Peashooter +from SunFlower import SunFlower +from WallNut import WallNut +from Sun import Sun +from Zombie import Zombie + +pygame.init() +backgd_size = (1200, 600) + +screen = pygame.display.set_mode(backgd_size) +pygame.display.set_caption('plant_vs_zoomie') +#初始化音乐模块 +pygame.mixer.init() +#加载音乐 +pygame.mixer.music.load("material/music/02 - Crazy Dave (Intro Theme).mp3") + +bg_img_path = 'material/images/background1.jpg' +bg_img_obj = pygame.image.load(bg_img_path).convert_alpha() + +sunFlowerImg = pygame.image.load('material/images/SunFlower_00.png').convert_alpha() +wallnutImg = pygame.image.load('material/images/WallNut_00.png').convert_alpha() +peashooterImg = pygame.image.load('material/images/Peashooter_00.png').convert_alpha() +# sunbank_img_path = 'material/images/SunBack.png' +# sunbank_img_obj = pygame.image.load(sunbank_img_path).convert_alpha() + +sunbackImg = pygame.image.load('material/images/SeedBank.png').convert_alpha() +flower_seed = pygame.image.load("material/images/TwinSunflower.gif") +wallNut_seed = pygame.image.load("material/images/WallNut.gif") +peashooter_seed = pygame.image.load("material/images/Peashooter.gif") + + +text = '1000' +sun_font = pygame.font.SysFont('arial',20) +sun_num_surface = sun_font.render(text,True,(0,0,0)) + +# peashooter = Peashooter() +# sunflower = SunFlower() +# wallnut = WallNut() +# zombie = Zombie() + +# spriteGroup = pygame.sprite.Group() +# spriteGroup.add(peashooter) +# spriteGroup.add(sunflower) +# spriteGroup.add(wallnut) +# spriteGroup.add(zombie) +bulletGroup = pygame.sprite.Group() +zombieGroup = pygame.sprite.Group() +wallNutGroup = pygame.sprite.Group() +peaShooterGroup = pygame.sprite.Group() +sunFlowerGroup = pygame.sprite.Group() + +sunList = pygame.sprite.Group() + +# sunList = [] + +clock = pygame.time.Clock() + +GEN_SUN_EVENT = pygame.USEREVENT + 1 +pygame.time.set_timer(GEN_SUN_EVENT,1000) + +GEN_BULLET_EVENT = pygame.USEREVENT + 2 +pygame.time.set_timer(GEN_BULLET_EVENT,1000) + +GEN_ZOMBIE_EVENT = pygame.USEREVENT + 3 +pygame.time.set_timer(GEN_ZOMBIE_EVENT,5000) + +GEN_FLAGZOMBIE_EVENT = pygame.USEREVENT + 4 +pygame.time.set_timer(GEN_FLAGZOMBIE_EVENT,8000) + + +choose = 0 +def main(): + global text,choose + global sun_num_surface + running = True + index = 0 + while running: + # if index >= 130: + # index = 0 + + clock.tick(20) + if not pygame.mixer.music.get_busy(): + pygame.mixer.music.play() + #2s产生一个太阳花 + # if index % 40 == 0: + # sun = Sun(sunflower.rect) + # sunList.add(sun) + + #3s产生一个子弹 + # if index % 30 == 0: + # for sprite in spriteGroup: + # if isinstance(sprite, Peashooter): + # bullet = Bullet(sprite.rect, backgd_size) + # spriteGroup.add(bullet) + + for bullet in bulletGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(bullet,zombie): + zombie.energy -= 1 + bulletGroup.remove(bullet) + + for wallNut in wallNutGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(wallNut, zombie): + zombie.isMeetWallNut = True + wallNut.zombies.add(zombie) + + for peaShooter in peaShooterGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(peaShooter, zombie): + zombie.isMeetWallNut = True + peaShooter.zombies.add(zombie) + + for sunFlower in sunFlowerGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(sunFlower, zombie): + zombie.isMeetWallNut = True + sunFlower.zombies.add(zombie) + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbackImg,(250,0)) + screen.blit(sun_num_surface,(270,60)) + + screen.blit(flower_seed, (330, 10)) + screen.blit(wallNut_seed, (380, 10)) + screen.blit(peashooter_seed, (430, 10)) + + + # spriteGroup.update(index) + # spriteGroup.draw(screen) + bulletGroup.update(index) + bulletGroup.draw(screen) + zombieGroup.update(index) + zombieGroup.draw(screen) + + + wallNutGroup.update(index) + wallNutGroup.draw(screen) + peaShooterGroup.update(index) + peaShooterGroup.draw(screen) + + sunFlowerGroup.update(index) + sunFlowerGroup.draw(screen) + + sunList.update(index) + sunList.draw(screen) + + (x,y) = pygame.mouse.get_pos() + # if choose == 1: + # screen.blit(sunFlowerImg,(x,y)) + # elif choose == 2: + # screen.blit(wallnutImg, (x, y)) + # elif choose == 3: + # screen.blit(peashooterImg, (x, y)) + if choose == 1: + screen.blit(sunFlowerImg, (x - sunFlowerImg.get_rect().width // 2, y - sunFlowerImg.get_rect().height // 2)) + if choose == 2: + screen.blit(wallnutImg, (x - wallnutImg.get_rect().width // 2, y - wallnutImg.get_rect().height // 2)) + if choose == 3: + screen.blit(peashooterImg, + (x - peashooterImg.get_rect().width // 2, y - peashooterImg.get_rect().height // 2)) + + index+=1 + + + + + + for event in pygame.event.get(): + if event.type == GEN_FLAGZOMBIE_EVENT: + zombie = FlagZombie() + zombieGroup.add(zombie) + + if event.type == GEN_ZOMBIE_EVENT: + zombie = Zombie() + zombieGroup.add(zombie) + + if event.type == GEN_SUN_EVENT: + for sprite in sunFlowerGroup: + now = time.time() + if now - sprite.lasttime >= 5: + sun = Sun(sprite.rect) + sunList.add(sun) + sprite.lasttime = now + + if event.type == GEN_BULLET_EVENT: + for sprite in peaShooterGroup: + bullet = Bullet(sprite.rect, backgd_size) + bulletGroup.add(bullet) + + if event.type == pygame.QUIT: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + pressed_key = pygame.mouse.get_pressed() + print(pressed_key) + if pressed_key[0] == 1: + pos = pygame.mouse.get_pos() + print(pos) + x,y = pos + if 330<=x<=380 and 10<=y<=80 and int(text) >= 50: + print('点中了太阳花卡片') + choose = 1 + elif 380= 50: + print('点中了坚果卡片') + choose = 2 + elif 430 < x <= 480 and 10 <= y <= 80 and int(text) >= 100: + print('点中了豌豆射手卡片') + choose = 3 + elif 250 < x < 1200 and 70= 130: + index = 0 + + clock.tick(20) + + #2s产生一个太阳花 + if index % 40 == 0: + sun = Sun(sunflower.rect) + sunList.append(sun) + + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbank_img_obj,(250,0)) + screen.blit(sun_num_surface,(300,5)) + + screen.blit(peashooter.images[index%13],peashooter.rect) + screen.blit(sunflower.images[index % 13], sunflower.rect) + screen.blit(wallnut.images[index % 13], wallnut.rect) + + for sun in sunList: + screen.blit(sun.images[index % 17], sun.rect) + + + index+=1 + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + pygame.display.update() + +if __name__ == '__main__': + main() diff --git a/plant_vs_zoomie_game_normal03.py b/plant_vs_zoomie_game_normal03.py new file mode 100644 index 0000000..6171c92 --- /dev/null +++ b/plant_vs_zoomie_game_normal03.py @@ -0,0 +1,74 @@ +import pygame +import os +from Peashooter import Peashooter +from SunFlower import SunFlower +from WallNut import WallNut +from Sun import Sun +from Zombie import Zombie + +pygame.init() +backgd_size = (1200, 600) + +screen = pygame.display.set_mode(backgd_size) +pygame.display.set_caption('plant_vs_zoomie') + +bg_img_path = 'material/images/background1.jpg' +bg_img_obj = pygame.image.load(bg_img_path).convert_alpha() + +sunbank_img_path = 'material/images/SunBack.png' +sunbank_img_obj = pygame.image.load(sunbank_img_path).convert_alpha() + +text = '900' +sun_font = pygame.font.SysFont('arial',25) +sun_num_surface = sun_font.render(text,True,(0,0,0)) + +peashooter = Peashooter() +sunflower = SunFlower() +wallnut = WallNut() +zombie = Zombie() + +spriteGroup = pygame.sprite.Group() +spriteGroup.add(peashooter) +spriteGroup.add(sunflower) +spriteGroup.add(wallnut) +spriteGroup.add(zombie) + + +# sunList = [] + +clock = pygame.time.Clock() + + + +def main(): + running = True + index = 0 + while running: + if index >= 130: + index = 0 + + clock.tick(20) + + #2s产生一个太阳花 + if index % 40 == 0: + sun = Sun(sunflower.rect) + spriteGroup.add(sun) + + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbank_img_obj,(250,0)) + screen.blit(sun_num_surface,(300,5)) + + spriteGroup.update(index) + spriteGroup.draw(screen) + + index+=1 + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + pygame.display.update() + +if __name__ == '__main__': + main() diff --git a/plant_vs_zoomie_game_normal04.py b/plant_vs_zoomie_game_normal04.py new file mode 100644 index 0000000..a67f117 --- /dev/null +++ b/plant_vs_zoomie_game_normal04.py @@ -0,0 +1,129 @@ +import pygame +import os + +from Bullet import Bullet +from Peashooter import Peashooter +from SunFlower import SunFlower +from WallNut import WallNut +from Sun import Sun +from Zombie import Zombie + +pygame.init() +backgd_size = (1200, 600) + +screen = pygame.display.set_mode(backgd_size) +pygame.display.set_caption('plant_vs_zoomie') + +bg_img_path = 'material/images/background1.jpg' +bg_img_obj = pygame.image.load(bg_img_path).convert_alpha() + +# sunbank_img_path = 'material/images/SunBack.png' +# sunbank_img_obj = pygame.image.load(sunbank_img_path).convert_alpha() + +sunbackImg = pygame.image.load('material/images/SeedBank.png').convert_alpha() +flower_seed = pygame.image.load("material/images/TwinSunflower.gif") +wallNut_seed = pygame.image.load("material/images/WallNut.gif") +peashooter_seed = pygame.image.load("material/images/Peashooter.gif") + + +text = '1000' +sun_font = pygame.font.SysFont('arial',25) +sun_num_surface = sun_font.render(text,True,(0,0,0)) + +peashooter = Peashooter() +# sunflower = SunFlower() +wallnut = WallNut() +zombie = Zombie() + +spriteGroup = pygame.sprite.Group() +spriteGroup.add(peashooter) +# spriteGroup.add(sunflower) +spriteGroup.add(wallnut) +spriteGroup.add(zombie) + +sunList = pygame.sprite.Group() + +# sunList = [] + +clock = pygame.time.Clock() + +GEN_SUN_EVENT = pygame.USEREVENT + 1 +pygame.time.set_timer(GEN_SUN_EVENT,2000) +choose = 0 +def main(): + global text + global sun_num_surface + running = True + index = 0 + while running: + # if index >= 130: + # index = 0 + + clock.tick(20) + + #2s产生一个太阳花 + # if index % 40 == 0: + # sun = Sun(sunflower.rect) + # sunList.add(sun) + + #3s产生一个子弹 + if index % 30 == 0: + bullet = Bullet(peashooter.rect, backgd_size) + spriteGroup.add(bullet) + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbackImg,(250,0)) + screen.blit(sun_num_surface,(270,60)) + + screen.blit(flower_seed, (330, 10)) + screen.blit(wallNut_seed, (380, 10)) + screen.blit(peashooter_seed, (430, 10)) + + + spriteGroup.update(index) + spriteGroup.draw(screen) + + sunList.update(index) + sunList.draw(screen) + + index+=1 + for event in pygame.event.get(): + if event.type == GEN_SUN_EVENT: + sun = Sun(sunflower.rect) + sunList.add(sun) + if event.type == pygame.QUIT: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + pressed_key = pygame.mouse.get_pressed() + print(pressed_key) + if pressed_key[0] == 1: + pos = pygame.mouse.get_pos() + print(pos) + x,y = pos + if 330<=x<=380 and 10<=y<=80 and int(text) >= 50: + print('点中了太阳花卡片') + choose = 1 + elif 380= 50: + print('点中了坚果卡片') + choose = 2 + elif 430 < x <= 480 and 10 <= y <= 80 and int(text) >= 100: + print('点中了豌豆射手卡片') + choose = 3 + elif 250 < x < 1200 and 70= 130: + # index = 0 + + clock.tick(20) + + #2s产生一个太阳花 + # if index % 40 == 0: + # sun = Sun(sunflower.rect) + # sunList.add(sun) + + #3s产生一个子弹 + # if index % 30 == 0: + # for sprite in spriteGroup: + # if isinstance(sprite, Peashooter): + # bullet = Bullet(sprite.rect, backgd_size) + # spriteGroup.add(bullet) + + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbackImg,(250,0)) + screen.blit(sun_num_surface,(270,60)) + + screen.blit(flower_seed, (330, 10)) + screen.blit(wallNut_seed, (380, 10)) + screen.blit(peashooter_seed, (430, 10)) + + + spriteGroup.update(index) + spriteGroup.draw(screen) + + sunList.update(index) + sunList.draw(screen) + + (x,y) = pygame.mouse.get_pos() + if choose == 1: + screen.blit(sunFlowerImg,(x,y)) + elif choose == 2: + screen.blit(wallnutImg, (x, y)) + elif choose == 3: + screen.blit(peashooterImg, (x, y)) + + index+=1 + for event in pygame.event.get(): + if event.type == GEN_SUN_EVENT: + for sprite in spriteGroup: + if isinstance(sprite,SunFlower): + now = time.time() + if now - sprite.lasttime >= 5: + sun = Sun(sprite.rect) + sunList.add(sun) + sprite.lasttime = now + + if event.type == GEN_BULLET_EVENT: + for sprite in spriteGroup: + if isinstance(sprite, Peashooter): + bullet = Bullet(sprite.rect, backgd_size) + spriteGroup.add(bullet) + + if event.type == pygame.QUIT: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + pressed_key = pygame.mouse.get_pressed() + print(pressed_key) + if pressed_key[0] == 1: + pos = pygame.mouse.get_pos() + print(pos) + x,y = pos + if 330<=x<=380 and 10<=y<=80 and int(text) >= 50: + print('点中了太阳花卡片') + choose = 1 + elif 380= 50: + print('点中了坚果卡片') + choose = 2 + elif 430 < x <= 480 and 10 <= y <= 80 and int(text) >= 100: + print('点中了豌豆射手卡片') + choose = 3 + elif 250 < x < 1200 and 70= 130: + # index = 0 + + clock.tick(20) + + #2s产生一个太阳花 + # if index % 40 == 0: + # sun = Sun(sunflower.rect) + # sunList.add(sun) + + #3s产生一个子弹 + # if index % 30 == 0: + # for sprite in spriteGroup: + # if isinstance(sprite, Peashooter): + # bullet = Bullet(sprite.rect, backgd_size) + # spriteGroup.add(bullet) + + for bullet in bulletGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(bullet,zombie): + zombie.energy -= 1 + bulletGroup.remove(bullet) + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbackImg,(250,0)) + screen.blit(sun_num_surface,(270,60)) + + screen.blit(flower_seed, (330, 10)) + screen.blit(wallNut_seed, (380, 10)) + screen.blit(peashooter_seed, (430, 10)) + + + spriteGroup.update(index) + spriteGroup.draw(screen) + bulletGroup.update(index) + bulletGroup.draw(screen) + zombieGroup.update(index) + zombieGroup.draw(screen) + + sunList.update(index) + sunList.draw(screen) + + (x,y) = pygame.mouse.get_pos() + if choose == 1: + screen.blit(sunFlowerImg,(x,y)) + elif choose == 2: + screen.blit(wallnutImg, (x, y)) + elif choose == 3: + screen.blit(peashooterImg, (x, y)) + + index+=1 + + + + + + for event in pygame.event.get(): + if event.type == GEN_FLAGZOMBIE_EVENT: + zombie = FlagZombie() + zombieGroup.add(zombie) + + if event.type == GEN_ZOMBIE_EVENT: + zombie = Zombie() + zombieGroup.add(zombie) + + if event.type == GEN_SUN_EVENT: + for sprite in spriteGroup: + if isinstance(sprite,SunFlower): + now = time.time() + if now - sprite.lasttime >= 5: + sun = Sun(sprite.rect) + sunList.add(sun) + sprite.lasttime = now + + if event.type == GEN_BULLET_EVENT: + for sprite in spriteGroup: + if isinstance(sprite, Peashooter): + bullet = Bullet(sprite.rect, backgd_size) + bulletGroup.add(bullet) + + if event.type == pygame.QUIT: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + pressed_key = pygame.mouse.get_pressed() + print(pressed_key) + if pressed_key[0] == 1: + pos = pygame.mouse.get_pos() + print(pos) + x,y = pos + if 330<=x<=380 and 10<=y<=80 and int(text) >= 50: + print('点中了太阳花卡片') + choose = 1 + elif 380= 50: + print('点中了坚果卡片') + choose = 2 + elif 430 < x <= 480 and 10 <= y <= 80 and int(text) >= 100: + print('点中了豌豆射手卡片') + choose = 3 + elif 250 < x < 1200 and 70= 130: + # index = 0 + + clock.tick(20) + # if not pygame.mixer.music.get_busy(): + # pygame.mixer.music.play() + #2s产生一个太阳花 + # if index % 40 == 0: + # sun = Sun(sunflower.rect) + # sunList.add(sun) + + #3s产生一个子弹 + # if index % 30 == 0: + # for sprite in spriteGroup: + # if isinstance(sprite, Peashooter): + # bullet = Bullet(sprite.rect, backgd_size) + # spriteGroup.add(bullet) + + for bullet in bulletGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(bullet,zombie): + zombie.energy -= 1 + bulletGroup.remove(bullet) + + for wallNut in wallNutGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(wallNut, zombie): + zombie.isMeetWallNut = True + wallNut.zombies.add(zombie) + + for peaShooter in peaShooterGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(peaShooter, zombie): + zombie.isMeetWallNut = True + peaShooter.zombies.add(zombie) + + for sunFlower in sunFlowerGroup: + for zombie in zombieGroup: + if pygame.sprite.collide_mask(sunFlower, zombie): + zombie.isMeetWallNut = True + sunFlower.zombies.add(zombie) + + + screen.blit(bg_img_obj,(0,0)) + screen.blit(sunbackImg,(250,0)) + screen.blit(sun_num_surface,(270,60)) + + screen.blit(flower_seed, (330, 10)) + screen.blit(wallNut_seed, (380, 10)) + screen.blit(peashooter_seed, (430, 10)) + + + # spriteGroup.update(index) + # spriteGroup.draw(screen) + bulletGroup.update(index) + bulletGroup.draw(screen) + zombieGroup.update(index) + zombieGroup.draw(screen) + + + wallNutGroup.update(index) + wallNutGroup.draw(screen) + peaShooterGroup.update(index) + peaShooterGroup.draw(screen) + + sunFlowerGroup.update(index) + sunFlowerGroup.draw(screen) + + sunList.update(index) + sunList.draw(screen) + + (x,y) = pygame.mouse.get_pos() + # if choose == 1: + # screen.blit(sunFlowerImg,(x,y)) + # elif choose == 2: + # screen.blit(wallnutImg, (x, y)) + # elif choose == 3: + # screen.blit(peashooterImg, (x, y)) + if choose == 1: + screen.blit(sunFlowerImg, (x - sunFlowerImg.get_rect().width // 2, y - sunFlowerImg.get_rect().height // 2)) + if choose == 2: + screen.blit(wallnutImg, (x - wallnutImg.get_rect().width // 2, y - wallnutImg.get_rect().height // 2)) + if choose == 3: + screen.blit(peashooterImg, + (x - peashooterImg.get_rect().width // 2, y - peashooterImg.get_rect().height // 2)) + + index+=1 + + + + + + for event in pygame.event.get(): + if event.type == GEN_FLAGZOMBIE_EVENT: + zombie = FlagZombie() + zombieGroup.add(zombie) + + if event.type == GEN_ZOMBIE_EVENT: + zombie = Zombie() + zombieGroup.add(zombie) + + if event.type == GEN_SUN_EVENT: + for sprite in sunFlowerGroup: + now = time.time() + if now - sprite.lasttime >= 5: + sun = Sun(sprite.rect) + sunList.add(sun) + sprite.lasttime = now + + if event.type == GEN_BULLET_EVENT: + for sprite in peaShooterGroup: + bullet = Bullet(sprite.rect, backgd_size) + bulletGroup.add(bullet) + + if event.type == pygame.QUIT: + running = False + if event.type == pygame.MOUSEBUTTONDOWN: + pressed_key = pygame.mouse.get_pressed() + print(pressed_key) + if pressed_key[0] == 1: + pos = pygame.mouse.get_pos() + print(pos) + x,y = pos + if 330<=x<=380 and 10<=y<=80 and int(text) >= 50: + print('点中了太阳花卡片') + choose = 1 + elif 380= 50: + print('点中了坚果卡片') + choose = 2 + elif 430 < x <= 480 and 10 <= y <= 80 and int(text) >= 100: + print('点中了豌豆射手卡片') + choose = 3 + elif 250 < x < 1200 and 70