So I've asked this question before, but this time I did not make the same mistake of calling the text loop before making the screen blue.
def win1():
print('Level 1 completed')
global levelcount, var1, var2, clr, score, alive
myfont = pygame.font.SysFont('Comic Sans MS', 100)
textsurface = myfont.render('Level 1 completed', True, (0, 0, 0))
screen.blit(textsurface,(0,0))
for sprite in enemies:
sprite.kill()
pygame.time.wait(2800)
levelcount = 2
var1 = 700
var2 = 900
clr = (10, 85, 135)
myfont = pygame.font.SysFont('Comic Sans MS', 100)
textsurface = myfont.render('Level 2', True, (0, 0, 0))
screen.blit(textsurface,(0,0))
alive = True
score = 0
That code is supposed to make it say "Level 1 completed", but it doesn't. Here is where I call it:
alive = True
while alive:
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
alive = False
elif event.type == ADDENEMY:
new_opponent = random.choice([Enemy(), Bomb(), Blimp()])
enemies.add(new_opponent)
all_sprites.add(new_opponent)
pressed_keys = pygame.key.get_pressed()
player.update(pressed_keys)
enemies.update()
screen.fill(clr)
for entity in all_sprites:
screen.blit(entity.surf, entity.rect)
if pygame.sprite.spritecollideany(player, enemies):
player.kill()
alive = False
death()
if levelcount == 1: #I call it here
if score > 100:
alive = False
win1()
if levelcount == 2: #this is for if you beat level 2
if score > 100:
alive = False
win2()
screen.blit(player.surf, player.rect)
pygame.display.flip()
pygame.display.update()
clock.tick(60)
I have a death part that makes it say "you died" and it works, but I used almost the same code from it for the win part.