基于Python+Pygame實(shí)現(xiàn)變異狗大戰(zhàn)游戲
前言
只有你想不到,沒(méi)有我找不到寫(xiě)不了的好游戲!
哈嘍。我是你們的栗子同學(xué)啦~
今天小編去了我朋友家里玩兒,看到了一個(gè)敲可愛(ài)的小狗狗,是我朋友養(yǎng)的薩摩耶啦。心里羨慕一下下蠻。嘿嘿,但是我養(yǎng)肯定養(yǎng)不了滴~養(yǎng)狗狗的話(huà)要花費(fèi)好多時(shí)間遛一遛的啦,小編除了代碼就是代碼,沒(méi)這么多時(shí)間的啦~
嘿嘿,雖說(shuō)我養(yǎng)不了狗,但是我們可以擁有一款專(zhuān)屬的狗子游戲啊~
PS——
Python代碼版本的狗子大戰(zhàn), 你值得擁有, 哈哈哈,可以放心的玩哦~
吐槽:這華麗突出丑的出奇的出場(chǎng)方式以及界面,**以至于我都不知道怎么吹了~你說(shuō)呢?我覺(jué)得咳咳咳......主要是學(xué)習(xí)來(lái)的哈(學(xué)習(xí)編程知識(shí),丑一點(diǎn)兒沒(méi)關(guān)系哈,我突然良心通了一下下)。其實(shí)你可以給你的狗狗裝飾一下也不是不行,換一只也行,創(chuàng)造一只專(zhuān)屬于你的最強(qiáng)狗子吧!(其實(shí)確實(shí)有丑的出奇,23333~我自爆了。)
一、準(zhǔn)備環(huán)境
1)環(huán)境安裝
本文用到的環(huán)境如下——
Python3、Pycharm社區(qū)版,pygame其他自帶的庫(kù)只要安裝完 Python就可以直接使用了
一般安裝:pip install +模塊名
鏡像源安裝:pip install -i pypi.douban.com/simple/+模塊名…
(之前有說(shuō)過(guò)安裝報(bào)錯(cuò)的幾種方式跟解決方法,不會(huì)安裝的可以去看下,還有很多國(guó)內(nèi)鏡像源 也有文章的)
二、代碼展示
1)導(dǎo)入庫(kù)
import pygame, sys from pygame.locals import *
2)主程序
def pygame_run():
pygame.init()
_display_surf = pygame.display.set_mode((480, 320))
pygame.display.set_caption('py夢(mèng)')
_font_type = pygame.font.match_font('Microsoft YaHei')
# 敵方精靈狀態(tài),文字顯示
_ord_pym_rect = pygame.Rect(-260, 0, 220, 50)
# 敵方精靈名字,文字顯示設(shè)置
_ord_pym_name = pygame.font.Font(_font_type, 16)
_ord_pym_name_surf_obj = _ord_pym_name.render("lv10:它狗", True, BLACK, None)
_ord_pym_name_rect = _ord_pym_name_surf_obj.get_rect()
_ord_pym_name_rect.left = -200
_ord_pym_name_rect.top = 0
# 敵方精靈血量,文字顯示設(shè)置
_ord_pym_blood = pygame.font.Font(_font_type, 16)
_ord_pym_blood_surf_obj = _ord_pym_blood.render("血量:----------[69/69]", True, BLACK, None)
_ord_pym_blood_rect = _ord_pym_blood_surf_obj.get_rect()
_ord_pym_blood_rect.left = -200
_ord_pym_blood_rect.top = 20
# 敵方精靈貼圖顯示設(shè)置
_ord_pym_img = pygame.image.load('dog1.png')
_ord_pym_img_top = 20
_ord_pym_img_left = 320+220
# 我方精靈狀態(tài),文字顯示設(shè)置
_my_pym_rect = pygame.Rect(260, 170, 220, 50)
# 我方精靈名字,文字顯示設(shè)置
_my_pym_name = pygame.font.Font(_font_type, 16)
_my_pym_name_surf_obj = _my_pym_name.render("lv18:我狗", True, BLACK, None)
_my_pym_name_rect = _my_pym_name_surf_obj.get_rect()
_my_pym_name_rect.left = 480
_my_pym_name_rect.top = 170
# 我方精靈血量,文字顯示設(shè)置
_my_pym_blood = pygame.font.Font(_font_type, 16)
_my_pym_blood_surf_obj = _my_pym_blood.render("血量:----------[99/99]", True, BLACK, None)
_my_pym_blood_rect = _my_pym_blood_surf_obj.get_rect()
_my_pym_blood_rect.left = 480
_my_pym_blood_rect.top = 190
# 我方精靈貼圖顯示設(shè)置
_my_pym_img = pygame.image.load('dog2.png')
_my_pym_img_top = 80
_my_pym_img_left = 20-220
# 對(duì)戰(zhàn)面板,顯示設(shè)置
_select_rect = pygame.Rect(480, 220, 220, 95)
# 戰(zhàn)斗,文字顯示設(shè)置
_select_font_1 = pygame.font.Font(_font_type, 30)
_select_font_1_surf_obj = _select_font_1.render("戰(zhàn)斗", True, BLACK, None)
_select_font_1_rect = _select_font_1_surf_obj.get_rect()
_select_font_1_rect.left = 480
_select_font_1_rect.top = 220
# 道具,文字顯示設(shè)置
_select_font_2 = pygame.font.Font(_font_type, 30)
_select_font_2_surf_obj = _select_font_2.render("道具", True, BLACK, None)
_select_font_2_rect = _select_font_2_surf_obj.get_rect()
_select_font_2_rect.left = 580
_select_font_2_rect.top = 220
# 精靈,文字顯示設(shè)置
_select_font_3 = pygame.font.Font(_font_type, 30)
_select_font_3_surf_obj = _select_font_3.render("精靈", True, BLACK, None)
_select_font_3_rect = _select_font_3_surf_obj.get_rect()
_select_font_3_rect.left = 480
_select_font_3_rect.top = 270
# 逃跑,文字顯示設(shè)置
_select_font_4 = pygame.font.Font(_font_type, 30)
_select_font_4_surf_obj = _select_font_4.render("逃跑", True, BLACK, None)
_select_font_4_rect = _select_font_4_surf_obj.get_rect()
_select_font_4_rect.left = 580
_select_font_4_rect.top = 270
while True:
_display_surf.fill(WHITE)
pygame.draw.rect(_display_surf, BLACK, _select_rect, 1)
pygame.draw.rect(_display_surf, WHITE, _my_pym_rect, 0)
_display_surf.blit(_ord_pym_img, (_ord_pym_img_left, _ord_pym_img_top))
_display_surf.blit(_my_pym_img, (_my_pym_img_left, _my_pym_img_top))
_display_surf.blit(_ord_pym_name_surf_obj, _ord_pym_name_rect)
_display_surf.blit(_ord_pym_blood_surf_obj, _ord_pym_blood_rect)
_display_surf.blit(_my_pym_name_surf_obj, _my_pym_name_rect)
_display_surf.blit(_my_pym_blood_surf_obj, _my_pym_blood_rect)
_display_surf.blit(_select_font_1_surf_obj, _select_font_1_rect)
_display_surf.blit(_select_font_2_surf_obj, _select_font_2_rect)
_display_surf.blit(_select_font_3_surf_obj, _select_font_3_rect)
_display_surf.blit(_select_font_4_surf_obj, _select_font_4_rect)
if _select_rect.left != 260:
_select_rect.left = _select_rect.left - 5
_select_font_1_rect.left = _select_font_1_rect.left - 5
_select_font_2_rect.left = _select_font_2_rect.left - 5
_select_font_3_rect.left = _select_font_3_rect.left - 5
_select_font_4_rect.left = _select_font_4_rect.left - 5
_my_pym_name_rect.left = _my_pym_name_rect.left - 5
_my_pym_blood_rect.left = _my_pym_blood_rect.left - 5
_ord_pym_name_rect.left = _ord_pym_name_rect.left + 5
_ord_pym_blood_rect.left = _ord_pym_blood_rect.left + 5
_ord_pym_img_left = _ord_pym_img_left - 5
_my_pym_img_left = _my_pym_img_left + 5
for _event in pygame.event.get():
if _event.type == QUIT:
pygame.quit()
sys.exit()
pygame.display.update()
_fps_Clock.tick(FPS)
if __name__ == '__main__':
pygame_run()三、效果展示
1)出場(chǎng)方式第一步

