Python植物大战僵尸源码分享
前言
今天给大家推荐一个Gtihub开源项目:PythonPlantsVsZombies,翻译成中就是植物大战僵尸。
《植物大战僵尸》是一款极富策略性的小游戏。可怕的僵尸即将入侵,每种僵尸都有不同的特点,例如铁桶僵尸拥有极强的抗击打能力,矿工僵尸可以挖地道绕过种植在土壤表面的植物等。玩家防御僵尸的方式就是栽种植物。49种植物每种都有不同的功能,例如樱桃炸弹可以和周围一定范围内的所有僵尸同归于尽,而食人花可以吃掉最靠近自己的一只僵尸。玩家可以针对不同僵尸的弱点来合理地种植植物,这也是胜利的诀窍。
功能实现
支持的植物:向日葵、豌豆射手、胡桃、雪豌豆射手、樱桃炸弹、三豌豆射手、大嘴花、puffshroom、马铃薯胺、穗状杂草、南瓜、胆小菇、墨西哥胡椒、阳光菇、冰川菇、催眠蘑菇。
支持僵尸:普通僵尸,旗帜僵尸,路障僵尸,铁桶僵尸,报纸僵尸。
支持在关卡开始时选择植物卡片。
支持白天级别、夜间级别、移动卡选择级别和胡桃保龄球
环境要求
1、python3.7
2、Python-Pygame 1.9
展示部分素材
游戏界面
个性化定义
游戏的关卡数据,存储在json文件里的。具体目录:PythonPlantsVsZombies-master\source\data。我们可以进行自定义配置,例如僵尸的位置和时间,背景信息。
主要代码
__author__ = 'marble_xu'import pygame as pg
from .. import tool
from .. import constants as cclass Menu(tool.State):
def __init__(self):tool.State.__init__(self)def startup(self, current_time, persist):
self.next = c.LEVEL
self.persist = persist
self.game_info = persistself.setupBackground()
self.setupOption()def setupBackground(self):frame_rect = [80, 0, 800, 600]
self.bg_image = tool.get_image(tool.GFX[c.MAIN_MENU_IMAGE], *frame_rect)
self.bg_rect = self.bg_image.get_rect()
self.bg_rect.x = 0
self.bg_rect.y = 0def setupOption(self):
self.option_frames = []frame_names = [c.OPTION_ADVENTURE + '_0', c.OPTION_ADVENTURE + '_1']frame_rect = [0, 0, 165, 77]for name in frame_names:
self.option_frames.append(tool.get_image(tool.GFX[name], *frame_rect, c.BLACK, 1.7))self.option_frame_index = 0
self.option_image = self.option_frames[self.option_frame_index]
self.option_rect = self.option_image.get_rect()
self.option_rect.x = 435
self.option_rect.y = 75self.option_start = 0
self.option_timer = 0
self.option_clicked = Falsedef checkOptionClick(self, mouse_pos):x, y = mouse_pos
if(x >= self.option_rect.x and x <= self.option_rect.right andy >= self.option_rect.y and y <= self.option_rect.bottom):
self.option_clicked = True
self.option_timer = self.option_start = self.current_time
return Falsedef update(self, surface, current_time, mouse_pos, mouse_click):
self.current_time = self.game_info[c.CURRENT_TIME] = current_timeif not self.option_clicked:
if mouse_pos:
self.checkOptionClick(mouse_pos)
else:
if(self.current_time - self.option_timer) > 200:
self.option_frame_index += 1
if self.option_frame_index >= 2:
self.option_frame_index = 0
self.option_timer = self.current_time
self.option_image = self.option_frames[self.option_frame_index]
if(self.current_time - self.option_start) > 1300:
self.done = Truesurface.blit(self.bg_image, self.bg_rect)surface.blit(self.option_image, self.option_rect)
__author__ = 'marble_xu'import pygame as pg
from .. import tool
from .. import constants as cclass Screen(tool.State):
def __init__(self):tool.State.__init__(self)
self.end_time = 3000def startup(self, current_time, persist):
self.start_time = current_time
self.next = c.LEVEL
self.persist = persist
self.game_info = persistname = self.getImageName()
self.setupImage(name)
self.next = self.set_next_state()def getImageName(self):passdef set_next_state(self):passdef setupImage(self, name):frame_rect = [0, 0, 800, 600]
self.image = tool.get_image(tool.GFX[name], *frame_rect)
self.rect = self.image.get_rect()
self.rect.x = 0
self.rect.y = 0def update(self, surface, current_time, mouse_pos, mouse_click):
if(current_time - self.start_time) < self.end_time:surface.fill(c.WHITE)surface.blit(self.image, self.rect)
else:
self.done = Trueclass GameVictoryScreen(Screen):
def __init__(self):Screen.__init__(self)def getImageName(self):
return c.GAME_VICTORY_IMAGEdef set_next_state(self):
return c.LEVELclass GameLoseScreen(Screen):
def __init__(self):Screen.__init__(self)def getImageName(self):
return c.GAME_LOOSE_IMAGEdef set_next_state(self):
return c.MAIN_MENU
Python植物大战僵尸源码分享相关推荐
- python版植物大战僵尸源码_基于python的植物大战僵尸游戏设计与实现.docx
湖南理工学院毕业设计(论文) PAGE PAGE 1 学 号 毕业设计(论文) 题目:基于python的植物大战僵尸游戏设计与实现 作 者 届 别 届 院 别 信息与通信工程学院 专 业 信息工程 指 ...
- 如何用python简单做一个植物大战僵尸 源码
简单实现的植物大战僵尸我自己网上扣了王校长的图做了个热狗射手hhhhhhhh最后面给大家分享一下我扣的热狗png图片求点赞!!!""" v1.81.完善僵尸类2.加载僵尸 ...
- 自己写的一个抢票加速的Python小程序源码分享-----纯属娱乐
最近这段时间频频看到微信群里发什么 抢票加速,智行.携程.飞猪.美团,对于我这能坐客车就不坐火车的人来说,无所谓靠谱不靠谱 突发奇想的整理了下整个抢票加速的逻辑,写了这个小程序,代码很low,拒绝批评 ...
- python抢票软件源代码_自己写的一个抢票加速的Python小程序源码分享-----纯属娱乐...
最近这段时间频频看到微信群里发什么 抢票加速,智行.携程.飞猪.美团,对于我这能坐客车就不坐火车的人来说,无所谓靠谱不靠谱 突发奇想的整理了下整个抢票加速的逻辑,写了这个小程序,代码很low,拒绝批评 ...
- python版植物大战僵尸源码_用Python写一个植物大战僵尸! 简直一模一样!
引入需要的模块 import pygame import random 配置图片地址 IMAGE_PATH = 'imgs/' 设置页面宽高 scrrr_width = 800 scrrr_heigh ...
- Python量化接口源码分享
量化接口的代码都要怎么找呢?其实很多股票论坛上都有,或者是一些编程相关的网站也能找到,直接搜索量化接口代码就有了,什么编程语言都有,比较多的是Python,而且Python也比较容易上手,适合大部分小 ...
- Android项目源码分享
├─android web应用 │ jqmDemo_static.zip │ jqmMobileDemo-master.zip │ jqmMobileDemo1_1-ma ...
- 用python实现植物大战僵尸(游戏截图+动态演示+源码分享)
大家好,我是梦执,对梦执着.希望能和大家共同进步! 下面给大家带来python实现植物大战僵尸的的源码分享,只含有冒险模式. 截图+动态演示+源码分享 游戏截图 动态演示 源码分享 state/too ...
- 植物大战僵尸以及超级玛丽源码分享
看到私信有许多小伙伴问我要源码,很抱歉不能及时回复,现在把源码放在这里啦.有需要自取 植物大战僵尸 演示地址:用python实现植物大战僵尸(游戏截图+动态演示+源码分享) 链接:点击获取源码 提取 ...
- 源码分享,送你一份Google Python class源码
几年前,Google推出Python课堂. Google Python课堂: https://developers.google.com/edu/python/ 小编也整理了一下Google Pyth ...
最新文章
- 爆气球这道题目,展开了新的思路
- Table-values parameter(TVP)系列之一:在T-SQL中创建和使用TVP
- Winform 打开下载的文件
- 亚麻纤维截面形态_天然丝纤维蚕丝
- MySQL定时备份(全量备份+增量备份)
- redis专题:redis键值设计、性能优化以及redis连接池配置
- vivado 使用DDS IP方法
- MainStoryboard.storyboard could not be opened
- w3c 菜鸟mysql_w3c菜鸟
- 多标签分类问题中的评价指标:准确率,交叉熵代价函数
- 第二篇 界面开发 (Android学习笔记)
- java极简使用FastFDFS文件服务器上传图片
- Log4j2官方文档翻译--欢迎使用Log4j2!
- 吾心,吾思,吾语,吾记
- 西门子精智和精简面板区别_西门子触摸屏操作面板区别
- 如何制定企业数据分析管理规范
- 解决 Hadoop 启动 ERROR: Attempting to operate on hdfs namenode as root 的方法
- LeetCode刷题记录(3)
- 数字新基建指南|数据中台赋能零售创造智慧新模式
- 堆排序对任一分支结点筛选时间复杂度