enemies = [] num = 10 for i in range(num): enemies.append(Enemy()) e_interval = 0
e_num = 0
scores = 0
font = pygame.font.Font(None,32) gameover = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() exit() if gameover and event.type == pygame.MOUSEBUTTONDOWN: gameover = False scores = 0 for e in enemies: e.blood = 0 for b in bullets: b.state = False screen.blit(background,(0,0)) if not gameover: if b_interval == 0: bullets[b_num].restart() b_num = (b_num + 1) % 10
b_interval = (b_interval + 1) % 100 for b in bullets: b.move() screen.blit(b.image,(b.x,b.y)) #此处逻辑跟先生不同,先生保证屏幕有固定的敌机数,
#我这里还是用子弹的逻辑,敌机出现的间隔保持一致 if e_interval == 0: if enemies[e_num].blood == 0: enemies[e_num].restart() e_num = (e_num + 1) % num
e_interval = (e_interval + 1) % 100 for e in enemies: if e.blood > 0: for b in bullets: if b.state: scores += hit(e, b) if crash(e, plane): gameover = True e.move() screen.blit(e.image,(e.x,e.y)) text = font.render('Scores:%d' % scores, True, (0, 0, 0)) screen.blit(text, (0, 0)) plane.move() screen.blit(plane.image,(plane.x,plane.y)) else: text = font.render('Scores:%d' % scores, True, (0, 0, 0)) screen.blit(text, (180, 300)) pygame.display.update() 作者: crossin先生 时间: 2018-11-20 22:59
可以的