mainvoid #音效存放picture #图片存放need #各种计算相关的函数play.py #运行db.db #数据库loadding.py #对图片进行加载
下面为主逻辑部分
def MainGame(info):#主游戏模块global distance,bird_x,bird_y,mask,tempname , level , default , color = inforeal_bg=random.choice(bg)level=dict_[level]mask ={}upper_img=pipe['green'][0]# 获得图像lower_img = pygame.transform.rotate(upper_img , 180)#翻转图像#管道距离mask['bird'] = (getHitmask(bird_c[color]))mask['pipe'] = (getHitmask(pipe['green'][0]) ,getHitmask(pipe['green'][1]) ,)mask['box']=(getHitmask(box))score=57#分数distance = distance_-level*20 #每个的距离bet=200-10*levelcount=distance #为了pipe距离一致进行的计算bird_x = 57 #鸟的初始坐标bird_y=190if default=='简单':far=easy #设置画面速度elif default=='一般':far=commontelse:far=difficultrotate=60 #角度v=0 #加速度g_v=0.5 #设置画面加速度g_v_=2 #起始下落速度cc=bird_c[color]#鸟的颜色box_x=[]box_y=[]x=[]far_=faru_y=[]l_y=[]v_=0counter=0while True:screen.blit(real_bg , (0 , 0))for event in pygame.event.get():if event.type==QUIT:pygame.display.quit()elif event.type==KEYDOWN and (event.key==K_SPACE or event.key==K_UP):m['wing'].play()v=8v_=rotateg_v_=2if v>0:cc=pygame.transform.rotate(bird_c[color],v_/2)bird_y-=vv_-=8v-=1else:v_-=1cc=pygame.transform.rotate(bird_c[color],v_)g_v_+=g_vbird_y+=(g_v_)#上面是飞行机制if count>=distance:count=0x.append(388)u_yy,l_yy=get_pipe(bet)u_y.append(u_yy)l_y.append(l_yy)#下面定义道具出现在俩个管道之间b_count = random.randint(1 , 10)if b_count < 10 * box_pro:box_x.append(random.randint(440 , 440 + distance-70))box_y.append(random.randint(100 , 300))#贴上管道if counter>0:if big:cc=pygame.transform.scale2x(cc) #处于大状态if fast:passif small:cc=pygame.transform.scale(cc, (17, 12))else:far=far_fast=Falsebig=Falsefor x_,u_y_,l_y_ in zip(x,u_y,l_y):if x_<-100:del x[0],u_y[0],l_y[0]screen.blit(upper_img,(x_,u_y_))screen.blit(lower_img,(x_,l_y_))for i in range(len(x)):x[i]-=far#贴上道具box_crash =check_crash(cc,box_x,box_y,img=box)if box_crash[0][0]:for b_x,b_y in zip(box_x,box_y):if b_x>55 and b_x<130:del box_x[box_x.index(box_crash[1])],box_y[box_y.index(box_crash[2])]far=far_big=Falsesmall=Falsetmp=random.randint(1,3)if tmp==1:big=Trueelif tmp==2:fast=Truefar_=farfar-=slowedelse:small=Truecounter=box_timecount+=farfor b_x,b_y in zip(box_x,box_y):if b_x<-100:del box_x[0],box_y[0]screen.blit(box,(b_x,b_y))for i in range(len(box_x)):box_x[i]-=farscore+=farrel_score=int((score-438+distance)/(distance))if rel_score<=0:rel_score=0;rel_score_=0if rel_score>rel_score_:m['point'].play()rel_score_=rel_scoreindex=0for i in str(rel_score):screen.blit(score_group[i],(200+index*30,10))index+=1counter-=4crash_test=check_crash(cc,x,u_y,l_y)if crash_test[0][0] and big==False:m['die'].play()return cc,bird_x,bird_y,name , level , default,rel_score_ #返回鸟的坐标if crash_test[0][0] and big==True:del u_y[u_y.index(crash_test[1])],l_y[l_y.index(crash_test[2])],x[x.index(crash_test[3])]rel_score+=distanceif cc.get_height()+bird_y>=410 or bird_y<=0:m['die'].play()return cc,bird_x,bird_y,name , level , default,rel_score_screen.blit(cc,(bird_x,bird_y))temp = -((-temp + 4) % 48)screen.blit(move , (temp , base))clock.tick(30)pygame.display.update()