1. 首页
  2. 编程语言
  3. Python
  4. 飞碟大战(就是把飞机大战改了一下)

飞碟大战(就是把飞机大战改了一下)

上传者: 2021-05-21 05:39:10上传 .ZIP文件 5.92 MB 热度 9次

from pygame.locals import *pygame.init()#pygame模块初始化#1.创建窗口screen=pygame.display.set_mode((480,852))#2.贴背景bg=pygame.image.load("background.png")#加载图片#贴灰鸡j=pygame.image.load("hero1.png")jj=pygame.image.load("hero0.png")hero_down=pygame.image.load("hero_down.png")#贴敌机enemy1=pygame.image.load("enemy1.png")enemy1_x=[]#创建敌人1的地点enemy1_y=[]

enemy1_down1=pygame.image.load("enemy1_down1.png")enemy1_down2=pygame.image.load("enemy1_down2.png")enemy1_down3=pygame.image.load("enemy1_down3.png")enemy1_blood=[]

enemy3=pygame.image.load("enemy3.png")enemy3_x=[]#创建敌人1的地点enemy3_y=[]

enemy3_down1=pygame.image.load("enemy1_down1.png")enemy3_down2=pygame.image.load("enemy1_down2.png")enemy3_down3=pygame.image.load("enemy1_down3.png")enemy3_blood=[]

enemy2=pygame.image.load("enemy2.png")enemy2_x=[]#创建敌人1的地点enemy2_y=[]

enemy2_down1=pygame.image.load("enemy2_down1.png")enemy2_down2=pygame.image.load("enemy2_down2.png")enemy2_down3=pygame.image.load("enemy2_down3.png")enemy2_blood=[]

#子弹bullet=pygame.image.load("bullet.png")bullet_x=[]bullet_y=[]#AWSLgameover=pygame.image.load("gameover.png")gameover=pygame.transform.scale(gameover,(480,852))start=0

#计数器number=0

font=pygame.font.Font("simsun.ttc",40)text=font.render("XD:",False,(0,0,0))score=0

while True: if start==0: mouse_x,mouse_y=pygame.mouse.get_pos()#获取当前鼠标坐标 #获取战鸡宽高 hero_x=mouse_x-(j.get_width()/2)#宽x hero_y=mouse_y-(j.get_height()/2)#高Y screen.blit(bg,(0,0)) screen.blit(text,(0,0)) text_score=font.render(str(score),False,(0,0,0)) screen.blit(text_score,(100,0)) #贴英雄鸡1 if number%2==0:#如果取余数=0贴hero0 screen.blit(jj,(hero_x,hero_y)) else:#如取余=1,贴hero1 screen.blit(j,(hero_x,hero_y)) #-------------------------------------------------------------------- if number%5==0:#¥¥¥可以改 #添加x坐标 enemy1_x.append(random.randint(0,480)) #添加y坐标 enemy1_y.append(0) #敌鸡2滴血 enemy1_blood.append(2) #贴 for i in range(len(enemy1_x)): screen.blit(enemy1,(enemy1_x[i],enemy1_y[i])) enemy1_y[i]=enemy1_y[i] 4#屎小敌鸡降落 :D for i in range(len(enemy1_x)): if enemy1_y[i]>852:#如小敌机y>852,那么让敌机重回0 del enemy1_x[i] del enemy1_y[i] break#跳跳跳跳跳跳出循环

#----------------------------------------------- if number%500==0:#¥¥¥可以改 enemy3_x.append(random.randint(0,480)) #添加y坐标 enemy3_y.append(0) enemy3_blood.append(1) for i in range(len(enemy3_x)): screen.blit(enemy3,(enemy3_x[i],enemy3_y[i])) enemy3_y[i]=enemy3_y[i] 2#屎大敌鸡降落 :D for i in range(len(enemy3_x)): if enemy3_y[i]>852:#如小敌机y>852,那么让敌机重回0 del enemy3_x[i] del enemy3_y[i] break#跳跳跳跳跳跳出循环 #----------------------------------------------------------- if number%200==0:#¥¥¥可以改 enemy2_x.append(random.randint(0,480)) #添加y坐标 enemy2_y.append(0) enemy2_blood.append(3) for i in range(len(enemy2_x)): screen.blit(enemy2,(enemy2_x[i],enemy2_y[i])) enemy2_y[i]=enemy2_y[i] 2#屎大敌鸡降落 :D for i in range(len(enemy2_x)): if enemy2_y[i]>852:#如小敌机y>852,那么让敌机重回0 del enemy2_x[i] del enemy2_y[i] break#跳跳跳跳跳跳出循环

#--------------------------------------------------------------

#子弹 if number%5==0:#可以改 bullet_x.append(hero_x jj.get_width()/2-bullet.get_width()/2) bullet_y.append(hero_y-jj.get_height()/100) for i in range(len(bullet_x)): screen.blit(bullet,(bullet_x[i],bullet_y[i])) bullet_y[i]=bullet_y[i]-10#可改 for i in range(len(bullet_x)): if bullet_y[i]<0: del bullet_x[i] del bullet_y[i] break

#---------------------------小敌机嗝屁------------------------------- for i in range(len(bullet_x)):#子弹列表 for k in range(len(enemy1_x)):################################################################3 #小鸡列表范围内 #如果子弹的x坐标在对面x的范围内 if bullet_x[i]>enemy1_x[k]-bullet.get_width() and bullet_x[i]enemy1_y[k]-bullet.get_height() and bullet_y[i]

#------------------------------------------------------------------- for i in range(len(bullet_x)):#子弹列表 for k in range(len(enemy3_x)):################################################################3 #小鸡列表范围内 #如果子弹的x坐标在对面x的范围内 if bullet_x[i]>enemy3_x[k]-bullet.get_width() and bullet_x[i]enemy3_y[k]-bullet.get_height() and bullet_y[i]

#---------------------------------------------------------------------------------------- for i in range(len(bullet_x)):#子弹列表 for k in range(len(enemy2_x)):################################################################3 #小鸡列表范围内 #如果子弹的x坐标在对面x的范围内 if bullet_x[i]>enemy2_x[k]-bullet.get_width() and bullet_x[i]enemy2_y[k]-bullet.get_height() and bullet_y[i]

#-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- for i in range(len(enemy1_x)): if enemy1_x[i]>hero_x-enemy1.get_width() and enemy1_x[i]hero_y-enemy1.get_height() and enemy1_y[i]hero_x-enemy1.get_width() and enemy2_x[i]hero_y-enemy1.get_height() and enemy2_y[i]hero_x-enemy3.get_width() and enemy3_x[i]hero_y-enemy3.get_height() and enemy3_y[i]

用户评论