日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python植物大战僵尸源码分享

發布時間:2023/12/20 python 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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植物大战僵尸源码分享的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。