plane=Plane()
bullets=[]
for i in range(5):
bullets.append(Bullet())
#子弹总数
count_b=len(bullets)
#即将激活的子弹序号
index_b=0
#发射子弹的间隔
interval_b=0
enemies=[]
for i in range(5):
enemies.append(Enemy())
gameover=False
score=0
font=pygame.font.Font(None,32)
while True:
for event in pygame.event.get():
#接收到退出事件后退出程序
if event.type==pygame.QUIT:
pygame.quit()
sys.exit()
if gameover and event.type==pygame.MOUSEBUTTONUP:
plane.restart()
for e in enemies:
e.setLeval(1)
e.restart()
for b in bullets:
b.active=False
score=0
gameover=False
screen.blit(background,(0,0))
if gameover==False:
interval_b-=1
if(interval_b<0):
bullets[index_b].restart()
interval_b=100
index_b=(index_b+1)%count_b
#判断每个子弹的状态
for b in bullets:
if b.active:
for e in enemies:
if checkHit(e,b,score):
score+=100
b.move()
screen.blit(b.image,(b.x,b.y))
for e in enemies:
e.move()
screen.blit(e.image,(e.x,e.y))
for b in bullets:
if b.active:
b.move()
screen.blit(b.image,(b.x,b.y))
for e in enemies:
#如果撞上敌机,设gameover为True
if checkCrash(e, plane):
gameover = True
e.move()
screen.blit(e.image, (e.x, e.y))