Kommentare
This commit is contained in:
parent
88b0d7e07e
commit
60508bd2ef
@ -21,6 +21,8 @@ def creer_ananas(pos_x, pos_y):
|
|||||||
pygame.init()
|
pygame.init()
|
||||||
clock = pygame.time.Clock()
|
clock = pygame.time.Clock()
|
||||||
running = True
|
running = True
|
||||||
|
|
||||||
|
# Avion, das der Spieler steuert
|
||||||
avion = pygame.sprite.Sprite()
|
avion = pygame.sprite.Sprite()
|
||||||
pygame.sprite.Sprite.__init__(avion)
|
pygame.sprite.Sprite.__init__(avion)
|
||||||
avion.image = pygame.image.load("avion.png").convert_alpha()
|
avion.image = pygame.image.load("avion.png").convert_alpha()
|
||||||
@ -32,7 +34,11 @@ liste_des_sprites = pygame.sprite.LayeredUpdates()
|
|||||||
liste_des_sprites.add(fond)
|
liste_des_sprites.add(fond)
|
||||||
liste_sprites_ananas = pygame.sprite.LayeredUpdates()
|
liste_sprites_ananas = pygame.sprite.LayeredUpdates()
|
||||||
liste_des_sprites.add(avion)
|
liste_des_sprites.add(avion)
|
||||||
|
|
||||||
|
# Liste der ananas
|
||||||
liste_d_ananas = []
|
liste_d_ananas = []
|
||||||
|
|
||||||
|
# Hilfetext 1
|
||||||
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)
|
||||||
@ -42,6 +48,7 @@ texte.rect.centerx = 360
|
|||||||
texte.rect.centery = 30
|
texte.rect.centery = 30
|
||||||
liste_des_sprites.add(texte)
|
liste_des_sprites.add(texte)
|
||||||
|
|
||||||
|
# Hilfetext 2
|
||||||
police = pygame.font.Font(None, 20)
|
police = pygame.font.Font(None, 20)
|
||||||
texte2 = pygame.sprite.Sprite()
|
texte2 = pygame.sprite.Sprite()
|
||||||
texte2.image = police.render("Vous vous trouver dans l’engin SU-PER12. Votre mission est d’éliminer le plus d’ennemis possible!", 1, (10, 10, 10),(255, 90, 20))
|
texte2.image = police.render("Vous vous trouver dans l’engin SU-PER12. Votre mission est d’éliminer le plus d’ennemis possible!", 1, (10, 10, 10),(255, 90, 20))
|
||||||
@ -50,6 +57,7 @@ texte2.rect.centerx = 360
|
|||||||
texte2.rect.centery = 60
|
texte2.rect.centery = 60
|
||||||
liste_des_sprites.add(texte2)
|
liste_des_sprites.add(texte2)
|
||||||
|
|
||||||
|
# Hilfetext 3
|
||||||
police = pygame.font.Font(None, 20)
|
police = pygame.font.Font(None, 20)
|
||||||
texte3 = pygame.sprite.Sprite()
|
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 « espace » pour tirer et bougez la souris pour manoeuvrer votre SU-PER12!", 1, (10, 10, 10),(255, 90, 20))
|
||||||
@ -58,6 +66,7 @@ texte3.rect.centerx = 360
|
|||||||
texte3.rect.centery = 80
|
texte3.rect.centery = 80
|
||||||
liste_des_sprites.add(texte3)
|
liste_des_sprites.add(texte3)
|
||||||
|
|
||||||
|
# Hilfetext 4
|
||||||
police = pygame.font.Font(None, 20)
|
police = pygame.font.Font(None, 20)
|
||||||
texte4 = pygame.sprite.Sprite()
|
texte4 = pygame.sprite.Sprite()
|
||||||
texte4.image = police.render("Bonne chance!", 1, (10, 10, 10),(255, 90, 20))
|
texte4.image = police.render("Bonne chance!", 1, (10, 10, 10),(255, 90, 20))
|
||||||
@ -66,6 +75,7 @@ texte4.rect.centerx = 360
|
|||||||
texte4.rect.centery = 100
|
texte4.rect.centery = 100
|
||||||
liste_des_sprites.add(texte4)
|
liste_des_sprites.add(texte4)
|
||||||
|
|
||||||
|
# Hilfetext 5
|
||||||
police = pygame.font.Font(None, 20)
|
police = pygame.font.Font(None, 20)
|
||||||
texte5 = pygame.sprite.Sprite()
|
texte5 = pygame.sprite.Sprite()
|
||||||
texte5.image = police.render("ALERTE, PLANETE TERRE EST SOUS ATTAQUE", 1, (10, 10, 10),(255, 90, 20))
|
texte5.image = police.render("ALERTE, PLANETE TERRE EST SOUS ATTAQUE", 1, (10, 10, 10),(255, 90, 20))
|
||||||
@ -76,32 +86,45 @@ liste_des_sprites.add(texte5)
|
|||||||
|
|
||||||
gameover = False
|
gameover = False
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
|
# Hautschleife
|
||||||
while running:
|
while running:
|
||||||
liste_des_sprites.draw(fenetre)
|
liste_des_sprites.draw(fenetre)
|
||||||
liste_sprites_ananas.draw(fenetre)
|
liste_sprites_ananas.draw(fenetre)
|
||||||
|
|
||||||
|
# Benutzer Aktionen auswerten
|
||||||
for event in pygame.event.get():
|
for event in pygame.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
|
# Spiel beenden, wenn X gedrückt wurde
|
||||||
running = False
|
running = False
|
||||||
if event.type == MOUSEMOTION:
|
if event.type == MOUSEMOTION:
|
||||||
|
# Bewegung des avion
|
||||||
avion.rect.x = event.pos[0]
|
avion.rect.x = event.pos[0]
|
||||||
keys = pygame.key.get_pressed()
|
keys = pygame.key.get_pressed()
|
||||||
if keys[pygame.K_SPACE]:
|
if keys[pygame.K_SPACE]:
|
||||||
|
# Hilfetext bei Leertaste löschen
|
||||||
liste_des_sprites.remove(texte)
|
liste_des_sprites.remove(texte)
|
||||||
|
|
||||||
|
# Steuerung des Spiels
|
||||||
if gameover == False:
|
if gameover == False:
|
||||||
nombre_aleatoire = randint(0, 100)
|
nombre_aleatoire = randint(0, 100)
|
||||||
if nombre_aleatoire == 100:
|
if nombre_aleatoire == 100:
|
||||||
|
# Neues ananas erzeugen
|
||||||
position_x_aleatoire = randint(0, LARGEUR - 60)
|
position_x_aleatoire = randint(0, LARGEUR - 60)
|
||||||
nouvel_ananas = creer_ananas(position_x_aleatoire, -100)
|
nouvel_ananas = creer_ananas(position_x_aleatoire, -100)
|
||||||
liste_d_ananas.append(nouvel_ananas)
|
liste_d_ananas.append(nouvel_ananas)
|
||||||
liste_sprites_ananas.add(nouvel_ananas)
|
liste_sprites_ananas.add(nouvel_ananas)
|
||||||
|
# Alle ananas verarbeiten
|
||||||
for ananas in liste_d_ananas:
|
for ananas in liste_d_ananas:
|
||||||
ananas.rect.y += 5
|
ananas.rect.y += 5
|
||||||
if ananas.rect.colliderect(avion):
|
if ananas.rect.colliderect(avion):
|
||||||
|
# ananas erfolgreich abgefangen
|
||||||
print("COLLISION")
|
print("COLLISION")
|
||||||
score += 1
|
score += 1
|
||||||
liste_d_ananas.remove(ananas)
|
liste_d_ananas.remove(ananas)
|
||||||
ananas.kill()
|
ananas.kill()
|
||||||
if ananas.rect.y > HAUTEUR:
|
if ananas.rect.y > HAUTEUR:
|
||||||
|
# ananas nicht abgefangen
|
||||||
gameover = True
|
gameover = True
|
||||||
police = pygame.font.Font(None, 36)
|
police = pygame.font.Font(None, 36)
|
||||||
texte = pygame.sprite.Sprite()
|
texte = pygame.sprite.Sprite()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user