Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
kamibababa committed Sep 2, 2022
0 parents commit 1c60327
Show file tree
Hide file tree
Showing 187 changed files with 1,732 additions and 0 deletions.
107 changes: 107 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
19 changes: 19 additions & 0 deletions Bullet.py
Original file line number Diff line number Diff line change
@@ -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()
25 changes: 25 additions & 0 deletions FlagZombie.py
Original file line number Diff line number Diff line change
@@ -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()
28 changes: 28 additions & 0 deletions Peashooter.py
Original file line number Diff line number Diff line change
@@ -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)]
23 changes: 23 additions & 0 deletions Player.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### 配套教程

[B站视频教程](https://www.bilibili.com/video/BV1EK4y187Kf)
[简书图片教程](https://www.jianshu.com/nb/33278365)

### 下载体验

链接:https://pan.baidu.com/s/1Icu2UkkHYfERhVU0USjHmw
提取码:yftf
23 changes: 23 additions & 0 deletions Sun.py
Original file line number Diff line number Diff line change
@@ -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)]

28 changes: 28 additions & 0 deletions SunFlower.py
Original file line number Diff line number Diff line change
@@ -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)]
44 changes: 44 additions & 0 deletions WallNut.py
Original file line number Diff line number Diff line change
@@ -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]
39 changes: 39 additions & 0 deletions Zombie.py
Original file line number Diff line number Diff line change
@@ -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
Binary file added material/images/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/Bullet_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombieAttack_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added material/images/FlagZombie_5.png
Binary file added material/images/FlagZombie_6.png
Binary file added material/images/FlagZombie_7.png
Binary file added material/images/FlagZombie_8.png
Binary file added material/images/FlagZombie_9.png
Binary file added material/images/GameOver.png
Binary file added material/images/Help.png
Binary file added material/images/NormalCard_1.png
Binary file added material/images/NormalCard_2.png
Binary file added material/images/NormalCard_3.png
Binary file added material/images/NormalCard_4.png
Binary file added material/images/NormalCard_5.png
Binary file added material/images/Peashooter.gif
Binary file added material/images/Peashooter_00.png
Binary file added material/images/Peashooter_01.png
Binary file added material/images/Peashooter_02.png
Binary file added material/images/Peashooter_03.png
Binary file added material/images/Peashooter_04.png
Binary file added material/images/Peashooter_05.png
Binary file added material/images/Peashooter_06.png
Binary file added material/images/Peashooter_07.png
Binary file added material/images/Peashooter_08.png
Binary file added material/images/Peashooter_09.png
Binary file added material/images/Peashooter_10.png
Binary file added material/images/Peashooter_11.png
Binary file added material/images/Peashooter_12.png
Binary file added material/images/SeedBank.png
Binary file added material/images/SunBack.png
Binary file added material/images/SunFlower_00.png
Binary file added material/images/SunFlower_01.png
Binary file added material/images/SunFlower_02.png
Binary file added material/images/SunFlower_03.png
Binary file added material/images/SunFlower_04.png
Binary file added material/images/SunFlower_05.png
Binary file added material/images/SunFlower_06.png
Binary file added material/images/SunFlower_07.png
Binary file added material/images/SunFlower_08.png
Binary file added material/images/SunFlower_09.png
Binary file added material/images/SunFlower_10.png
Binary file added material/images/SunFlower_11.png
Binary file added material/images/SunFlower_12.png
Binary file added material/images/Sun_1.png
Binary file added material/images/Sun_10.png
Binary file added material/images/Sun_11.png
Binary file added material/images/Sun_12.png
Binary file added material/images/Sun_13.png
Binary file added material/images/Sun_14.png
Binary file added material/images/Sun_15.png
Binary file added material/images/Sun_16.png
Binary file added material/images/Sun_17.png
Binary file added material/images/Sun_2.png
Binary file added material/images/Sun_3.png
Binary file added material/images/Sun_4.png
Binary file added material/images/Sun_5.png
Binary file added material/images/Sun_6.png
Binary file added material/images/Sun_7.png
Binary file added material/images/Sun_8.png
Binary file added material/images/Sun_9.png
Binary file added material/images/Sunflower.gif
Binary file added material/images/Surface.png
Binary file added material/images/Surface1.png
Binary file added material/images/TwinSunflower.gif
Binary file added material/images/WallNut.gif
Binary file added material/images/WallNut_00.png
Binary file added material/images/WallNut_01.png
Binary file added material/images/WallNut_02.png
Binary file added material/images/WallNut_03.png
Binary file added material/images/WallNut_04.png
Binary file added material/images/WallNut_05.png
Binary file added material/images/WallNut_06.png
Binary file added material/images/WallNut_07.png
Binary file added material/images/WallNut_08.png
Binary file added material/images/WallNut_09.png
Binary file added material/images/WallNut_10.png
Binary file added material/images/WallNut_11.png
Binary file added material/images/WallNut_12.png
Binary file added material/images/Wallnut_body.png
Binary file added material/images/Wallnut_cracked1.png
Binary file added material/images/Wallnut_cracked2.png
Binary file added material/images/ZombieAttack_0.png
Binary file added material/images/ZombieAttack_1.png
Binary file added material/images/ZombieAttack_10.png
Binary file added material/images/ZombieAttack_11.png
Binary file added material/images/ZombieAttack_12.png
Binary file added material/images/ZombieAttack_13.png
Binary file added material/images/ZombieAttack_14.png
Binary file added material/images/ZombieAttack_15.png
Binary file added material/images/ZombieAttack_16.png
Binary file added material/images/ZombieAttack_17.png
Binary file added material/images/ZombieAttack_18.png
Binary file added material/images/ZombieAttack_19.png
Binary file added material/images/ZombieAttack_2.png
Binary file added material/images/ZombieAttack_20.png
Binary file added material/images/ZombieAttack_3.png
Binary file added material/images/ZombieAttack_4.png
Binary file added material/images/ZombieAttack_5.png
Binary file added material/images/ZombieAttack_6.png
Binary file added material/images/ZombieAttack_7.png
Binary file added material/images/ZombieAttack_8.png
Binary file added material/images/ZombieAttack_9.png
Binary file added material/images/ZombieDie_0.png
Binary file added material/images/ZombieDie_1.png
Binary file added material/images/ZombieDie_2.png
Binary file added material/images/ZombieDie_3.png
Binary file added material/images/ZombieDie_4.png
Binary file added material/images/ZombieDie_5.png
Binary file added material/images/ZombieDie_6.png
Binary file added material/images/ZombieDie_7.png
Binary file added material/images/ZombieDie_8.png
Binary file added material/images/ZombieDie_9.png
Binary file added material/images/Zombie_0.png
Binary file added material/images/Zombie_0_hit.jpg
Binary file added material/images/Zombie_1.png
Binary file added material/images/Zombie_10.png
Binary file added material/images/Zombie_11.png
Binary file added material/images/Zombie_12.png
Binary file added material/images/Zombie_13.png
Binary file added material/images/Zombie_14.png
Binary file added material/images/Zombie_15.png
Binary file added material/images/Zombie_16.png
Binary file added material/images/Zombie_17.png
Binary file added material/images/Zombie_18.png
Binary file added material/images/Zombie_19.png
Binary file added material/images/Zombie_2.png
Binary file added material/images/Zombie_20.png
Binary file added material/images/Zombie_21.png
Binary file added material/images/Zombie_3.png
Binary file added material/images/Zombie_4.png
Binary file added material/images/Zombie_5.png
Binary file added material/images/Zombie_6.png
Binary file added material/images/Zombie_7.png
Binary file added material/images/Zombie_8.png
Binary file added material/images/Zombie_9.png
Binary file added material/images/background1.jpg
Binary file added material/images/background2.jpg
Binary file added material/images/game_pause_nor.png
Binary file added material/images/logo.jpg
Binary file added material/images/result_win.png
Binary file added material/images/win.jpg
Binary file added material/music/02 - Crazy Dave (Intro Theme).mp3
Binary file not shown.
Binary file added material/music/18 - Crazy Dave IN-GAME.mp3
Binary file not shown.
Binary file added material/music/4918.mp3
Binary file not shown.
41 changes: 41 additions & 0 deletions plant_vs_zoomie_game.py
Original file line number Diff line number Diff line change
@@ -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()
Loading

0 comments on commit 1c60327

Please sign in to comment.