2)出場(chǎng)方式第二步

3)出場(chǎng)方式第三步

到此這篇關(guān)于基于Python+Pygame實(shí)現(xiàn)變異狗大戰(zhàn)游戲的文章就介紹到這了,更多相關(guān)Python Pygame變異狗游戲內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
簡(jiǎn)單分析python的類(lèi)變量、實(shí)例變量
在本篇文章中小編給大家整理的是關(guān)于python類(lèi)變量、實(shí)例變量的知識(shí)點(diǎn)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2019-08-08
python獲取當(dāng)前用戶(hù)的主目錄路徑方法(推薦)
下面小編就為大家?guī)?lái)一篇python獲取當(dāng)前用戶(hù)的主目錄路徑方法(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01
python向MySQL數(shù)據(jù)庫(kù)插入數(shù)據(jù)的操作方法
這篇文章主要介紹了python向MySQL數(shù)據(jù)庫(kù)插入數(shù)據(jù),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-11-11
使用python檢測(cè)網(wǎng)頁(yè)文本內(nèi)容屏幕上的坐標(biāo)
在 Web 開(kāi)發(fā)中,經(jīng)常需要對(duì)網(wǎng)頁(yè)上的文本內(nèi)容進(jìn)行處理和操作,有時(shí)候,我們可能需要知道某個(gè)特定文本在屏幕上的位置,以便進(jìn)行后續(xù)的操作,所以本文將介紹如何使用 Python 中的 Selenium 和 BeautifulSoup 庫(kù)來(lái)檢測(cè)網(wǎng)頁(yè)文本內(nèi)容在屏幕上的坐標(biāo),需要的朋友可以參考下2024-04-04
Python Des加密解密如何實(shí)現(xiàn)軟件注冊(cè)碼機(jī)器碼
這篇文章主要介紹了Python Des加密解密如何實(shí)現(xiàn)軟件注冊(cè)碼機(jī)器碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01
淺析Python中g(shù)etattr和getattribute的調(diào)用
在Python中,getattr和getattribute是兩個(gè)用于屬性訪問(wèn)的重要函數(shù),它們可以在運(yùn)行時(shí)動(dòng)態(tài)地獲取對(duì)象的屬性或自定義屬性訪問(wèn)行為,下面我們就來(lái)學(xué)習(xí)一下它們的具體用法吧2023-11-11

