From f12bd0b5e8cb814fd836fab150370d96a576f35b Mon Sep 17 00:00:00 2001 From: Stefan Liebl Date: Sat, 4 Jan 2025 16:15:19 +0100 Subject: [PATCH] caitlin: missiles --- main.py | 71 +++++++++++++++++++++++++++------------------------------ 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/main.py b/main.py index 6aa93d6..0305a8e 100644 --- a/main.py +++ b/main.py @@ -69,7 +69,7 @@ liste_des_sprites.add(texte2) police = pygame.font.Font(None, 20) texte3 = pygame.sprite.Sprite() -texte3.image = police.render("Pour ce faire, appuyez sur « espace » pour tirer et bougez la souris pour manoeuvrer votre SU-PER12!", 1, (10, 10, 10),(255, 90, 20)) +texte3.image = police.render("Pour ce faire, appuyez sur votre souris pour tirer et manoeuvrer votre SU-PER12!", 1, (10, 10, 10),(255, 90, 20)) texte3.rect = texte3.image.get_rect() texte3.rect.centerx = 360 texte3.rect.centery = 80 @@ -93,6 +93,8 @@ liste_des_sprites.add(texte5) gameover = False +ananas_speed = 4 + while running: keys = pygame.key.get_pressed() @@ -114,7 +116,6 @@ while running: avion.rect.x = event.pos[0] if event.type == MOUSEBUTTONDOWN: print("Vous avez tué l'ennemi! Continuez!") - liste_d_ananas.remove(ananas) nouveau_missile = tirer_missiles(avion.rect.centerx, HAUTEUR/2) liste_de_missiles.append(nouveau_missile) == [nouveau_missile] liste_sprites_missiles.add(nouveau_missile) == pygame.sprite.Group(nouveau_missile) @@ -127,7 +128,7 @@ while running: liste_d_ananas.append(nouvel_ananas) liste_sprites_ananas.add(nouvel_ananas) for ananas in liste_d_ananas: - ananas.rect.y += 2 + ananas.rect.y += ananas_speed if ananas.rect.colliderect(avion): print("COLLISION, L'OBJET A ÉTÉ ÉLIMINÉ, MALHEUREUSEMENT, VOUS AUSSI") liste_d_ananas.remove(ananas) @@ -135,44 +136,38 @@ while running: gameover = True if ananas.rect.y > HAUTEUR: gameover = True + police = pygame.font.Font(None, 36) + texte22 = pygame.sprite.Sprite() + pygame.sprite.Sprite.__init__(texte22) + texte22.image = police.render("Réessaye de tuer tout les ennemis!", 1, (10,10,10),(255, 90, 20)) + texte22.rect = texte22.image.get_rect() + texte22.rect.centerx = 360 + texte22.rect.centery = 500 + liste_des_sprites.add(texte22) - for missiles in liste_de_missiles: - ananas.rect.y -= 1 - if missiles.rect.colliderect(ananas): - print("COLLISION, L'OBJET A ÉTÉ ÉLIMINÉ") - liste_de_missiles.remove(missiles) - ananas.kill() - if ananas.rect.y <= 0: - gameover = True + police = pygame.font.Font(None, 36) + texte33 = pygame.sprite.Sprite() + pygame.sprite.Sprite.__init__(texte33) + texte33.image = police.render("L'ennemi est entré dans notre atmosphère!", 1, (10,10,10),(255, 90, 20)) + texte33.rect = texte33.image.get_rect() + texte33.rect.centerx = 360 + texte33.rect.centery = 450 + liste_des_sprites.add(texte33) - police = pygame.font.Font(None, 36) - texte1 = pygame.sprite.Sprite() - pygame.sprite.Sprite.__init__(texte1) - texte1.image = police.render("Gameover.", 1, (10,10,10),(255, 90, 20)) - texte1.rect = texte1.image.get_rect() - texte1.rect.centerx = 360 - texte1.rect.centery = 450 - liste_des_sprites.add(texte1) - - police = pygame.font.Font(None, 36) - texte22 = pygame.sprite.Sprite() - pygame.sprite.Sprite.__init__(texte22) - texte22.image = police.render("L'ennemi est entré dans notre atmosphère!", 1, (10,10,10),(255, 90, 20)) - texte22.rect = texte22.image.get_rect() - texte22.rect.centerx = 360 - texte22.rect.centery = 500 - liste_des_sprites.add(texte22) - - police = pygame.font.Font(None, 36) - texte33 = pygame.sprite.Sprite() - pygame.sprite.Sprite.__init__(texte33) - texte33.image = police.render("Réessaye de tuer tout les ennemis!", 1, (10,10,10),(255, 90, 20)) - texte33.rect = texte33.image.get_rect() - texte33.rect.centerx = 360 - texte33.rect.centery = 450 - liste_des_sprites.add(texte33) + for missiles in liste_de_missiles: + missiles.rect.y -= 10 + if missiles.rect.y <= 0: + liste_de_missiles.remove(missiles) + missiles.kill() + else: + for ananas in liste_d_ananas: + if ananas.rect.colliderect(missiles): + liste_d_ananas.remove(ananas) + ananas.kill() + liste_de_missiles.remove(missiles) + missiles.kill() pygame.display.flip() fenetre.fill((0,0,0)) - clock.tick(60) + clock.tick(50) pygame.quit()