欢迎光临
我们一直在努力

Python植物大战僵尸源码分享

前言

今天给大家推荐一个Gtihub开源项目:PythonPlantsVsZombies,翻译成中就是植物大战僵尸。

《植物大战僵尸》是一款极富策略性的小游戏。可怕的僵尸即将入侵,每种僵尸都有不同的特点,例如铁桶僵尸拥有极强的抗击打能力,矿工僵尸可以挖地道绕过种植在土壤表面的植物等。玩家防御僵尸的方式就是栽种植物。49种植物每种都有不同的功能,例如樱桃炸弹可以和周围一定范围内的所有僵尸同归于尽,而食人花可以吃掉最靠近自己的一只僵尸。玩家可以针对不同僵尸的弱点来合理地种植植物,这也是胜利的诀窍。

功能实现

  • 支持的植物:向日葵、豌豆射手、胡桃、雪豌豆射手、樱桃炸弹、三豌豆射手、大嘴花、puffshroom、马铃薯胺、穗状杂草、南瓜、胆小菇、墨西哥胡椒、阳光菇、冰川菇、催眠蘑菇。

  • 支持僵尸:普通僵尸,旗帜僵尸,路障僵尸,铁桶僵尸,报纸僵尸。

  • 支持在关卡开始时选择植物卡片。

  • 支持白天级别、夜间级别、移动卡选择级别和胡桃保龄球

环境要求

1、python3.7

2、Python-Pygame 1.9

展示部分素材

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

游戏界面

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

Python植物大战僵尸源码分享

个性化定义

游戏的关卡数据,存储在json文件里的。具体目录:PythonPlantsVsZombies-master\source\data。我们可以进行自定义配置,例如僵尸的位置和时间,背景信息。

Python植物大战僵尸源码分享

主要代码

__author__ = 'marble_xu' import pygame as pg from .. import tool from .. import constants as c class 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 = persist self.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 = 0 def 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 = 75 self.option_start = 0 self.option_timer = 0 self.option_clicked = False def checkOptionClick(self, mouse_pos): x, y = mouse_pos if(x >= self.option_rect.x and x <= self.option_rect.right and y >= self.option_rect.y and y <= self.option_rect.bottom): self.option_clicked = True self.option_timer = self.option_start = self.current_time return False def update(self, surface, current_time, mouse_pos, mouse_click): self.current_time = self.game_info[c.CURRENT_TIME] = current_time if 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 = True surface.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 c class Screen(tool.State): def __init__(self): tool.State.__init__(self) self.end_time = 3000 def startup(self, current_time, persist): self.start_time = current_time self.next = c.LEVEL self.persist = persist self.game_info = persist name = self.getImageName() self.setupImage(name) self.next = self.set_next_state() def getImageName(self): pass def set_next_state(self): pass def 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 = 0 def 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 = True class GameVictoryScreen(Screen): def __init__(self): Screen.__init__(self) def getImageName(self): return c.GAME_VICTORY_IMAGE def set_next_state(self): return c.LEVEL class GameLoseScreen(Screen): def __init__(self): Screen.__init__(self) def getImageName(self): return c.GAME_LOOSE_IMAGE def set_next_state(self): return c.MAIN_MENU
  • 海报
海报图正在生成中...
赞(0) 打赏
声明:
1、本博客不从事任何主机及服务器租赁业务,不参与任何交易,也绝非中介。博客内容仅记录博主个人感兴趣的服务器测评结果及一些服务器相关的优惠活动,信息均摘自网络或来自服务商主动提供;所以对本博客提及的内容不作直接、间接、法定、约定的保证,博客内容也不具备任何参考价值及引导作用,访问者需自行甄别。
2、访问本博客请务必遵守有关互联网的相关法律、规定与规则;不能利用本博客所提及的内容从事任何违法、违规操作;否则造成的一切后果由访问者自行承担。
3、未成年人及不能独立承担法律责任的个人及群体请勿访问本博客。
4、一旦您访问本博客,即表示您已经知晓并接受了以上声明通告。
文章名称:《Python植物大战僵尸源码分享》
文章链接:https://www.456zj.com/37357.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址