|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
看完90讲后借用小甲鱼老师的素材先试着写了一下,待完善……import pygame as py
import random
from threading import Thread
#小飞机类
class Small_plane(py.sprite.Sprite):
def __init__(self,name,down1,down2,down3,down4,speed):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self._down1 = py.image.load(down1).convert_alpha()
self._down2 = py.image.load(down2).convert_alpha()
self._down3 = py.image.load(down3).convert_alpha()
self._down4 = py.image.load(down4).convert_alpha()
self._speed = speed
self.rect = self._image.get_rect()
self.rect.left,self.rect.top = random.randint(0,423),-43
self._collide = False
def move(self):
self.rect = self.rect.move(self._speed)
#中飞机类
class Middle_plane(py.sprite.Sprite):
def __init__(self,name,name1,down1,down2,down3,down4,speed):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self._image1 = py.image.load(name1).convert_alpha()
self._down1 = py.image.load(down1).convert_alpha()
self._down2 = py.image.load(down2).convert_alpha()
self._down3 = py.image.load(down3).convert_alpha()
self._down4 = py.image.load(down4).convert_alpha()
self._speed = speed
self.rect = self._image.get_rect()
self.rect.left,self.rect.bottom = random.randint(0,411),0
self._collide = False
self._hit = 0
def move(self):
self.rect = self.rect.move(self._speed)
def blood(self,screen):
width = 11.5 * (6 - self._hit)
if self._hit == 0:
py.draw.rect(screen,(0,255,0),(self.rect.left,self.rect.top - 5,width,5),0)
elif self._hit == 6:
py.draw.rect(screen,(255,0,0),(self.rect.left,self.rect.top - 5,width,5),0)
else:
py.draw.rect(screen,(0,255,0),(self.rect.left,self.rect.top - 5,width,5),0)
py.draw.rect(screen,(255,0,0),(self.rect.left + width,self.rect.top - 5,69 - width,5),0)
pass
#大飞机类
class Large_plane(py.sprite.Sprite):
def __init__(self,name,name1,name2,down1,down2,down3,down4,down5,down6,speed):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self._image1 = py.image.load(name1).convert_alpha()
self._image2 = py.image.load(name2).convert_alpha()
self._down1 = py.image.load(down1).convert_alpha()
self._down2 = py.image.load(down2).convert_alpha()
self._down3 = py.image.load(down3).convert_alpha()
self._down4 = py.image.load(down4).convert_alpha()
self._down5 = py.image.load(down5).convert_alpha()
self._down6 = py.image.load(down6).convert_alpha()
self._speed = speed
self.rect = self._image.get_rect()
self.rect.left,self.rect.bottom = random.randint(0,315),0
self._collide = False
self._hit = 0
def move(self):
self.rect = self.rect.move(self._speed)
def blood(self,screen):
width = 16.5 * (10 - self._hit)
if self._hit == 0:
py.draw.rect(screen,(0,255,0),(self.rect.left,self.rect.top - 5,width,5),0)
elif self._hit == 10:
py.draw.rect(screen,(255,0,0),(self.rect.left,self.rect.top - 5,width,5),0)
else:
py.draw.rect(screen,(0,255,0),(self.rect.left,self.rect.top - 5,width,5),0)
py.draw.rect(screen,(255,0,0),(self.rect.left + width,self.rect.top - 5,165 - width,5),0)
pass
#自己飞机类
class My_plane(py.sprite.Sprite):
def __init__(self,name,name1,destroy1,destroy2,destroy3,destroy4,size):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self._image1 = py.image.load(name1).convert_alpha()
self._destroy1 = py.image.load(destroy1).convert_alpha()
self._destroy2 = py.image.load(destroy2).convert_alpha()
self._destroy3 = py.image.load(destroy3).convert_alpha()
self._destroy4 = py.image.load(destroy4).convert_alpha()
self.rect = self._image.get_rect()
self._size = size
self.rect.left,self.rect.bottom = (self._size[0] - self.rect.width) / 2,self._size[1] - 57
self._collide = False
self._live = True
self._protect = True
self._pause = True
def move(self,speed):
self.rect = self.rect.move(speed)
#边界处理
if self.rect.left <= 0:
self.rect.left = 0
if self.rect.right >= self._size[0]:
self.rect.right = self._size[0]
if self.rect.top <= 0:
self.rect.top = 0
if self.rect.bottom >= self._size[1] - 57:
self.rect.bottom = self._size[1] - 57
pass
#子弹类
class Bullet(py.sprite.Sprite):
def __init__(self,name,other):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self.rect = self._image.get_rect()
self.rect.left,self.rect.top = other.rect.left + (other.rect.width - self.rect.width) / 2 + 1,\
other.rect.top - self.rect.height + 50
def move(self):
self.rect = self.rect.move([0,-50])
def existence(self):
if self.rect.top > 0:
return True
else:
return False
class Supply(py.sprite.Sprite):
def __init__(self,name):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self.rect = self._image.get_rect()
self.rect.left,self.rect.bottom = random.randint(0,(480 - self.rect.width)),0
def move(self):
self.rect = self.rect.move([0,2])
def out(self):
if self.rect.top >= 700:
return False
else:
return True
class Bullet_dubble1(py.sprite.Sprite):
def __init__(self,name,other):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self.rect = self._image.get_rect()
self.rect.left,self.rect.top = other.rect.left + 20 ,\
other.rect.top - self.rect.height + 50
def move(self):
self.rect = self.rect.move([0,-50])
def existence(self):
if self.rect.top > 0:
return True
else:
return False
class Bullet_dubble2(py.sprite.Sprite):
def __init__(self,name,other):
super().__init__()
self._image = py.image.load(name).convert_alpha()
self.rect = self._image.get_rect()
self.rect.left,self.rect.top = other.rect.left + 77 ,\
other.rect.top - self.rect.height + 50
def move(self):
self.rect = self.rect.move([0,-50])
def existence(self):
if self.rect.top > 0:
return True
else:
return False
import pygame as py
import sys
import random
import traceback
from class_def import Small_plane,Middle_plane,Large_plane,My_plane,Bullet,Supply,Bullet_dubble1,Bullet_dubble2
def plane_list_init(*args):
list1 = list(args)
list1[0].empty()
list1[1].empty()
list1[2].empty()
list1[3].empty()
list1[4].clear()
list1[5].clear()
list1[6].clear()
list1[7].clear()
list1[8].clear()
#初始化,窗口大小
def main():
py.init()
py.mixer.init()
#游戏音频导入
bg_music_name = 'sound\\game_music.ogg'
bullet_name = 'sound\\bullet.wav'
supply_name = 'sound\\supply.wav'
supply_bomb = 'sound\\get_bomb.wav'
supply_bullet = 'sound\\get_bullet.wav'
myplane_collide_name = 'sound\\me_down.wav'
bomb_name = 'sound\\use_bomb.wav'
middle_down_name = 'sound\\enemy2_down.wav'
large_down_name = 'sound\\enemy3_down.wav'
large_move_name = 'sound\\enemy3_flying.wav'
py.mixer.music.load(bg_music_name)
py.mixer.music.set_volume(0.1)
py.mixer.music.play()
bullet_sound = py.mixer.Sound(bullet_name)
bullet_sound.set_volume(0.3)
supply_sound = py.mixer.Sound(supply_name)
supply_sound.set_volume(0.2)
supply_bomb_sound = py.mixer.Sound(supply_bomb)
supply_bomb_sound.set_volume(0.2)
supply_bullet_sound = py.mixer.Sound(supply_bullet)
supply_bullet_sound.set_volume(0.2)
myplane_collide_sound = py.mixer.Sound(myplane_collide_name)
myplane_collide_sound.set_volume(0.2)
bomb_sound = py.mixer.Sound(bomb_name)
bomb_sound.set_volume(0.2)
middle_down_sound = py.mixer.Sound(middle_down_name)
middle_down_sound.set_volume(0.2)
large_down_sound = py.mixer.Sound(large_down_name)
large_down_sound.set_volume(0.2)
large_move_sound = py.mixer.Sound(large_move_name)
large_move_sound.set_volume(0.1)
#游戏所需图片导入
bg_image_name = 'images\\background.png'
bomb_name = 'images\\bomb.png'
life_name = 'images\\life.png'
small_plane_name_1 = 'images\\enemy1.png'
small_plane_name_2 = 'images\\enemy1_down1.png'
small_plane_name_3 = 'images\\enemy1_down2.png'
small_plane_name_4 = 'images\\enemy1_down3.png'
small_plane_name_5 = 'images\\enemy1_down4.png'
middle_plane_name_1 = 'images\\enemy2.png'
middle_plane_name_2 = 'images\\enemy2_hit.png'
middle_plane_name_3 = 'images\\enemy2_down1.png'
middle_plane_name_4 = 'images\\enemy2_down2.png'
middle_plane_name_5 = 'images\\enemy2_down3.png'
middle_plane_name_6 = 'images\\enemy2_down4.png'
large_plane_name_1 = 'images\\enemy3_n1.png'
large_plane_name_2 = 'images\\enemy3_n2.png'
large_plane_name_3 = 'images\\enemy3_hit.png'
large_plane_name_4 = 'images\\enemy3_down1.png'
large_plane_name_5 = 'images\\enemy3_down2.png'
large_plane_name_6 = 'images\\enemy3_down3.png'
large_plane_name_7 = 'images\\enemy3_down4.png'
large_plane_name_8 = 'images\\enemy3_down5.png'
large_plane_name_9 = 'images\\enemy3_down6.png'
my_plane_name_1 = 'images\\me1.png'
my_plane_name_2 = 'images\\me2.png'
my_plane_name_3 = 'images\\me_destroy_1.png'
my_plane_name_4 = 'images\\me_destroy_2.png'
my_plane_name_5 = 'images\\me_destroy_3.png'
my_plane_name_6 = 'images\\me_destroy_4.png'
bullet_name_1 = 'images\\bullet1.png'
bullet_name_2 = 'images\\bullet2.png'
supply_name_1 = 'images\\bomb_supply.png'
supply_name_2 = 'images\\bullet_supply.png'
again_name = 'images\\again.png'
gameover_name = 'images\\gameover.png'
pause_name_1 = 'images\\pause_nor.png'
pause_name_2 = 'images\\pause_pressed.png'
resume_name_1 = 'images\\resume_nor.png'
resume_name_2 = 'images\\resume_pressed.png'
size = width,height = 480,700
screen = py.display.set_mode(size)
py.display.set_caption('Aircraft Wars')
bg_image = py.image.load(bg_image_name).convert_alpha()
bomb_image = py.image.load(bomb_name).convert_alpha()
life_image = py.image.load(life_name).convert_alpha()
again_image = py.image.load(again_name).convert_alpha()
again_image_rect = again_image.get_rect()
again_image_rect.left,again_image_rect.top = 90,300
gameover_image = py.image.load(gameover_name).convert_alpha()
gameover_image_rect = gameover_image.get_rect()
gameover_image_rect.left,gameover_image_rect.top = 90,400
#文字设置
font1 = py.font.SysFont('行书',40)
font1.set_bold(True)
font2 = py.font.SysFont('行书',60)
scorestext1 = 0000
num1text1 = 1
#实例化飞机
myplane = My_plane(my_plane_name_1,my_plane_name_2,my_plane_name_3,my_plane_name_4,my_plane_name_5,my_plane_name_6,size)
#存储敌方飞机
allplanes_group = py.sprite.Group()
smallplane_list = []
smallplane_destroylist = []
smallplane_group = py.sprite.Group()
middleplane_list = []
middleplane_destroylist = []
middleplane_hitlist = []
middleplane_group = py.sprite.Group()
largeplane_list = []
largeplane_destroylist = []
largeplane_hitlist = []
largeplane_group = py.sprite.Group()
#存储己方飞机发射的子弹
bullet_list = []
bullet_group = py.sprite.Group()
#存储补给
supply_group = py.sprite.Group()
#设置按键不断响应
#py.key.set_repeat(1,10)
Music_bg = py.USEREVENT
GameSupply = py.USEREVENT + 1
py.mixer.music.set_endevent(Music_bg)
flag_left,flag_right,flag_up,flag_down,flag_space = 0,0,0,0,0
#子弹的移动生成标志,己方飞机的显示标志,敌方飞机被击落标志
flag_bullet = 0
#敌方飞机的生成和移动标志
flag_enemyplane = 0
#己方飞机被击落标志
flag_destroyplane = 1
#毁灭动画显示控制标志
i,j,m,n = 0,0,0,0
#敌方中大飞机出现标志
start,start1,start2 =0,0,0
#补给标志
supply_bomb,supply_bullet,supply_get,supply_bullet_time,supply_time= 0,0,0,0,0
#生命条
life_num = 3
life_list = [(434,643) ,(388,643) ,(342,643)]
speed_list = [(0,1),(0,1.5),(0,2),(0,2.5),(0,3)]
smallcreate_list = [70,60,50,40,30,20]
middlecreate_list = [random.randint(2500,3000),random.randint(2000,2500),random.randint(1500,2000),random.randint(1000,1500),1000]
largecreate_list = [random.randint(4500,5000),random.randint(4000,4500),random.randint(3000,4000),random.randint(2500,3000),2000]
speed_index = 0
protect_time = 0 #保护时间
flag_pause,flag_resume= 1,0 #暂停切换标志
clock = py.time.Clock()
while True:
for event in py.event.get():
if event.type == py.QUIT:
py.quit()
sys.exit()
if event.type == py.MOUSEBUTTONDOWN:
if event.button == 1:
pos = event.pos
#重新开始,设置重启
if 90<= pos[0] <= 390 and 300 <= pos[1] <= 341:
myplane._live = True
myplane._collide = False
myplane.rect.left,myplane.rect.bottom = (myplane._size[0] - myplane.rect.width) / 2,myplane._size[1] - 57
life_num = 3
start,start1,start2 =0,0,0
flag_enemyplane,flag_bullet= 0,0
flag_destroyplane = 1
num1text1 = 1
scorestext1 = 0000
if 90<= pos[0] <= 390 and 400 <= pos[1] <= 440:
py.quit()
sys.exit()
#暂停
if 420<= pos[0] <= 480 and 0 <= pos[1] <= 45 and flag_pause:
py.mixer.music.pause()
flag_resume = 1
myplane._pause = False
if 420<= pos[0] <= 480 and 0 <= pos[1] <= 45 and not flag_pause:
flag_resume = 0
py.mixer.music.unpause()
flag_pause = 1
myplane._pause = True
#己方飞机操作设置
if event.type == py.KEYDOWN:
if event.key == py.K_a or event.key == py.K_LEFT:
flag_left = 1
if event.key == py.K_d or event.key == py.K_RIGHT:
flag_right = 1
if event.key == py.K_w or event.key == py.K_UP:
flag_up = 1
if event.key == py.K_s or event.key == py.K_DOWN:
flag_down = 1
if event.key == py.K_SPACE:
flag_space = 1
if event.type == py.KEYUP:
if event.key == py.K_a or event.key == py.K_LEFT:
flag_left = 0
if event.key == py.K_d or event.key == py.K_RIGHT:
flag_right = 0
if event.key == py.K_w or event.key == py.K_UP:
flag_up = 0
if event.key == py.K_s or event.key == py.K_DOWN:
flag_down = 0
if event.type == Music_bg:
py.mixer.music.play()
if myplane._live and myplane._pause:
#敌方小飞机生成与移动
#随着分数增加难度上升
if scorestext1 < 40000:
speed_index = 0
elif scorestext1 < 100000:
speed_index = 1
elif scorestext1 < 250000:
speed_index = 2
elif scorestext1 < 450000:
speed_index = 3
else:
speed_index = 4
flag_enemyplane += 1
if smallplane_group:
for each in smallplane_group:
each.move()
if middleplane_group:
for each in middleplane_group:
each.move()
if largeplane_group:
for each in largeplane_group:
large_move_sound.play()
each.move()
if flag_enemyplane == smallcreate_list[speed_index]:
flag_enemyplane = 0
small_plane = Small_plane(small_plane_name_1,small_plane_name_2,small_plane_name_3,small_plane_name_4,small_plane_name_5,speed_list[speed_index])
while py.sprite.spritecollide(small_plane,allplanes_group,False):
small_plane.rect.left,small_plane.rect.bottom =random.randint(0,423),0
smallplane_list.append(small_plane)
smallplane_group.add(small_plane)
allplanes_group.add(small_plane)
start += 1
if start == 300:
start1 = 1
if start > 300:
if start == create_time1:
start1 = 1
if start == 1200:
start2 = 1
if start > 1200:
if start == create_time2:
start2 = 1
if start1:
middle_plane = Middle_plane(middle_plane_name_1,middle_plane_name_2,middle_plane_name_3,middle_plane_name_4,middle_plane_name_5,middle_plane_name_6,speed_list[speed_index])
while py.sprite.spritecollide(middle_plane,allplanes_group,False):
middle_plane.rect.left,middle_plane.rect.bottom = random.randint(0,411),0
middleplane_list.append(middle_plane)
middleplane_group.add(middle_plane)
allplanes_group.add(middle_plane)
middleplane_hitlist.append(0)
start1 = 0
create_time1 = start + middlecreate_list[4]
if start2:
large_plane = Large_plane(large_plane_name_1,large_plane_name_2,large_plane_name_3,large_plane_name_4,large_plane_name_5,large_plane_name_6,large_plane_name_7,large_plane_name_8,large_plane_name_9,speed_list[speed_index])
while py.sprite.spritecollide(large_plane,allplanes_group,False):
large_plane.rect.left,large_plane.rect.bottom = random.randint(0,315),0
largeplane_list.append(large_plane)
largeplane_group.add(large_plane)
allplanes_group.add(large_plane)
largeplane_hitlist.append(0)
start2 = 0
create_time2 = start + largecreate_list[4]
#myplane 方向控制
if flag_left:
myplane.move([-10,0])
if flag_right:
myplane.move([10,0])
if flag_up:
myplane.move([0,-10])
if flag_down:
myplane.move([0,10])
#投放炸弹清屏
if flag_space and num1text1:
bomb_sound.play()
flag_space = 0
num1text1 -= 1
scorestext1 += (len(smallplane_group) * 1000 + len(middleplane_group) * 5000 + len(largeplane_group) * 10000)
smallplane_destroylist = smallplane_list.copy()
middleplane_destroylist = middleplane_list.copy()
largeplane_destroylist = largeplane_list.copy()
plane_list_init(allplanes_group,smallplane_group,middleplane_group,largeplane_group,\
smallplane_list,middleplane_list,largeplane_list,middleplane_hitlist,largeplane_hitlist )
#分数/炸弹数显示
scorestext2 = 'SCORES:%04d'%scorestext1
scores = font1.render(scorestext2,False,(255,255,255))
num1text2 = 'X%d'%num1text1
num1 = font2.render(num1text2,False,(255,255,255))
num1_rect = num1.get_rect()
num1_rect.left,num1_rect.top = 70,653
#显示
screen.blit(bg_image,(0,0))
screen.blit(bomb_image,(0,643))
for vol in range(life_num):
screen.blit(life_image,life_list[vol])
screen.blit(scores,(0,0))
screen.blit(num1,num1_rect)
#补给
if not flag_destroyplane % 50:
supply_time += 1
if supply_time == 20:
supply_time = 0
supply_type = random.randint(0,1)
if supply_type:
supply = Supply(supply_name_1)
supply_bomb = 1
else:
supply = Supply(supply_name_2)
supply_bullet = 1
supply_sound.play()
supply_group.add(supply)
if supply_group:
for each in supply_group:
if each.out():
each.move()
else:
supply_group.empty()
screen.blit(each._image,each.rect)
#己方飞机显示
if not flag_bullet % 5 and not myplane._collide:
screen.blit(myplane._image,myplane.rect)
if flag_bullet % 5 and not myplane._collide:
screen.blit(myplane._image1,myplane.rect)
#己方飞机子弹的生成与移动
if supply_bullet and supply_get:
if not flag_bullet % 12:
supply_bullet_time += 1
bullet1 = Bullet_dubble1(bullet_name_2,myplane)
bullet2 = Bullet_dubble2(bullet_name_2,myplane)
bullet_sound.play()
if flag_up:
bullet1.rect.top -= 50
bullet2.rect.top -= 50
bullet_list.append(bullet1)
bullet_list.append(bullet2)
bullet_group.add(bullet1)
bullet_group.add(bullet2)
if supply_bullet_time == 60:
supply_bullet_time = 0
supply_bullet = 0
supply_get = 0
if not flag_bullet % 3 and bullet_group:
for each in bullet_group:
if each.existence():
each.move()
else:
bullet_group.remove(each)
bullet_list.remove(each)
else:
if not flag_bullet % 12:
bullet = Bullet(bullet_name_1,myplane)
bullet_sound.play()
if flag_up:
bullet.rect.top -= 50
bullet_list.append(bullet)
bullet_group.add(bullet)
if not flag_bullet % 3 and bullet_group:
for each in bullet_group:
if each.existence():
each.move()
else:
bullet_group.remove(each)
bullet_list.remove(each)
#检测己方飞机与敌方小飞机是否发生碰撞
if life_num == 0:
myplane._live = False
if myplane._protect:
if py.sprite.spritecollide(myplane,allplanes_group,False):
myplane_collide_sound.play()
myplane._collide = True
myplane._protect = False
life_num -= 1
#重生保护
else:
protect_time += 1
if protect_time == 300:
protect_time = 0
myplane._protect = True
if py.sprite.spritecollide(myplane,supply_group,True):
supply_get = 1
if supply_bullet:
supply_bullet_sound.play()
else:
supply_bomb_sound.play()
for each in smallplane_group:
if py.sprite.collide_rect(each,myplane):
each._collide = True
for each in middleplane_group:
if py.sprite.collide_rect(each,myplane):
each._collide = True
for each in largeplane_group:
if py.sprite.collide_rect(each,myplane):
each._collide = True
#轰炸次数
if supply_get and supply_bomb:
supply_bomb = 0
supply_get = 0
if num1text1 < 3:
num1text1 += 1
#己方飞机坠毁
if myplane._collide:
down = [myplane._destroy1,myplane._destroy2,myplane._destroy3,myplane._destroy4]
if not flag_destroyplane % 6:
screen.blit(down[j],myplane.rect)
j += 1
if not j % 4:
j = 0
myplane.rect.left,myplane.rect.bottom = (myplane._size[0] - myplane.rect.width) / 2,myplane._size[1] - 57
myplane._collide = False
#检测飞机是否被击落
for each in smallplane_group:
if py.sprite.spritecollide(each,bullet_group,True):
each._collide = True
scorestext1 += 1000
for each in middleplane_group:
if py.sprite.spritecollide(each,bullet_group,True):
middleplane_hitlist[middleplane_list.index(each)] += 1
each._hit += 1
if middleplane_hitlist[middleplane_list.index(each)] == 6:
each._collide = True
scorestext1 += 5000
for each in largeplane_group:
if py.sprite.spritecollide(each,bullet_group,True):
largeplane_hitlist[largeplane_list.index(each)] += 1
each._hit += 1
if largeplane_hitlist[largeplane_list.index(each)] == 10:
each._collide = True
scorestext1 += 10000
#显示子弹轨迹
for each in bullet_group:
screen.blit(each._image,each.rect)
#被击落飞机生成动画
for each in smallplane_group:
if each._collide:
smallplane_group.remove(each)
allplanes_group.remove(each)
smallplane_destroylist.append(smallplane_list.pop(smallplane_list.index(each)))
screen.blit(each._image,each.rect)
if smallplane_destroylist:
vol = smallplane_destroylist[0]
if not flag_bullet % 3:
down = [vol._down1,vol._down2,vol._down3,vol._down4]
screen.blit(down[i],vol.rect)
i += 1
if not i % 4:
i = 0
smallplane_destroylist.pop(0)
for each in middleplane_group:
if each._collide:
middle_down_sound.play()
middleplane_group.remove(each)
allplanes_group.remove(each)
index = middleplane_list.index(each)
middleplane_destroylist.append(middleplane_list.pop(index))
middleplane_hitlist.pop(index)
screen.blit(each._image,each.rect)
each.blood(screen)
if middleplane_destroylist:
vol = middleplane_destroylist[0]
if not flag_bullet % 3:
down = [vol._down1,vol._down2,vol._down3,vol._down4]
screen.blit(down[i],vol.rect)
m += 1
if not m % 4:
m = 0
middleplane_destroylist.pop(0)
for each in largeplane_group:
if each._collide:
large_down_sound.play()
largeplane_group.remove(each)
allplanes_group.remove(each)
index1 = largeplane_list.index(each)
largeplane_destroylist.append(largeplane_list.pop(index1))
largeplane_hitlist.pop(index1)
screen.blit(each._image,each.rect)
each.blood(screen)
if largeplane_destroylist:
vol = largeplane_destroylist[0]
if not flag_bullet % 3:
down = [vol._down1,vol._down2,vol._down3,vol._down4,vol._down5,vol._down6]
screen.blit(down[i],vol.rect)
n += 1
if not n % 6:
n = 0
largeplane_destroylist.pop(0)
if not myplane._live:
screen.blit(bg_image,(0,0))
screen.blit(bomb_image,(0,643))
screen.blit(scores,(0,0))
screen.blit(num1,num1_rect)
screen.blit(again_image,again_image_rect)
screen.blit(gameover_image,gameover_image_rect)
plane_list_init(allplanes_group,smallplane_group,middleplane_group,largeplane_group,\
smallplane_list,middleplane_list,largeplane_list,middleplane_hitlist,largeplane_hitlist )
bullet_group.empty()
bullet_list.clear()
pos = py.mouse.get_pos()
smallplane_destroylist.clear()
middleplane_destroylist.clear()
largeplane_destroylist.clear()
supply_bomb,supply_bullet,supply_get,supply_bullet_time,supply_time= 0,0,0,0,0
#暂停
pause1 = py.image.load(pause_name_1).convert_alpha()
pause2 = py.image.load(pause_name_2).convert_alpha()
pause1_rect = pause1.get_rect()
pause1_rect.right,pause1_rect.top = 480,0
pause_pos = py.mouse.get_pos()
resume1 = py.image.load(resume_name_1).convert_alpha()
resume2 = py.image.load(resume_name_2).convert_alpha()
if flag_pause:
if pause1_rect.left <= pause_pos[0] <= 480 and \
0 <= pause_pos[1] <= pause1_rect.height:
screen.blit(pause2,pause1_rect)
else:
screen.blit(pause1,pause1_rect)
if flag_resume:
flag_pause = 0
screen.blit(bg_image,(0,0))
if pause1_rect.left <= pause_pos[0] <= 480 and \
0 <= pause_pos[1] <= pause1_rect.height:
screen.blit(resume2,pause1_rect)
else:
screen.blit(resume1,pause1_rect)
flag_bullet += 1
flag_destroyplane += 1
if flag_bullet == 90:
flag_bullet = 0
if flag_destroyplane == 90:
flag_destroyplane = 0
py.display.flip()
clock.tick(60)
if __name__ == '__main__':
try:
main()
except SystemExit:
pass
except:
traceback.print_exc()
py.quit()
|
|