游戏创作——爱猫大作战乀
生活随笔
收集整理的這篇文章主要介紹了
游戏创作——爱猫大作战乀
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
今天,我玩到一款全新的小游戲——愛貓大作戰💘,突然就有了創作靈感,根據自己豐富的想象 力創作了這款游戲——愛貓大作戰乀💘,不多說,直接把我的辛勤成果展示給大家!
在創作之前,請各位大佬們準備好以下工具:
1、python編輯器(版本要在3.20.21以上,否則無法運行)
2、下載文章結尾免費的資源圖片包,否則無法運行,注意,是免費的哦!
下面我就把代碼展示出來:
import random,pygame,sys,time from random import* import webbrowser pygame.init() screen = pygame.display.set_mode((600, 636)) pygame.display.set_caption("拯救貓咪大作戰") loading=pygame.image.load("loading.png") lose=pygame.image.load("lose.png") startimg=pygame.image.load("start.png")bg=pygame.mixer.music.load("bg.mp3") sound=pygame.mixer.Sound("point.wav") sound.set_volume(0.5) sound1=pygame.mixer.Sound("success.wav") sound1.set_volume(0.5) sound2=pygame.mixer.Sound("lose.wav") sound2.set_volume(0.5) pygame.mixer.music.set_volume(0.2) pygame.mixer.music.play(-1) def sum_d(a,num):sum=0for i in a:sum=sum+i.count(num)return sumdef updat(level): global t1,data1,datanum=randint(level,2+level)data1=[[randint(1,5) for i in range(6)] for i in range(6)] for i in range(num):data1[randint(0,5)][randint(0,5)]=6data=[[0 for i in range(6)] for i in range(6)]t1=time.time()def bli(a):for i in range(6):for j in range(6):for m in range(7):if a[i][j]==m:img=pygame.image.load(str(m)+".png")myRect=pygame.Rect(j*100,i*100,100,100) screen.blit(img,myRect) rectName=pygame.Rect(-150,-150,100,100) font=pygame.font.SysFont("",40)lv=1 victor=True nex=False n=0 all=0 one=Truestart=Truewhile True:screen.fill((255, 255, 255))for event in pygame.event.get():if event.type == pygame.QUIT:pygame.quit()import osos.system('index.html')sys.exit()elif event.type==pygame.MOUSEBUTTONDOWN :if start:updat(lv)start=Falseif time.time()-t1>=4 and victor:point=data[event.pos[1]//100][event.pos[0]//100]index_1=event.pos[1]//100index_2=event.pos[0]//100new=[point,index_1,index_2]data[new[1]][new[2]]=data1[new[1]][new[2]]img_li=data1[new[1]][new[2]]sound.play()if img_li!=6:rectName=pygame.Rect(index_2*100,index_1*100,100,100)victor=Falset1=time.time()if sum_d(data,6)==sum_d(data1,6):all=sum_d(data1,6)+alllv+=1if lv>30:lv=ranint(15,20)n+=1sound1.play()updat(lv)pygame.draw.rect(screen,(255,0,0),rectName,1)try: if time.time()-t1<=1 and victor==True:screen.blit(loading,(0,0))elif time.time()-t1>=4: bli(data)else: bli(data1)except:screen.blit(startimg,(0,0))if victor==False and time.time()-t1>=1:screen.blit(lose,(0,0))if victor==False and one and time.time()-t1>=1:pygame.mixer.music.stop()sound2.play()one=Falsetry: if victor and time.time()-t1>=1:font2=font.render("Now:"+str(sum_d(data1,6)-sum_d(data,6)),1,(242,3,36))screen.blit(font2,(8,608)) elif time.time()-t1>=1:font2=font.render("The cats you saved:"+str(all),1,(242,3,36))screen.blit(font2,(8,608)) if time.time()-t1>=1: font1=font.render("level:"+str(n),1,(242,3,36))if victor:font3=font.render("Cats:"+str(all),1,(242,3,36))screen.blit(font3,((screen.get_width()-font1.get_width())/2,608))screen.blit(font1,(screen.get_width()-font1.get_width()-8,608))except:screen.blit(startimg,(0,0)) pygame.display.update()最后就是大家需要的圖片啦(很多博客只會上主代碼,不上素材。但我不是這樣的人,我想讓大家真正地學習,所以,話不多說,上素材!點個小紅心吧!)
素材網址:python拯救貓咪創作-其他文檔類資源-CSDN下載
總結
以上是生活随笔為你收集整理的游戏创作——爱猫大作战乀的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MATLAB 二值图像中的白色变为彩色
- 下一篇: 计算机应用能力 实施办法,《计算机应用基