基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼_第1頁(yè)
基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼_第2頁(yè)
基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼_第3頁(yè)
基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼_第4頁(yè)
基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼_第5頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

第基于Python實(shí)現(xiàn)開(kāi)心消消樂(lè)小游戲的示例代碼__screen_size=(900,600)

screen=pygame.display.set_mode(__screen_size,DOUBLEBUF,32)

fruit_list=[]

fruit_image=pygame.image.load(Tree.fruit).convert_alpha()

fruit_width=fruit_image.get_width()

fruit_height=fruit_image.get_height()

type=0#0樹(shù)界面,1加精力界面

energy_full=False#精力已滿(mǎn)標(biāo)志初始未滿(mǎn)

money_empty=False#銀幣不足

defload_text(self,text,position,txt_size=25,txt_color=(255,255,255)):

my_font=pygame.font.SysFont(None,txt_size)

text_screen=my_font.render(text,True,txt_color)

self.screen.blit(text_screen,position)

defdraw_tree(self,energy_num,money_num):

"""畫(huà)tree"""

Tree(Tree.tree,(0,600)).draw(self.screen)#畫(huà)樹(shù)

Tree(Tree.energy_num,Tree.energy_num_position).draw(self.screen)#畫(huà)精力

#print("energy",energy_num)

ifenergy_num30:

self.load_text(str(30)+'/30',(22,55),21)

else:

self.load_text(str(energy_num)+'/30',(22,55),21)

#print("money",money_num)

Tree(Tree.money,(15,135)).draw(self.screen)#畫(huà)銀幣

self.load_text(str(money_num),(32,124),21)

foriinrange(0,10):#畫(huà)果子

Tree(Tree.fruit,Tree.position[i]).draw(self.screen)

self.load_text(str(i+1),(Tree.position[i][0]+15,Tree.position[i][1]-47))

ifself.type==1:

Tree(Tree.energy_buy,Tree.energy_buy_position).draw(self.screen)

ifself.energy_full:

self.load_text("energyisfull!",(430,310),30,(255,0,0))

pygame.display.flip()

pygame.time.delay(500)

self.energy_full=False

ifself.money_empty:

self.load_text("moneyisnotenough!",(410,310),30,(255,0,0))

pygame.display.flip()

pygame.time.delay(500)

self.money_empty=False

2.4制作鼠標(biāo)點(diǎn)擊效果

defmouse_select(self,button,level,energy_num,money_num):

"""鼠標(biāo)點(diǎn)擊"""

ifbutton.type==MOUSEBUTTONDOWN:

mouse_down_x,mouse_down_y=button.pos

print(button.pos)

iflevel==0:

ifself.type==0:#樹(shù)界面

foriinrange(0,10):

ifTree.position[i][0]mouse_down_xTree.position[i][0]+self.fruit_width\

andTree.position[i][1]-self.fruit_heightmouse_down_yTree.position[i][1]:

ifenergy_num=0:

self.type=1

else:

level=i+1

ifTree.energy_num_position[0]mouse_down_xTree.energy_num_position[0]+60\

andTree.energy_num_position[1]-60mouse_down_yTree.energy_num_position[1]:#精力60*60

SoundPlay(SoundPlay.click)

self.type=1

else:#加精力彈窗界面

if408mouse_down_x600and263mouse_down_y313:#點(diǎn)加精力按鈕

SoundPlay(SoundPlay.click_button)

ifmoney_num50:

self.money_empty=True

ifenergy_num=30:

self.energy_full=True

elifenergy_num30andmoney_num=50:

energy_num+=5

money_num-=50

elif619mouse_down_x638and158mouse_down_y177:#點(diǎn)叉號(hào)

self.type=0

ifbutton.type==MOUSEBUTTONUP:

pass

returnlevel,energy_num,money_num

2.5制作出現(xiàn)元素

classElement(pygame.sprite.Sprite):

"""元素類(lèi)"""

#圖標(biāo)元組,包括6個(gè)小動(dòng)物,

animal=('pic2/fox.png','pic2/bear.png','pic2/chick.png','pic2/eagle.png','pic2/frog.png','pic2/cow.png')

ice='pic2/ice.png'#冰層

brick='pic2/brick.png'#磚

frame='pic2/frame.png'#選中框

bling=("pic2/bling1.png","pic2/bling2.png","pic2/bling3.png","pic2/bling4.png","pic2/bling5.png",\

"pic2/bling6.png","pic2/bling7.png","pic2/bling8.png","pic2/bling9.png")#消除動(dòng)畫(huà)

ice_eli=('pic2/ice0.png','pic2/ice1.png','pic2/ice2.png','pic2/ice3.png','pic2/ice4.png','pic2/ice5.png',\

'pic2/ice6.png','pic2/ice7.png','pic2/ice8.png')#消除冰塊動(dòng)畫(huà)

#得分圖片

score_level=('pic2/good.png','pic2/great.png','pic2/amazing.png','pic2/excellent.png','pic2/unbelievable.png')

none_animal='pic2/noneanimal.png'#無(wú)可消除小動(dòng)物

stop='pic2/exit.png'#暫停鍵

stop_position=(20,530)

def__init__(self,icon,position):

super().__init__()

self.image=pygame.image.load(icon).convert_alpha()

self.rect=self.image.get_rect()

self.rect.topleft=position#左上角坐標(biāo)

self.speed=[0,0]

self.init_position=position

defmove(self,speed):

self.speed=speed

self.rect=self.rect.move(self.speed)

ifself.speed[0]!=0:#如果左右移動(dòng)

ifabs(self.rect.left-self.init_position[0])==self.rect[2]:

self.init_position=self.rect.topleft

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論