import pygame

from pygame.locals import *

import sys

from Bullet import Bullet

from Peashooter import Peashooter

from Sun import Sun

from SunFlower import SunFlower

from WallNut import WallNut

# 初始化pygame

from Zombie import Zombie

pygame.init()

for font in pygame.font.get_fonts():

print(font)

size = (1200, 600)

# 设置屏幕宽高

screen = pygame.display.set_mode(size)

# 设置屏幕标题

pygame.display.set_caption("植物大战僵尸")

backgroundImg = pygame.image.load('material/images/background1.jpg').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")

sunFlowerImg = pygame.image.load('material/images/SunFlower_00.png').convert_alpha()

wallNutImg = pygame.image.load('material/images/WallNut_00.png').convert_alpha()

score = '500'

myfont = pygame.font.SysFont('arial', 20)

txtImg = myfont.render(score, True, (0, 0, 0))

peashooter = Peashooter()

# sunFlower = SunFlower()

# wallNut = WallNut()

# zombie = Zombie()

spriteList = pygame.sprite.Group()

sunFlowerList = pygame.sprite.Group()

wallNutList = pygame.sprite.Group()

spriteList.add(peashooter)

# spriteList.add(sunFlower)

# spriteList.add(wallNut)

# spriteList.add(zombie)

sunList = pygame.sprite.Group()

zombieList = pygame.sprite.Group()

index = 0

clock = pygame.time.Clock()

GENERATOR_SUN_EVENT = pygame.USEREVENT + 1

pygame.time.set_timer(GENERATOR_SUN_EVENT, 5000)

GENERATOR_ZOMBIE_EVENT = pygame.USEREVENT + 2

pygame.time.set_timer(GENERATOR_ZOMBIE_EVENT, 5000)

choose = 0

while True:

clock.tick(15)

# 启动消息队列,获取消息并处理

for event in pygame.event.get():

if event.type == QUIT:

pygame.quit()

sys.exit()

if event.type == GENERATOR_SUN_EVENT:

# 当前是否有太阳花对象,有几个太阳花对象,就生成几个太阳

if len(sunFlowerList) > 0:

for sunFlower in sunFlowerList:

sun = Sun(sunFlower.rect)

sunList.add(sun)

if event.type == GENERATOR_ZOMBIE_EVENT:

zombie = Zombie()

zombieList.add(zombie)

if event.type == MOUSEBUTTONDOWN:

mouse_pressed = pygame.mouse.get_pressed()

# 判断是否按下的事鼠标左键

if mouse_pressed[0]:

(x, y) = pygame.mouse.get_pos()

# 判断鼠标是否点中了某个卡片

if 330 <= x <= 380 and 10 <= y <= 80 and int(score) >= 50:

choose = 1

elif 380 < x <= 430 and 10 <= y <= 80 and int(score) >= 50:

choose = 2

elif 430 < x <= 480 and 10 <= y <= 80 and int(score) >= 100:

choose = 3

elif 250 < x < 1200 and 70 < y < 600:

if choose == 1:

sunFlower = SunFlower()

sunFlower.rect.top = y

sunFlower.rect.left = x

sunFlowerList.add(sunFlower)

choose = 0

# 扣去太阳花相应的分数

score = int(score)

score -= 50

myfont = pygame.font.SysFont('arial', 20)

txtImg = myfont.render(str(score), True, (0, 0, 0))

if choose == 2:

wallNut = WallNut()

wallNut.rect.top = y

wallNut.rect.left = x

wallNutList.add(wallNut)

choose = 0

# 扣去太阳花相应的分数

score = int(score)

score -= 50

myfont = pygame.font.SysFont('arial', 20)

txtImg = myfont.render(str(score), True, (0, 0, 0))

for sun in sunList:

if sun.rect.collidepoint((x, y)):

# sunList.remove(sun)

sun.is_click = True

score = int(score) + 50

myfont = pygame.font.SysFont('arial', 20)

txtImg = myfont.render(str(score), True, (0, 0, 0))

screen.blit(backgroundImg, (0, 0))

screen.blit(sunbackImg, (250, 0))

screen.blit(txtImg, (270, 60))

screen.blit(flower_seed, (330, 10))

screen.blit(wallNut_seed, (380, 10))

screen.blit(peashooter_seed, (430, 10))

# 根据选中的卡片,将对应的植物图片,显示在当前鼠标的右下角,跟随鼠标移动

(x, y) = pygame.mouse.get_pos()

if choose == 1:

screen.blit(sunFlowerImg, (x, y))

if choose == 2:

screen.blit(wallNutImg, (x, y))

if choose == 3:

screen.blit(peashooter.images[0], (x, y))

if index % 10 == 0:

bullet = Bullet(peashooter.rect, size)

spriteList.add(bullet)

sunFlowerList.update(index)

sunFlowerList.draw(screen)

sunList.update(index)

sunList.draw(screen)

zombieList.update(index)

zombieList.draw(screen)

wallNutList.update(index)

wallNutList.draw(screen)

for zombie in zombieList:

headStr = '刘无敌'

