0 項(xiàng)目簡(jiǎn)介
?? Hi,各位同學(xué)好呀,這里是L學(xué)長(zhǎng)!
??今天向大家分享一個(gè)今年(2022)最新完成的畢業(yè)設(shè)計(jì)項(xiàng)目作品
python小游戲畢設(shè) 坦克大戰(zhàn)小游戲設(shè)計(jì)與實(shí)現(xiàn) (源碼)
?? 學(xué)長(zhǎng)根據(jù)實(shí)現(xiàn)的難度和等級(jí)對(duì)項(xiàng)目進(jìn)行評(píng)分(最低0分,滿分5分)
-
難度系數(shù):3分
-
工作量:3分
-
創(chuàng)新點(diǎn):4分
-
項(xiàng)目獲?。?/strong>https://gitee.com/sinonfin/system-sharing
1 游戲介紹
《坦克大戰(zhàn)》是由日本南夢(mèng)宮Namco游戲公司開(kāi)發(fā)的一款平面射擊游戲,于1985年發(fā)售。游戲以坦克戰(zhàn)斗及保衛(wèi)基地為主題,屬于策略型聯(lián)機(jī)類(lèi)。
同時(shí)也是FC平臺(tái)上少有的內(nèi)建關(guān)卡編輯器的幾個(gè)游戲之一,玩家可自己創(chuàng)建獨(dú)特的關(guān)卡,并通過(guò)獲取一些道具使坦克和基地得到強(qiáng)化。
今天我們利用python實(shí)現(xiàn)簡(jiǎn)易版坦克大戰(zhàn)游戲。
2 實(shí)現(xiàn)效果
3 開(kāi)發(fā)工具
3.1 環(huán)境配置
-
Python版本:3.6.4
-
相關(guān)模塊:
-
pygame模塊;
-
以及一些Python自帶的模塊。
3.2 Pygame介紹
簡(jiǎn)介
Pygame是一系列專(zhuān)門(mén)為編寫(xiě)電子游戲而設(shè)計(jì)的Python模塊(modules)。Pygame在已經(jīng)非常優(yōu)秀的SDL庫(kù)的基礎(chǔ)上增加了許多功能。這讓你能夠用Python語(yǔ)言編寫(xiě)出豐富多彩的游戲程序。
Pygame可移植性高,幾乎能在任何平臺(tái)和操作系統(tǒng)上運(yùn)行。
Pygame已經(jīng)被下載過(guò)數(shù)百萬(wàn)次。
Pygame免費(fèi)開(kāi)源。它在LGPL許可證(Lesser General Public License,GNU寬通用公共許可證)下發(fā)行。使用Pygame,你可以創(chuàng)造出免費(fèi)開(kāi)源,可共享,或者商業(yè)化的游戲。詳情請(qǐng)見(jiàn)LGPL許可證。
優(yōu)點(diǎn)
-
能夠輕松使用多核CPU(multi core CPUs) :如今雙核CPU很常用,8核CPU在桌面系統(tǒng)中也很便宜,而利用好多核系統(tǒng),能讓你在你的游戲中實(shí)現(xiàn)更多東西。特定的pygame函數(shù)能夠釋放令人生畏的python GIL(全局解釋器鎖),這幾乎是你用C語(yǔ)言才能做的事。
-
核心函數(shù)用最優(yōu)化的C語(yǔ)言或匯編語(yǔ)言編寫(xiě):C語(yǔ)言代碼通常比Python代碼運(yùn)行速度快10-20倍。而匯編語(yǔ)言編寫(xiě)的代碼(assembly code)比Python甚至快到100多倍。
-
安裝便捷:一般僅需包管理程序或二進(jìn)制系統(tǒng)程序便能安裝。
-
真正地可移植:支持Linux (主要發(fā)行版), Windows (95, 98, ME, 2000, XP, Vista, 64-bit Windows,), Windows CE, BeOS, MacOS, Mac OS X, FreeBSD, NetBSD, OpenBSD, BSD/OS, Solaris, IRIX, and QNX等操作系統(tǒng).也能支持AmigaOS, Dreamcast, Atari, AIX, OSF/Tru64, RISC OS, SymbianOS and OS/2,但是還沒(méi)有受到官方認(rèn)可。你也可以在手持設(shè)備,游戲控制臺(tái), One Laptop Per Child (OLPC) computer項(xiàng)目的電腦等設(shè)備中使用pygame.
-
用法簡(jiǎn)單:無(wú)論是小孩子還是大人都能學(xué)會(huì)用pygame來(lái)制作射擊類(lèi)游戲。
-
很多Pygame游戲已發(fā)行:其中包括很多游戲大賽入圍作品、非常受歡迎的開(kāi)源可分享的游戲。
-
由你來(lái)控制主循環(huán):由你來(lái)調(diào)用pygame的函數(shù),pygame的函數(shù)并不需要調(diào)用你的函數(shù)。當(dāng)你同時(shí)還在使用其他庫(kù)來(lái)編寫(xiě)各種各種的程序時(shí),這能夠?yàn)槟闾峁O大的掌控權(quán)。
-
不需要GUI就能使用所有函數(shù):僅在命令行中,你就可以使用pygame的某些函數(shù)來(lái)處理圖片,獲取游戲桿輸入,播放音樂(lè)……
-
對(duì)bug反應(yīng)迅速:很多bug在被上報(bào)的1小時(shí)內(nèi)就能被我們修復(fù)。雖然有時(shí)候我們確實(shí)會(huì)卡在某一個(gè)bug上很久,但大多數(shù)時(shí)候我們都是很不錯(cuò)的bug修復(fù)者。如今bug的上報(bào)已經(jīng)很少了,因?yàn)樵S多bug早已被我們修復(fù)。
-
代碼量少:pygame并沒(méi)有數(shù)以萬(wàn)計(jì)的也許你永遠(yuǎn)用不到的冗雜代碼。pygame的核心代碼一直保持著簡(jiǎn)潔特點(diǎn),其他附加物諸如GUI庫(kù)等,都是在核心代碼之外單獨(dú)設(shè)計(jì)研發(fā)的。
-
模塊化:你可以單獨(dú)使用pygame的某個(gè)模塊。想要換著使用一個(gè)別的聲音處理庫(kù)?沒(méi)問(wèn)題。pygame的很多核心模塊支持獨(dú)立初始化與使用。
最小開(kāi)發(fā)框架
import pygame,sys #sys是python的標(biāo)準(zhǔn)庫(kù),提供Python運(yùn)行時(shí)環(huán)境變量的操控
pygame.init() #內(nèi)部各功能模塊進(jìn)行初始化創(chuàng)建及變量設(shè)置,默認(rèn)調(diào)用
size = width,height = 800,600 #設(shè)置游戲窗口大小,分別是寬度和高度
screen = pygame.display.set_mode(size) #初始化顯示窗口
pygame.display.set_caption("小游戲程序") #設(shè)置顯示窗口的標(biāo)題內(nèi)容,是一個(gè)字符串類(lèi)型
while True: #無(wú)限循環(huán),直到Python運(yùn)行時(shí)退出結(jié)束
for event in pygame.event.get(): #從Pygame的事件隊(duì)列中取出事件,并從隊(duì)列中刪除該事件
if event.type == pygame.QUIT: #獲得事件類(lèi)型,并逐類(lèi)響應(yīng)
sys.exit() #用于退出結(jié)束游戲并退出
pygame.display.update() #對(duì)顯示窗口進(jìn)行更新,默認(rèn)窗口全部重繪
代碼執(zhí)行流程
文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-780435.html
4 具體實(shí)現(xiàn)
4.1 實(shí)現(xiàn)游戲主循環(huán)
# 主函數(shù)
def main():
# 初始化
pygame.init()
screen = pygame.display.set_mode((630, 630))
pygame.display.set_caption("坦克大戰(zhàn)")
# 加載圖片
bg_img = pygame.image.load("./圖片/others/background.png")
# 開(kāi)始界面
num_player = show_start_interface(screen, 630, 630)
# 關(guān)卡
stage = 0
num_stage = 2
# 游戲是否結(jié)束
is_gameover = False
# 時(shí)鐘
clock = pygame.time.Clock()
# 主循環(huán)
while not is_gameover:
# 關(guān)卡
stage += 1
if stage > num_stage:
break
show_switch_stage(screen, 630, 630, stage)
# 該關(guān)卡坦克總數(shù)量
enemytanks_total = min(stage * 18, 80)
# 場(chǎng)上存在的敵方坦克總數(shù)量
enemytanks_now = 0
# 場(chǎng)上可以存在的敵方坦克總數(shù)量
enemytanks_now_max = min(max(stage * 2, 4), 8)
# 精靈組
tanksGroup = pygame.sprite.Group()
mytanksGroup = pygame.sprite.Group()
enemytanksGroup = pygame.sprite.Group()
bulletsGroup = pygame.sprite.Group()
mybulletsGroup = pygame.sprite.Group()
enemybulletsGroup = pygame.sprite.Group()
myfoodsGroup = pygame.sprite.Group()
# 自定義事件
# -生成敵方坦克事件
genEnemyEvent = pygame.constants.USEREVENT + 0
pygame.time.set_timer(genEnemyEvent, 100)
# -敵方坦克靜止恢復(fù)事件
recoverEnemyEvent = pygame.constants.USEREVENT + 1
pygame.time.set_timer(recoverEnemyEvent, 8000)
# -我方坦克無(wú)敵恢復(fù)事件
noprotectMytankEvent = pygame.constants.USEREVENT + 2
pygame.time.set_timer(noprotectMytankEvent, 8000)
# 關(guān)卡地圖
map_stage = scene.Map(stage)
# 我方坦克
tank_player1 = tanks.myTank(1)
tanksGroup.add(tank_player1)
mytanksGroup.add(tank_player1)
if num_player > 1:
tank_player2 = tanks.myTank(2)
tanksGroup.add(tank_player2)
mytanksGroup.add(tank_player2)
is_switch_tank = True
player1_moving = False
player2_moving = False
# 為了輪胎的動(dòng)畫(huà)效果
time = 0
# 敵方坦克
for i in range(0, 3):
if enemytanks_total > 0:
enemytank = tanks.enemyTank(i)
tanksGroup.add(enemytank)
enemytanksGroup.add(enemytank)
enemytanks_now += 1
enemytanks_total -= 1
# 大本營(yíng)
myhome = home.Home()
# 出場(chǎng)特效
appearance_img = pygame.image.load("./圖片/others/appear.png").convert_alpha()
appearances = []
appearances.append(appearance_img.subsurface((0, 0), (48, 48)))
appearances.append(appearance_img.subsurface((48, 0), (48, 48)))
appearances.append(appearance_img.subsurface((96, 0), (48, 48)))
# 關(guān)卡主循環(huán)
while True:
if is_gameover is True:
break
if enemytanks_total < 1 and enemytanks_now < 1:
is_gameover = False
break
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == genEnemyEvent:
if enemytanks_total > 0:
if enemytanks_now < enemytanks_now_max:
enemytank = tanks.enemyTank()
if not pygame.sprite.spritecollide(enemytank, tanksGroup, False, None):
tanksGroup.add(enemytank)
enemytanksGroup.add(enemytank)
enemytanks_now += 1
enemytanks_total -= 1
if event.type == recoverEnemyEvent:
for each in enemytanksGroup:
each.can_move = True
if event.type == noprotectMytankEvent:
for each in mytanksGroup:
mytanksGroup.protected = False
# 檢查用戶(hù)鍵盤(pán)操作
key_pressed = pygame.key.get_pressed()
# 玩家一
# WSAD -> 上下左右
# 空格鍵射擊
if key_pressed[pygame.K_w]:
tanksGroup.remove(tank_player1)
tank_player1.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player1)
player1_moving = True
elif key_pressed[pygame.K_s]:
tanksGroup.remove(tank_player1)
tank_player1.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player1)
player1_moving = True
elif key_pressed[pygame.K_a]:
tanksGroup.remove(tank_player1)
tank_player1.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player1)
player1_moving = True
elif key_pressed[pygame.K_d]:
tanksGroup.remove(tank_player1)
tank_player1.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player1)
player1_moving = True
elif key_pressed[pygame.K_SPACE]:
if not tank_player1.bullet.being:
tank_player1.shoot()
# 玩家二
# ↑↓←→ -> 上下左右
# 小鍵盤(pán)0鍵射擊
if num_player > 1:
if key_pressed[pygame.K_UP]:
tanksGroup.remove(tank_player2)
tank_player2.move_up(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player2)
player2_moving = True
elif key_pressed[pygame.K_DOWN]:
tanksGroup.remove(tank_player2)
tank_player2.move_down(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player2)
player2_moving = True
elif key_pressed[pygame.K_LEFT]:
tanksGroup.remove(tank_player2)
tank_player2.move_left(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player2)
player2_moving = True
elif key_pressed[pygame.K_RIGHT]:
tanksGroup.remove(tank_player2)
tank_player2.move_right(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(tank_player2)
player2_moving = True
elif key_pressed[pygame.K_KP0]:
if not tank_player2.bullet.being:
tank_player2.shoot()
# 背景
screen.blit(bg_img, (0, 0))
# 石頭墻
for each in map_stage.brickGroup:
screen.blit(each.brick, each.rect)
# 鋼墻
for each in map_stage.ironGroup:
screen.blit(each.iron, each.rect)
# 冰
for each in map_stage.iceGroup:
screen.blit(each.ice, each.rect)
# 河流
for each in map_stage.riverGroup:
screen.blit(each.river, each.rect)
# 樹(shù)
for each in map_stage.treeGroup:
screen.blit(each.tree, each.rect)
time += 1
if time == 5:
time = 0
is_switch_tank = not is_switch_tank
# 我方坦克
if tank_player1 in mytanksGroup:
if is_switch_tank and player1_moving:
screen.blit(tank_player1.tank_0, (tank_player1.rect.left, tank_player1.rect.top))
player1_moving = False
else:
screen.blit(tank_player1.tank_1, (tank_player1.rect.left, tank_player1.rect.top))
if tank_player1.protected:
screen.blit(tank_player1.protected_mask1, (tank_player1.rect.left, tank_player1.rect.top))
if num_player > 1:
if tank_player2 in mytanksGroup:
if is_switch_tank and player2_moving:
screen.blit(tank_player2.tank_0, (tank_player2.rect.left, tank_player2.rect.top))
player1_moving = False
else:
screen.blit(tank_player2.tank_1, (tank_player2.rect.left, tank_player2.rect.top))
if tank_player2.protected:
screen.blit(tank_player1.protected_mask1, (tank_player2.rect.left, tank_player2.rect.top))
# 敵方坦克
for each in enemytanksGroup:
# 出生特效
if each.born:
if each.times > 0:
each.times -= 1
if each.times <= 10:
screen.blit(appearances[2], (3+each.x*12*24, 3))
elif each.times <= 20:
screen.blit(appearances[1], (3+each.x*12*24, 3))
elif each.times <= 30:
screen.blit(appearances[0], (3+each.x*12*24, 3))
elif each.times <= 40:
screen.blit(appearances[2], (3+each.x*12*24, 3))
elif each.times <= 50:
screen.blit(appearances[1], (3+each.x*12*24, 3))
elif each.times <= 60:
screen.blit(appearances[0], (3+each.x*12*24, 3))
elif each.times <= 70:
screen.blit(appearances[2], (3+each.x*12*24, 3))
elif each.times <= 80:
screen.blit(appearances[1], (3+each.x*12*24, 3))
elif each.times <= 90:
screen.blit(appearances[0], (3+each.x*12*24, 3))
else:
each.born = False
else:
if is_switch_tank:
screen.blit(each.tank_0, (each.rect.left, each.rect.top))
else:
screen.blit(each.tank_1, (each.rect.left, each.rect.top))
if each.can_move:
tanksGroup.remove(each)
each.move(tanksGroup, map_stage.brickGroup, map_stage.ironGroup, myhome)
tanksGroup.add(each)
# 我方子彈
for tank_player in mytanksGroup:
if tank_player.bullet.being:
tank_player.bullet.move()
screen.blit(tank_player.bullet.bullet, tank_player.bullet.rect)
# 子彈碰撞敵方子彈
for each in enemybulletsGroup:
if each.being:
if pygame.sprite.collide_rect(tank_player.bullet, each):
tank_player.bullet.being = False
each.being = False
enemybulletsGroup.remove(each)
break
else:
enemybulletsGroup.remove(each)
# 子彈碰撞敵方坦克
for each in enemytanksGroup:
if each.being:
if pygame.sprite.collide_rect(tank_player.bullet, each):
if each.is_red == True:
myfood = food.Food()
myfood.generate()
myfoodsGroup.add(myfood)
each.is_red = False
each.blood -= 1
each.color -= 1
if each.blood < 0:
each.being = False
enemytanksGroup.remove(each)
enemytanks_now -= 1
tanksGroup.remove(each)
else:
each.reload()
tank_player.bullet.being = False
break
else:
enemytanksGroup.remove(each)
tanksGroup.remove(each)
# 子彈碰撞石頭墻
if pygame.sprite.spritecollide(tank_player.bullet, map_stage.brickGroup, True, None):
tank_player.bullet.being = False
'''
# 等價(jià)方案(更科學(xué)點(diǎn))
for each in map_stage.brickGroup:
if pygame.sprite.collide_rect(tank_player.bullet, each):
tank_player.bullet.being = False
each.being = False
map_stage.brickGroup.remove(each)
break
'''
# 子彈碰鋼墻
if tank_player.bullet.stronger:
if pygame.sprite.spritecollide(tank_player.bullet, map_stage.ironGroup, True, None):
tank_player.bullet.being = False
else:
if pygame.sprite.spritecollide(tank_player.bullet, map_stage.ironGroup, False, None):
tank_player.bullet.being = False
'''
# 等價(jià)方案(更科學(xué)點(diǎn))
for each in map_stage.ironGroup:
if pygame.sprite.collide_rect(tank_player.bullet, each):
tank_player.bullet.being = False
if tank_player.bullet.stronger:
each.being = False
map_stage.ironGroup.remove(each)
break
'''
# 子彈碰大本營(yíng)
if pygame.sprite.collide_rect(tank_player.bullet, myhome):
tank_player.bullet.being = False
myhome.set_dead()
is_gameover = True
# 敵方子彈
for each in enemytanksGroup:
if each.being:
if each.can_move and not each.bullet.being:
enemybulletsGroup.remove(each.bullet)
each.shoot()
enemybulletsGroup.add(each.bullet)
if not each.born:
if each.bullet.being:
each.bullet.move()
screen.blit(each.bullet.bullet, each.bullet.rect)
# 子彈碰撞我方坦克
for tank_player in mytanksGroup:
if pygame.sprite.collide_rect(each.bullet, tank_player):
if not tank_player.protected:
tank_player.life -= 1
if tank_player.life < 0:
mytanksGroup.remove(tank_player)
tanksGroup.remove(tank_player)
if len(mytanksGroup) < 1:
is_gameover = True
else:
tank_player.reset()
each.bullet.being = False
enemybulletsGroup.remove(each.bullet)
break
# 子彈碰撞石頭墻
if pygame.sprite.spritecollide(each.bullet, map_stage.brickGroup, True, None):
each.bullet.being = False
enemybulletsGroup.remove(each.bullet)
'''
# 等價(jià)方案(更科學(xué)點(diǎn))
for one in map_stage.brickGroup:
if pygame.sprite.collide_rect(each.bullet, one):
each.bullet.being = False
one.being = False
enemybulletsGroup.remove(one)
break
'''
# 子彈碰鋼墻
if each.bullet.stronger:
if pygame.sprite.spritecollide(each.bullet, map_stage.ironGroup, True, None):
each.bullet.being = False
else:
if pygame.sprite.spritecollide(each.bullet, map_stage.ironGroup, False, None):
each.bullet.being = False
'''
# 等價(jià)方案(更科學(xué)點(diǎn))
for one in map_stage.ironGroup:
if pygame.sprite.collide_rect(each.bullet, one):
each.bullet.being = False
if each.bullet.stronger:
one.being = False
map_stage.ironGroup.remove(one)
break
'''
# 子彈碰大本營(yíng)
if pygame.sprite.collide_rect(each.bullet, myhome):
each.bullet.being = False
myhome.set_dead()
is_gameover = True
else:
enemytanksGroup.remove(each)
tanksGroup.remove(each)
# 家
screen.blit(myhome.home, myhome.rect)
# 食物
for myfood in myfoodsGroup:
if myfood.being and myfood.time > 0:
screen.blit(myfood.food, myfood.rect)
myfood.time -= 1
for tank_player in mytanksGroup:
if pygame.sprite.collide_rect(tank_player, myfood):
# 消滅當(dāng)前所有敵人
if myfood.kind == 0:
enemytanksGroup = pygame.sprite.Group()
enemytanks_total -= enemytanks_now
enemytanks_now = 0
# 敵人靜止
if myfood.kind == 1:
for each in enemytanksGroup:
each.can_move = False
# 子彈增強(qiáng)
if myfood.kind == 2:
tank_player.bullet.stronger = True
# 使得大本營(yíng)的墻變?yōu)殇摪?/span>
if myfood.kind == 3:
map_stage.protect_home()
# 坦克獲得一段時(shí)間的保護(hù)罩
if myfood.kind == 4:
for tank_player in mytanksGroup:
tank_player.protected = True
# 坦克升級(jí)
if myfood.kind == 5:
tank_player.up_level()
# 坦克生命+1
if myfood.kind == 6:
tank_player.life += 1
myfood.being = False
myfoodsGroup.remove(myfood)
break
else:
myfood.being = False
myfoodsGroup.remove(myfood)
pygame.display.flip()
clock.tick(60)
if not is_gameover:
show_end_interface(screen, 630, 630, True)
else:
show_end_interface(screen, 630, 630, False)
4.2 制作游戲開(kāi)始和結(jié)束界面
# 開(kāi)始界面顯示
def show_start_interface(screen, width, height):
tfont = pygame.font.Font('./font/simkai.ttf', width//4)
cfont = pygame.font.Font('./font/simkai.ttf', width//20)
title = tfont.render(u'坦克大戰(zhàn)', True, (255, 0, 0))
content1 = cfont.render(u'按1鍵進(jìn)入單人游戲', True, (0, 0, 255))
content2 = cfont.render(u'按2鍵進(jìn)入雙人人游戲', True, (0, 0, 255))
trect = title.get_rect()
trect.midtop = (width/2, height/4)
crect1 = content1.get_rect()
crect1.midtop = (width/2, height/1.8)
crect2 = content2.get_rect()
crect2.midtop = (width/2, height/1.6)
screen.blit(title, trect)
screen.blit(content1, crect1)
screen.blit(content2, crect2)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_1:
return 1
if event.key == pygame.K_2:
return 2
# 結(jié)束界面顯示
def show_end_interface(screen, width, height, is_win):
bg_img = pygame.image.load("./圖片/others/background.png")
screen.blit(bg_img, (0, 0))
if is_win:
font = pygame.font.Font('./font/simkai.ttf', width//10)
content = font.render(u'恭喜通關(guān)!', True, (255, 0, 0))
rect = content.get_rect()
rect.midtop = (width/2, height/2)
screen.blit(content, rect)
else:
fail_img = pygame.image.load("./圖片/others/gameover.png")
rect = fail_img.get_rect()
rect.midtop = (width/2, height/2)
screen.blit(fail_img, rect)
pygame.display.update()
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
# 關(guān)卡切換
def show_switch_stage(screen, width, height, stage):
bg_img = pygame.image.load("./圖片/others/background.png")
screen.blit(bg_img, (0, 0))
font = pygame.font.Font('./font/simkai.ttf', width//10)
content = font.render(u'第%d關(guān)' % stage, True, (0, 255, 0))
rect = content.get_rect()
rect.midtop = (width/2, height/2)
screen.blit(content, rect)
pygame.display.update()
delay_event = pygame.constants.USEREVENT
pygame.time.set_timer(delay_event, 1000)
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == delay_event:
return
5 最后
項(xiàng)目獲?。?/strong>https://gitee.com/sinonfin/system-sharing文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-780435.html
到了這里,關(guān)于python畢設(shè)分享 python坦克大戰(zhàn)小游戲的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!