Python编写植物大战僵尸
本文件包含Python编写的植物大战僵尸,亲测有效,并且代码加入了足够的注释,理解简单,半天便可学会
联系方式:upqcyjp@163.com
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-02-27 17:32 植物大战僵尸
目录 0 2020-02-27 17:32 植物大战僵尸.idea
文件 138 2020-02-26 18:35 植物大战僵尸.ideaencodings.xml
文件 448 2020-02-26 18:52 植物大战僵尸.ideagame.iml
文件 301 2020-02-26 18:52 植物大战僵尸.ideamisc.xml
文件 267 2020-02-26 18:35 植物大战僵尸.ideamodules.xml
文件 10541 2020-02-27 16:59 植物大战僵尸.ideaworkspace.xml
文件 6299 2020-02-27 16:56 植物大战僵尸main.py
目录 0 2020-02-27 17:32 植物大战僵尸
es
文件 7361 2020-02-26 18:45 植物大战僵尸
esackground.jpg
文件 1114 2020-02-26 21:33 植物大战僵尸
esullet.jpg
文件 8177 2020-02-27 12:58 植物大战僵尸
espeas.jpg
文件 10823 2020-02-26 21:39 植物大战僵尸
eszombie.jpg
目录 0 2020-02-27 17:32 植物大战僵尸venv
目录 0 2020-02-27 17:32 植物大战僵尸venvInclude
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesite
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesitepython3.5
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesitepython3.5pygame
文件 840 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_camera.h
文件 28409 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_pygame.h
文件 958 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_surface.h
文件 4777 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygameitmask.h
文件 6957 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamecamera.h
文件 1643 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefastevents.h
文件 1836 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefont.h
文件 4175 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefreetype.h
文件 620 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamemask.h
文件 2258 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamemixer.h
文件 7057 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepalette.h
文件 1060 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepgarrinter.h
文件 1961 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepgbufferproxy.h
............此处省略929个文件信息
import pygame
import random
from pygame.locals import *
# 窗体的高度和宽度
WIDTH = 1200
HEIGHT = 600
# 豌豆对象
class Peas:
def __init__(self):
self.image = pygame.image.load(“./res/peas.jpg“)
self.image_rect = self.image.get_rect()
self.image_rect.top = 280
self.image_rect.left = 30
# 设置豌豆是否上下移动
self.is_move_down = False
self.is_move_up = False
self.is_shout = False
def display(self):
“““豌豆显示在页面上“““
screen.blit(self.image self.image_rect)
def move_up(self):
if self.image_rect.top > 20:
self.image_rect.move_ip(0 -6)
for z in Zombie.zombie_list:
if self.image_rect.colliderect(z.image_rect) :
pygame.quit()
exit()
def move_down(self):
if self.image_rect.bottom < 580:
self.image_rect.move_ip(0 6)
for z in Zombie.zombie_list:
if self.image_rect.colliderect(z.image_rect):
pygame.quit()
exit()
def shout_bullet(self):
# 创建一个炮弹对象
bullet = Bullet(self)
# 保存创建的炮弹对象
Bullet.bullet_list.append(bullet)
# 炮弹对象
class Bullet:
# 显示所有的炮弹信息
bullet_list = []
# 炮弹的间隔信息
interval = 0
def __init__(self pea):
self.image = pygame.image.load(“./res/bullet.jpg“)
self.image_rect = self.image.get_rect()
self.image_rect.top = pea.image_rect.top+10
self.image_rect.left = pea.image_rect.right
# 设置豌豆是否上下移动
self.is_move_down = False
self.is_move_up = False
self.is_shout = False
def display(self):
“““炮弹显示在页面上“““
screen.blit(self.image self.image_rect)
def move(self):
self.image_rect.move_ip(100)
# 如果炮弹越界,删除炮弹
if self.image_rect.left > WIDTH - 50 :
Bullet.bullet_list.remove(self)
for z in Zombie.zombie_list:
if self.image_rect.colliderect(z.image_rect) :
Bullet.bullet_list.remove(self)
Zombie.zombie_list.remove(z)
break
# 僵尸对象
class Zombie:
# 创建频率
interval = 0
# 保存多个僵尸
zombie_list = []
def __init__(self):
self.image = pygame.image.load(“./res/zombie.jpg“)
# 改变图片大小
self.image = pygame.transform.scale(self.image (70 70))
self.image_rect = self.image.get_rect()
self.image_rect.top = random.randint(15 HEIGHT-80)
self.image_rect.left = WIDTH-100
def display(self):
“““僵尸显示在页面上“““
screen.blit(self.image self.image_rect)
def move(self):
“““僵尸移动“““
self.image_rect.move_ip(-20)
if self.image_rect.right <= 0 :
Zombie.zombie_list.remove(self)
for b in Bullet.bullet_list :
if self.image_rect.colliderect(b.image_rect) :
Zombie.zombie_list.remove(self)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2020-02-27 17:32 植物大战僵尸
目录 0 2020-02-27 17:32 植物大战僵尸.idea
文件 138 2020-02-26 18:35 植物大战僵尸.ideaencodings.xm
文件 448 2020-02-26 18:52 植物大战僵尸.ideagame.iml
文件 301 2020-02-26 18:52 植物大战僵尸.ideamisc.xm
文件 267 2020-02-26 18:35 植物大战僵尸.ideamodules.xm
文件 10541 2020-02-27 16:59 植物大战僵尸.ideaworkspace.xm
文件 6299 2020-02-27 16:56 植物大战僵尸main.py
目录 0 2020-02-27 17:32 植物大战僵尸
es
文件 7361 2020-02-26 18:45 植物大战僵尸
esackground.jpg
文件 1114 2020-02-26 21:33 植物大战僵尸
esullet.jpg
文件 8177 2020-02-27 12:58 植物大战僵尸
espeas.jpg
文件 10823 2020-02-26 21:39 植物大战僵尸
eszombie.jpg
目录 0 2020-02-27 17:32 植物大战僵尸venv
目录 0 2020-02-27 17:32 植物大战僵尸venvInclude
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesite
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesitepython3.5
目录 0 2020-02-27 17:32 植物大战僵尸venvIncludesitepython3.5pygame
文件 840 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_camera.h
文件 28409 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_pygame.h
文件 958 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygame\_surface.h
文件 4777 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygameitmask.h
文件 6957 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamecamera.h
文件 1643 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefastevents.h
文件 1836 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefont.h
文件 4175 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamefreetype.h
文件 620 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamemask.h
文件 2258 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamemixer.h
文件 7057 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepalette.h
文件 1060 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepgarrinter.h
文件 1961 2020-02-26 19:06 植物大战僵尸venvIncludesitepython3.5pygamepgbufferproxy.h
............此处省略929个文件信息
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)