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

peashooterImg = pygame.image.load('material/images/Peashooter_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()

peashooterList = pygame.sprite.Group()

sunFlowerList = pygame.sprite.Group()

wallNutList = pygame.sprite.Group()

bulletList = pygame.sprite.Group()

# peashooterList.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)

GENERATOR_PEASHOOTER_EVENT = pygame.USEREVENT + 3

pygame.time.set_timer(GENERATOR_PEASHOOTER_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_PEASHOOTER_EVENT:

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

if len(peashooterList) > 0:

for peashooter in peashooterList:

bullet = Bullet(peashooter.rect, size)

bulletList.add(bullet)

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

if choose == 3:

peashooter = Peashooter()

peashooter.rect.top = y

peashooter.rect.left = x

peashooterList.add(peashooter)

choose = 0

# 扣去太阳花相应的分数

score = int(score)

score -= 100

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(peashooterImg, (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)

peashooterList.update(index)

peashooterList.draw(screen)

bulletList.update(index)

bulletList.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

import random

class Bullet(pygame.sprite.Sprite):

def __init__(self, rect, bg_size):

super(Bullet, self).__init__()

self.image = pygame.image.load('material/images/Bullet_1.png').convert_alpha()

self.width, self.height = bg_size

self.rect = self.image.get_rect()

self.rect.top = rect.top

self.rect.left = rect.left + 50

self.speed = 10

# 更新精灵的位置

def update(self, *args):

if self.rect.left <= self.width:

self.rect.left += self.speed

else:

self.kill()

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. 第5课python植物大战僵尸-添加豌豆射手类

    提示:第5课python植物大战僵尸-添加豌豆射手类 文章目录 摘要 一.豌豆射手类 Peashooter 1.import导入pygame模块 2.定义一个豌豆射手的类型,不用继承任何的类 3.定义 ...

  5. Python浅析-从植物大战僵尸源代码入门Python 从Python就业前景分析如何学习

    源代码私信小编"学习"领取 Python到底有多火呢?Python的简单易学,应用领域广让Python语言一路飙升到不可磨灭的重要地位.先来看看Python的就业方向吧 Pytho ...

  6. scratch中的植物大战僵尸之豌豆射手收集豌豆

    这是一个简单的案例,主要的是运用植物大战僵尸里面的素材去做到一个好玩的小游戏,这个游戏的概念是教会小学生怎样运用一些变量还有数学中的知识,例如有负数和坐标的概念,下面我来展示一下我的这个案例: 有的小 ...

  7. Python 开发接豆人小游戏 TurnipBit

    Python 开发接豆人小游戏 TurnipBit 最近入手了一款MicroPython的开发板-TurnipBit,这个板子比较适合单片机入门,以及青少年编程,因为它有配备的在线图形编程. 官网地址 ...

  8. 学习python课程_想学习Python吗? 这是我们的免费4小时互动课程

    学习python课程 Python is a popular, versatile and easy-to-learn language. It's the go-to language for AI ...

  9. 37 岁接触 Python,3 年搭建 Python 金融“金字塔”

    导语: 在从事金融行业的20余年里,斯文博士拥有一系列闪亮的名片--经济学博士.中国注册会计师(CPA),特许金融分析师(CFA).金融风险管理师(FRM). 当金融科技(Fintech)被引入国内, ...

最新文章

  1. 最强写作AI竟然学会象棋和作曲,语言模型跨界操作引热议,在线求战
  2. Android--多点触控事件捕捉
  3. 优化Linux系统中的服务
  4. Vue3里的setup中使用vuex
  5. git clone 某次提交前代码_git提交代码常用命令
  6. java设计模式学习 ----- 单例模式(Singleton)
  7. a form 出口享惠情况_次磷酸8类危险品海运出口
  8. 如何让Mac电脑在Finder窗口顶部显示文件路径?
  9. matlab画受力分析图,MATLAB求解受力分析
  10. hdu1197(十进制十六进制十二进制位数和)
  11. し: make jianjie的文本网页
  12. 多个wordpress_40多个使用WordPress的热门大学
  13. Hubstudio指纹浏览器和MaxProxy代理的配置教程
  14. Mapped Statements collection already contains value
  15. 宏碁笔记本安装固态硬盘
  16. 如何学好游戏3D引擎编程(摘抄)
  17. indesign中怎么在冒号后面ctrl_InDesign不完全使用指南
  18. Maxima符号计算系统简介
  19. arm裸机程序启动流程
  20. 免费听好歌曲,音乐下载工具

热门文章

  1. 毫无意义的非均匀性校正----2研究现状
  2. clean my mac最新版多功能电脑管家类清理软件工具
  3. mysql 查看权限_MySQL查看用户权限
  4. 树—— 找树根和孩子
  5. coldfusion_ColdFusion中的一周:5月21日至27日:迟到总比不到好
  6. 一名合格的运维工程师都要掌握什么
  7. linux线程的创建与删除
  8. Ambassador介绍
  9. Python 世界的黑客帝国!
  10. Intent.ACTION_PROCESS_TEXT实现摘抄功能