caitlin: tirer_missiles

This commit is contained in:
Stefan Liebl 2025-01-01 21:49:43 +01:00
parent a7e291809e
commit a97c9ad62a

54
main.py
View File

@ -18,6 +18,21 @@ def creer_ananas(pos_x, pos_y):
ananas.rect.x = pos_x ananas.rect.x = pos_x
ananas.rect.y = pos_y ananas.rect.y = pos_y
return ananas return ananas
def tirer_missiles(pos_x, pos_y):
missiles = pygame.sprite.Sprite()
pygame.sprite.Sprite.__init__(missiles)
missiles.image = pygame.image.load("missiles.png").convert_alpha()
missiles.image = pygame.transform.scale(missiles.image,[50, 100])
missiles.rect = missiles.image.get_rect()
missiles.rect.x = pos_x
missiles.rect.y = pos_y
return missiles
liste_de_missiles = []
liste_sprites_missiles = pygame.sprite.Group()
pygame.sprite.LayeredUpdates()
pygame.init() pygame.init()
clock = pygame.time.Clock() clock = pygame.time.Clock()
running = True running = True
@ -34,9 +49,8 @@ liste_sprites_ananas = pygame.sprite.LayeredUpdates()
liste_des_sprites.add(avion) liste_des_sprites.add(avion)
liste_d_ananas = [] liste_d_ananas = []
if running == True:
keys = pygame.key.get_pressed()
keys = pygame.key.get_pressed()
police = pygame.font.Font(None, 25) police = pygame.font.Font(None, 25)
texte = pygame.sprite.Sprite() texte = pygame.sprite.Sprite()
pygame.sprite.Sprite.__init__(texte) pygame.sprite.Sprite.__init__(texte)
@ -45,8 +59,6 @@ if running == True:
texte.rect.centerx = 360 texte.rect.centerx = 360
texte.rect.centery = 30 texte.rect.centery = 30
liste_des_sprites.add(texte) liste_des_sprites.add(texte)
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte)
police = pygame.font.Font(None, 20) police = pygame.font.Font(None, 20)
texte2 = pygame.sprite.Sprite() texte2 = pygame.sprite.Sprite()
@ -55,8 +67,6 @@ if running == True:
texte2.rect.centerx = 360 texte2.rect.centerx = 360
texte2.rect.centery = 60 texte2.rect.centery = 60
liste_des_sprites.add(texte2) liste_des_sprites.add(texte2)
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte2)
police = pygame.font.Font(None, 20) police = pygame.font.Font(None, 20)
texte3 = pygame.sprite.Sprite() texte3 = pygame.sprite.Sprite()
@ -65,8 +75,6 @@ if running == True:
texte3.rect.centerx = 360 texte3.rect.centerx = 360
texte3.rect.centery = 80 texte3.rect.centery = 80
liste_des_sprites.add(texte3) liste_des_sprites.add(texte3)
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte3)
police = pygame.font.Font(None, 20) police = pygame.font.Font(None, 20)
texte4 = pygame.sprite.Sprite() texte4 = pygame.sprite.Sprite()
@ -75,8 +83,6 @@ if running == True:
texte4.rect.centerx = 360 texte4.rect.centerx = 360
texte4.rect.centery = 100 texte4.rect.centery = 100
liste_des_sprites.add(texte4) liste_des_sprites.add(texte4)
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte4)
police = pygame.font.Font(None, 20) police = pygame.font.Font(None, 20)
texte5 = pygame.sprite.Sprite() texte5 = pygame.sprite.Sprite()
@ -85,15 +91,18 @@ if running == True:
texte5.rect.centerx = 360 texte5.rect.centerx = 360
texte5.rect.centery = 1500 texte5.rect.centery = 1500
liste_des_sprites.add(texte5) liste_des_sprites.add(texte5)
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte5)
gameover = False gameover = False
score = 0 score = 0
while running: while running:
if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte)
liste_des_sprites.remove(texte1)
liste_des_sprites.remove(texte2)
liste_des_sprites.remove(texte3)
liste_des_sprites.remove(texte4)
liste_des_sprites.remove(texte5)
liste_des_sprites.draw(fenetre) liste_des_sprites.draw(fenetre)
liste_sprites_ananas.draw(fenetre) liste_sprites_ananas.draw(fenetre)
@ -104,6 +113,8 @@ while running:
avion.rect.x = event.pos[0] avion.rect.x = event.pos[0]
if event.type == MOUSEBUTTONDOWN: if event.type == MOUSEBUTTONDOWN:
print("Vous avez tué l'ennemi! Continuez!") print("Vous avez tué l'ennemi! Continuez!")
missiles.rect.centerx = avion.rect.centerx
missiles.rect.centery = HAUTEUR/2
keys = pygame.key.get_pressed() keys = pygame.key.get_pressed()
if keys[pygame.K_SPACE]: if keys[pygame.K_SPACE]:
liste_des_sprites.remove(texte) liste_des_sprites.remove(texte)
@ -126,9 +137,9 @@ while running:
police = pygame.font.Font(None, 36) police = pygame.font.Font(None, 36)
texte1 = pygame.sprite.Sprite() texte1 = pygame.sprite.Sprite()
pygame.sprite.Sprite.__init__(texte) pygame.sprite.Sprite.__init__(texte1)
texte.image = police.render("Gameover.", 1, (10,10,10),(255, 90, 20)) texte1.image = police.render("Gameover.", 1, (10,10,10),(255, 90, 20))
texte1.rect = texte.image.get_rect() texte1.rect = texte1.image.get_rect()
texte1.rect.centerx = 360 texte1.rect.centerx = 360
texte1.rect.centery = 450 texte1.rect.centery = 450
liste_des_sprites.add(texte1) liste_des_sprites.add(texte1)
@ -136,8 +147,8 @@ while running:
police = pygame.font.Font(None, 36) police = pygame.font.Font(None, 36)
texte22 = pygame.sprite.Sprite() texte22 = pygame.sprite.Sprite()
pygame.sprite.Sprite.__init__(texte22) pygame.sprite.Sprite.__init__(texte22)
texte.image = police.render("L'ennemi est entré dans notre atmosphère!", 1, (10,10,10),(255, 90, 20)) texte22.image = police.render("L'ennemi est entré dans notre atmosphère!", 1, (10,10,10),(255, 90, 20))
texte22.rect = texte.image.get_rect() texte22.rect = texte22.image.get_rect()
texte22.rect.centerx = 360 texte22.rect.centerx = 360
texte22.rect.centery = 500 texte22.rect.centery = 500
liste_des_sprites.add(texte22) liste_des_sprites.add(texte22)
@ -145,12 +156,13 @@ while running:
police = pygame.font.Font(None, 36) police = pygame.font.Font(None, 36)
texte33 = pygame.sprite.Sprite() texte33 = pygame.sprite.Sprite()
pygame.sprite.Sprite.__init__(texte33) pygame.sprite.Sprite.__init__(texte33)
texte.image = police.render("L'ennemi est entré dans notre atmosphère!", 1, (10,10,10),(255, 90, 20)) texte33.image = police.render("Réessaye de tuer tout les ennemis!", 1, (10,10,10),(255, 90, 20))
texte33.rect = texte.image.get_rect() texte33.rect = texte33.image.get_rect()
texte33.rect.centerx = 360 texte33.rect.centerx = 360
texte33.rect.centery = 450 texte33.rect.centery = 450
liste_des_sprites.add(texte33) liste_des_sprites.add(texte33)
pygame.display.flip() pygame.display.flip()
fenetre.fill((0,0,0)) fenetre.fill((0,0,0))
clock.tick(60) clock.tick(60)