yourfont = pygame.font.SysFont('simsunnsimsun', 30)

headpic = yourfont.render(headStr, True, (0, 0, 0))

screen.blit(headpic, (zombie.rect.left + 60, zombie.rect.top - 20))

index += 1

pygame.display.update()

'''坚果'''

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.rect = self.images[0].get_rect()

# self.rect.top = 280

# self.rect.left = 250

def update(self, *args):

self.image = self.images[args[0] % len(self.images)]

python植物大战僵尸 豆约翰,python植物大战僵尸十二之坚果摆放相关推荐

  1. python植物大战僵尸 豆约翰,python植物大战僵尸六之添加僵尸

    import pygame from pygame.locals import * import sys from Peashooter import Peashooter from Sun impo ...

  2. python植物大战僵尸 豆约翰_python植物大战僵尸十之拖拽卡片

    import pygame from pygame.locals import * import sys from Bullet import Bullet from Peashooter impor ...

  3. python植物大战僵尸 豆约翰,python植物大战僵尸十三之豌豆射手摆放

    import pygame from pygame.locals import * import sys from Bullet import Bullet from Peashooter impor ...

  4. Python编写微信打飞机小游戏(十二)

    如果觉得这篇文章对您有所启发,欢迎关注我的公众号,我会尽可能积极和大家交流,谢谢. Python编写微信打飞机小游戏(一) Python编写微信打飞机小游戏(二) Python编写微信打飞机小游戏(三 ...

  5. python爬虫框架教程_Python爬虫实战(十二):爬虫框架Scrapy的第一个爬虫示例入门教程...

    本文主要向大家介绍了Python爬虫实战的爬虫框架Scrapy的第一个爬虫示例入门教程,通过具体的内容向大家展现,希望对大家学习Python爬虫实战有所帮助. 我们使用dmoz.org这个网站来作为小 ...

  6. python获取今日头条搜索信息_python爬虫(十二、爬取今日头条关键词所有文章)

    今日头条 我们以搜索'妹子'为例 那 么 我 们 在 右 上 角 的 搜 索 框 搜 索 妹 子 , 出 来 了 一 系 列 文 章 那么我们在右上角的搜索框搜索妹子,出来了一系列文章那么我们在右上角 ...

  7. 八十二、Python | Leetcode贪心算法系列

    @Author:Runsen @Date:2020/7/5 人生最重要的不是所站的位置,而是内心所朝的方向.只要我在每篇博文中写得自己体会,修炼身心:在每天的不断重复学习中,耐住寂寞,练就真功,不畏艰 ...

  8. 七十二、Python | Leetcode字符串系列(下篇)

    @Author:Runsen @Date:2020/7/3 人生最重要的不是所站的位置,而是内心所朝的方向.只要我在每篇博文中写得自己体会,修炼身心:在每天的不断重复学习中,耐住寂寞,练就真功,不畏艰 ...

  9. python程序设计实践教程答案-Python程序设计实践教程

    书名:Python程序设计实践教程 定价:29.8 ISBN:9787115532602 作者:储岳中 薛希玲 版次:*1版 出版时间:2020-04 内容提要: 本书是Python语言程序设计的配套 ...

最新文章

  1. 【Qt】Qt5在ubuntu16.04无法输入中文解决方式
  2. [微信小程序]单选框以及多选框实例代码附讲解
  3. 【阿里云课程】残差网络原理,结构发展及有效性理解
  4. Boost.Flyweight 性能比较示例
  5. 测试计算机操作基础知识,计算机病毒基础知识测试
  6. input标签用法解读
  7. bzoj 1016 [JSOI2008]最小生成树计数——matrix tree(相同权值的边为阶段缩点)(码力)...
  8. 蓝桥杯 ALGO-83 算法训练 阶乘 java版
  9. Android Makefile and build system 分析
  10. SLAM--状态估计
  11. 数据库上机练习-1-建表
  12. storm任务提交流程
  13. 闰年2月29号 通过apache的ftp工具从ftp上下载文件失败
  14. 公园遛狗 / 小白逛公园【线段树】
  15. MySQL(八):InnoDB 日志缓冲区(Log Buffer)
  16. 揭秘可变剪切研究的本质
  17. python correlate_关于numpy互相关函数np.correlate的一点疑问
  18. JQ局域网通信软件(C/S)
  19. linux接路由器没反应,路由器连接网线指示灯没反应完美解决方法
  20. Windows+VScode配置与使用git,超详细教程,赶紧收藏吧

热门文章

  1. JPEG图像EXIF数据信息的解析
  2. 解决ubuntu12.04上无法运行Minitool的问题
  3. 两天快速开发一个自己的微信小程序
  4. python处理nc数据转换为tif格式
  5. 最有效的注意力集中训练法
  6. Oracle PL/SQL存储过程对象类型Object type详解 create type obj_type as object, create table tab_name of obj_type
  7. 怎样在自己的网站上集成paypal国际支付方式
  8. c语言程序 心理测试,简单心理测试题及答案
  9. s3c2410 bootloader 第一部分启动代码分析
  10. 网络认证小结——你有网络身份证吗?