Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- # -*- coding: Utf-8 -*
- """
- Project de BAC ISN, Alexandre REPPERT, Saina MARQUET, Raphael CAMUS
- Capture de drapeau
- Script Python
- Fichiers : pjetfinal.py, classes.py, constantes.py, images, sons, n0, n1, n2, n3, n4, n5, n6, n8, n9, niveau surprise
- """
- import pygame
- from pygame.locals import *
- from classes import *
- from constantes import *
- from fonction import *
- import random
- import time
- pygame.init()
- ###---Ouverture fenetre---###
- fenetre = pygame.display.set_mode((cote_fenetre, cote_fenetre), pygame.RESIZABLE)
- ###---Icone---###
- icone = pygame.image.load(image_icone)
- pygame.display.set_icon(icone)
- ###---Titre---###
- pygame.display.set_caption(titre_fenetre)
- ###---Variable qu'il ne faut charger qu'a l'ouverture du jeu---###
- DPG = 10
- pdb = 2
- tpsf = 60
- vol = 1 #-volume au maximum ( d'ou le 1 )-#
- ###---Sons---###
- son_tir = pygame.mixer.Sound(son_tir)
- son_gain = pygame.mixer.Sound(son_fin)
- son_mouton = pygame.mixer.Sound(son_mouton)
- pygame.mixer.music.load(son_menu)
- barre_son = pygame.image.load(image_barre_son_1).convert_alpha()
- pygame.mixer.music.play()
- ###---BOUCLE PRINCIPALE---###
- continuer = 1
- while continuer:
- accueil = pygame.image.load(image_accueil).convert()
- fenetre.blit(accueil, (0,0))
- ###---Lecture du son d'accueil---###
- ###---Rafraichissement---###
- pygame.display.flip()
- ###---variable mis a jour a chaque retour a la boucle principale---###
- Munition_Joueur1 = 8
- Munition_Joueur2 = 8
- munition_Grenade_Item_Joueur1 = 3
- Score_Joueur1 = 0
- DEM_Joueur1 = 0
- DEM_Joueur2 = 0
- Score_Joueur2 = 0
- stl = 1
- drapeau_spawn = 0
- t = time.time()
- recharge_tireJoueur1 = t - t
- recharge_tireJoueur2 = t - t
- Joueur1_Vole_DP = t - t
- Joueur2_Vole_DP = t - t
- Temps_Explo_Grenade = t - t
- Temps_Sup_Explo = t - t
- Temps_Spawn_Drapeau = t - t + 10
- ##--variable des boucle--##
- continuer_jeu = 1
- continuer_accueil = 1
- continuer_option = 1
- continuer_credit = 1
- continuer_commande = 1
- continuer_choix_niveau = 1
- continuer_choix_son_jeu = 1
- continuer_parametre = 1
- continuer_ChoixJoueur = 1
- continuer_Victoire_Joueur1 = 1
- continuer_Victoire_Joueur2 = 1
- ##--Liste--##
- GRENADEJoueur1 = [] #liste contenant les coordonnées de la grenade du joueur 1
- GRENADEJoueur2 = [] #liste contenant les coordonnées de la grenade du joueur 2
- EXPLOJoueur1 = [] #liste contenant les coordonnées des explosions de la grenade du joueur 1
- EXPLOJoueur2 = [] #liste contenant les coordonnées des explosions de la grenade du joueur 2
- ########################################
- ##########---Boucle Accueil---##########
- ########################################
- while continuer_accueil:
- pygame.time.Clock().tick(30)
- for event in pygame.event.get():
- if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
- pygame.quit()
- elif event.type == pygame.MOUSEBUTTONUP:
- x, y = event.pos
- ###---choix du menu---###
- #-Jouer-#
- if x >= 356 and x <= 550 and y >= 217 and y <= 321 :
- continuer_accueil = 0
- continuer_commande = 0
- continuer_parametre = 0
- continuer_option = 0
- continuer_credit = 0
- #-Option-#
- elif x >= 345 and x <= 561 and y >= 394 and y <= 502 :
- continuer_accueil = 0
- continuer_commande = 0
- continuer_parametre = 0
- continuer_option = 1
- #-Commande-#
- elif x >= 290 and x <= 614 and y >= 540 and y <= 626 :
- continuer_accueil = 0
- continuer_commande = 1
- continuer_parametre = 0
- continuer_option = 0
- continuer_credit = 0
- #-Quitter-#
- elif x >= 340 and x <= 563 and y >= 680 and y <= 745 :
- pygame.quit()
- #-Credit-#
- elif x >= 675 and x <= 891 and y >= 810 and y <= 894 :
- pass
- elif 6 <= x <= 376 and 827 <= y <= 888 :
- continuer_accueil = 0
- continuer_parametre = 1
- print(continuer_accueil)
- print(continuer_parametre)
- ########################################
- ##########---Boucle parametre---########
- ########################################
- while continuer_parametre:
- pygame.time.Clock().tick(30)
- parametre = pygame.image.load(image_parametre).convert()
- fenetre.blit(parametre, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- ###---Pour les touches cliquable---###
- elif event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- continuer_credit = 0
- continuer_parametre = 0
- continuer_option = 0
- continuer_commande = 0
- continuer_jeu = 0
- continuer_choix_niveau = 0
- continuer_choix_son_jeu = 0
- choix = 0
- continuer_ChoixJoueur = 0
- continuer_accueil = 1
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- elif event.type == pygame.MOUSEBUTTONUP:
- x, y = event.pos
- ##--Drapeau pour gagner--##
- if 89 <= x <= 144 and 122 <= y <= 210 :
- DPG = 5
- elif 240 <= x <= 331 and 122 <= y <= 210 :
- DPG = 10
- elif 422 <= x <= 512 and 122 <= y <= 210 :
- DPG = 15
- elif 592 <= x <= 824 and 124 <= y <= 210 :
- DPG = 1000
- ##--Portée de la bombe--##
- elif 322 <= x <= 364 and 698 <= y <= 787 :
- pdb = 1
- elif 539 <= x <= 600 and 698 <= y <= 787 :
- pdb = 2
- ##--Temps Maximum--##
- elif 234 <= x <= 277 and 438 <= y <= 525:
- tpsf = 15
- elif 423 <= x <= 483 and 438 <= y <= 525:
- tpsf = 120
- elif 600 <= x <= 667 and 438 <= y <= 525:
- tpsf = 180
- ########################################
- ###########---Boucle option---##########
- ########################################
- while continuer_option:
- pygame.time.Clock().tick(30)
- menu_option = pygame.image.load(image_menu_option).convert()
- fenetre.blit(menu_option, (0,0))
- fenetre.blit(barre_son, (198, 70)) #########a remettre correctement
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- elif event.type == KEYDOWN :
- if event.key == K_ESCAPE:
- continuer_option = 0
- continuer_commande = 0
- continuer_credit = 0
- continuer_parametre = 0
- continuer_jeu = 0
- continuer_choix_niveau = 0
- choix = 0
- continuer_ChoixJoueur = 0
- continuer_choix_son_jeu = 0
- continuer_accueil = 1
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- ###---Pour gerer le son---###
- elif event.key == K_9 and vol == 1 :
- pygame.mixer.music.set_volume(0.5) #-Met le volume à 0.5-#
- vol = 0.5
- print("volume a 0.5 de son max")
- barre_son = pygame.image.load(image_barre_son_0_5).convert_alpha()
- elif event.key == K_9 and vol == 0.5 :
- pygame.mixer.music.set_volume(0.25) #-Met le volume à 0.25-#
- vol= 0.25
- print("volume a 0.25 de son max")
- barre_son = pygame.image.load(image_barre_son_0_25).convert_alpha()
- elif event.key == K_0 and vol == 0.25 :
- pygame.mixer.music.set_volume(0.5) #-Met le volume à 0.5-#
- vol = 0.5
- print("volume a 0.5 de son max")
- barre_son = pygame.image.load(image_barre_son_0_5).convert_alpha()
- elif event.key == K_0 and vol == 0.5 :
- pygame.mixer.music.set_volume(1) #-Met le volume à son max-#
- vol = 1
- print("volume a son max")
- barre_son = pygame.image.load(image_barre_son_1).convert_alpha()
- elif event.type == pygame.MOUSEBUTTONUP :
- x, y = event.pos
- if 190 <= x <= 262 and 439 <= y <= 574 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_menu)
- pygame.mixer.music.play()
- elif 402 <= x <= 485 and 439 <= y <= 574 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_menu2)
- pygame.mixer.music.play()
- elif 602 <= x <= 673 and 439 <= y <= 574 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_menu3)
- pygame.mixer.music.play()
- elif 188 <= x <= 271 and 92 <= y <= 175 and vol == 1 :
- pygame.mixer.music.set_volume(0.5) #-Met le volume à 0.5-#
- vol = 0.5
- print("volume a 0.5 de son max")
- barre_son = pygame.image.load(image_barre_son_0_5).convert_alpha()
- elif 188 <= x <= 271 and 92 <= y <= 175 and vol == 0.5 :
- pygame.mixer.music.set_volume(0.25) #-Met le volume à 0.25-#
- vol= 0.25
- print("volume a 0.25 de son max")
- barre_son = pygame.image.load(image_barre_son_0_25).convert_alpha()
- elif 450 <= x <= 533 and 92 <= y <= 175 and vol == 0.25 :
- pygame.mixer.music.set_volume(0.5) #-Met le volume à 0.5-#
- vol = 0.5
- print("volume a 0.5 de son max")
- barre_son = pygame.image.load(image_barre_son_0_5).convert_alpha()
- elif 450 <= x <= 533 and 92 <= y <= 175 and vol == 0.50 :
- pygame.mixer.music.set_volume(1) #-Met le volume à son max-#
- vol = 1
- print("volume a son max")
- barre_son = pygame.image.load(image_barre_son_1).convert_alpha()
- pygame.display.flip()
- ########################################
- ##########---Boucle commande---#########
- ########################################
- while continuer_commande:
- pygame.time.Clock().tick(30)
- commande = pygame.image.load(image_commande).convert()
- fenetre.blit(commande, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- elif event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- continuer_credit = 0
- continuer_jeu = 0
- continuer_choix_niveau = 0
- continuer_commande = 0
- choix = 0
- continuer_ChoixJoueur = 0
- continuer_parametre = 0
- continuer_accueil = 1
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- continuer_choix_son_jeu = 0
- ########################################
- ##########---Boucle credit---###########
- ########################################
- while continuer_credit:
- pass ####################### a faire
- ########################################
- ######---Boucle choix du niveau---######
- ########################################
- while continuer_choix_niveau:
- ###---Limitation de vitesse de la boucle---###
- pygame.time.Clock().tick(30)
- choix_niveau = pygame.image.load(image_choix_niveau).convert()
- fenetre.blit(choix_niveau, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- elif event.type == KEYDOWN:
- ##--Retour au premier menu--##
- if event.key == K_ESCAPE:
- continuer_choix_niveau = 0
- choix = 0
- continuer_jeu = 0
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- continuer_parametre = 0
- continuer_choix_son_jeu = 0
- continuer_ChoixJoueur = 0
- continuer_accueil = 1
- ##--Lancement du niveau 1--##
- elif event.key == K_F1:
- continuer_choix_niveau = 0
- choix = 'n0'
- elif event.key == K_F2:
- continuer_choix_niveau = 0
- choix = 'n1'
- elif event.key == K_F3:
- continuer_choix_niveau = 0
- choix = 'n2'
- elif event.key == K_F4:
- continuer_choix_niveau = 0
- choix = 'n3' #niveau vide
- son_jeu.play(-1)
- elif event.key == K_F5:
- continuer_choix_niveau = 0
- choix = 'n4'
- elif event.key == K_F6:
- continuer_choix_niveau = 0
- choix = 'n5'
- elif event.key == K_F7:
- continuer_choix_niveau = 0
- choix = 'n6'
- elif event.key == K_F8:
- continuer_choix_niveau = 0
- choix = 'n7' #niveau labyrinthe
- son_jeu.play(-1)
- elif event.key == K_F9:
- continuer_choix_niveau = 0
- choix = 'n8'
- elif event.key == K_F10:
- continuer_choix_niveau = 0
- choix = 'n9'
- elif event.key == K_F11:
- continuer_choix_niveau = 0
- a = 1
- i = 1
- d = 1
- fichier=open('niveau_surprise','w') #ouverture ou creation du niveau surprise
- fichier.write('mmmmmmmmmmmaaaaaaaammmmmmmmmmm\n') #la premiere ligne est un mur
- while a<29:
- fichier.write('m') # on commence le ligne par un mur
- while i<29: #Tant que l'on a pas rempli la ligne
- aleatoire = random.randint(1,50) #on génère une variable aléatoire entre 1 et 10
- if aleatoire == 4 or aleatoire == 12 or aleatoire == 22 or aleatoire == 34 or aleatoire == 46: #si elle vaut 4 on crée un mur dans le niveau
- fichier.write('m')
- elif aleatoire == 5: # si elle vaut cinq et qu'il y a 1 ou 0 drapeau
- if d <= 15:
- fichier.write('i') # on en ajoute 1
- d+=1
- elif d >= 15: # sinon on ne met rien
- fichier.write('0')
- elif aleatoire != 4 and aleatoire != 5:
- fichier.write('0')
- i+=1
- fichier.write('m\n') # au bout de la ligne on ajoute un mur
- i=1
- a+=1
- fichier.write('mmmmmmmmmmmbbbbbbbbmmmmmmmmmmm') #la derniere ligne est un mur
- fichier.close() # fermeture du fichier
- choix = 'niveau_surprise' #niveau aleatoire
- d=1
- a=1
- if choix != 0:
- ###---Chargement du fond---###
- fond = pygame.image.load(image_fond).convert()
- ###---Génération d'un niveau à partir d'un fichier---###
- niveau = Niveau(choix)
- niveau.generer()
- niveau.afficher(fenetre)
- ###---Création des personnages---###
- Joueur1 = Perso("images/perso_one_droite.png", "images/perso_one_gauche.png",
- "images/perso_one_haut.png", "images/perso_one_bas.png", niveau)
- Joueur2 = Perso("images/perso2_droite.png","images/perso2_gauche.png",
- "images/perso2_haut.png","images/perso2_bas.png", niveau)
- Joueur1_drapeau = Perso("images/perso_one_droite_drapeau.png", "images/perso_one_gauche_drapeau.png",
- "images/perso_one_haut_drapeau.png", "images/perso_one_bas_drapeau.png", niveau)
- Joueur2_drapeau = Perso("images/perso2_droite_drapeau.png","images/perso2_gauche_drapeau.png",
- "images/perso2_haut_drapeau.png","images/perso2_bas_drapeau.png", niveau)
- ###---Création des IA---###
- Mouton1 = IA_Passive("images/IA/mouton/mouton_droite.png", "images/IA/mouton/mouton_gauche.png",
- "images/IA/mouton/mouton_haut.png", "images/IA/mouton/mouton_bas.png", niveau)
- ###---Création des projectiles---###
- p1 = Projectile(image_fleche,image_fleche,image_fleche,image_fleche,niveau, Joueur1)
- p2 = Projectile(image_fleche,image_fleche,image_fleche,image_fleche,niveau, Joueur2)
- ###---Creation de la tourelle---###
- tourelle = Tour("images/tourelle/tourelle_droite.png","images/tourelle/tourelle_gauche.png",
- "images/tourelle/tourelle_haut.png","images/tourelle/tourelle_bas.png", niveau)
- tourelle2 = Tour2("images/tourelle/tourelle_droite.png","images/tourelle/tourelle_gauche.png",
- "images/tourelle/tourelle_haut.png","images/tourelle/tourelle_bas.png", niveau)
- ###---Creation de la grenade---###
- Grenade_Item_Joueur1 = Grenade(image_grenade, image_grenade, image_grenade, image_grenade, niveau, Joueur1)
- ########################################
- ########---Boucle choix perso---########
- ########################################
- while continuer_ChoixJoueur:
- ChoixJoueur = pygame.image.load(image_ChoixJoueur).convert()
- fenetre.blit(ChoixJoueur, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == pygame.MOUSEBUTTONUP and event.button == 3 :
- x, y = event.pos
- ###---choix du style---###
- if 301 >= x >= 102 and 255 >= y >= 99 :
- stl = 1
- print(stl)
- elif 921 >= x >= 622 and 254 >= y >= 98 :
- stl = 2
- print(stl)
- elif 561 >= x >= 362 and 253 >= y >= 94 :
- stl = 3
- print(stl)
- ###---passer au jeu---###
- elif 900 >= x >= 706 and 900 >= y >= 789:
- continuer_ChoixJoueur = 0
- ###---Style_one---###
- elif stl == 1:
- if 608 >= x >= 457 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_one/gris/perso2_droite.png","images/personnages/perso2/style_one/gris/perso2_gauche.png",
- "images/personnages/perso2/style_one/gris/perso2_haut.png","images/personnages/perso2/style_one/gris/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_one/gris/perso2_droite_d.png","images/personnages/perso2/style_one/gris/perso2_gauche_d.png",
- "images/personnages/perso2/style_one/gris/perso2_haut_d.png","images/personnages/perso2/style_one/gris/perso2_bas_d.png", niveau)
- elif 251 >= x >= 100 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_one/marron/perso2_droite.png","images/personnages/perso2/style_one/marron/perso2_gauche.png",
- "images/personnages/perso2/style_one/marron/perso2_haut.png","images/personnages/perso2/style_one/marron/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_one/marron/perso2_droite_d.png","images/personnages/perso2/style_one/marron/perso2_gauche_d.png",
- "images/personnages/perso2/style_one/marron/perso2_haut_d.png","images/personnages/perso2/style_one/marron/perso2_bas_d.png", niveau)
- elif 790 >= x >= 639 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_one/vert/perso2_droite.png","images/personnages/perso2/style_one/vert/perso2_gauche.png",
- "images/personnages/perso2/style_one/vert/perso2_haut.png","images/personnages/perso2/style_one/vert/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_one/vert/perso2_droite_d.png","images/personnages/perso2/style_one/vert/perso2_gauche_d.png",
- "images/personnages/perso2/style_one/vert/perso2_haut_d.png","images/personnages/perso2/style_one/vert/perso2_bas_d.png", niveau)
- elif 431 >= x >= 280 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_one/jaune/perso2_droite.png","images/personnages/perso2/style_one/jaune/perso2_gauche.png",
- "images/personnages/perso2/style_one/jaune/perso2_haut.png","images/personnages/perso2/style_one/jaune/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_one/jaune/perso2_droite_d.png","images/personnages/perso2/style_one/jaune/perso2_gauche_d.png",
- "images/personnages/perso2/style_one/jaune/perso2_haut_d.png","images/personnages/perso2/style_one/jaune/perso2_bas_d.png", niveau)
- ###---Style_2---###
- elif stl == 2:
- if 608 >= x >= 457 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_2/gris/perso2_droite.png","images/personnages/perso2/style_2/gris/perso2_gauche.png",
- "images/personnages/perso2/style_2/gris/perso2_haut.png","images/personnages/perso2/style_2/gris/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_2/gris/perso2_droite_d.png","images/personnages/perso2/style_2/gris/perso2_gauche_d.png",
- "images/personnages/perso2/style_2/gris/perso2_haut_d.png","images/personnages/perso2/style_2/gris/perso2_bas_d.png", niveau)
- elif 251 >= x >= 100 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_2/marron/perso2_droite.png","images/personnages/perso2/style_2/marron/perso2_gauche.png",
- "images/personnages/perso2/style_2/marron/perso2_haut.png","images/personnages/perso2/style_2/marron/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_2/marron/perso2_droite_d.png","images/personnages/perso2/style_2/marron/perso2_gauche_d.png",
- "images/personnages/perso2/style_2/marron/perso2_haut_d.png","images/personnages/perso2/style_2/marron/perso2_bas_d.png", niveau)
- elif 790 >= x >= 639 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_2/vert/perso2_droite.png","images/personnages/perso2/style_2/vert/perso2_gauche.png",
- "images/personnages/perso2/style_2/vert/perso2_haut.png","images/personnages/perso2/style_2/vert/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_2/vert/perso2_droite_d.png","images/personnages/perso2/style_2/vert/perso2_gauche_d.png",
- "images/personnages/perso2/style_2/vert/perso2_haut_d.png","images/personnages/perso2/style_2/vert/perso2_bas_d.png", niveau)
- elif 431 >= x >= 280 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_2/jaune/perso2_droite.png","images/personnages/perso2/style_2/jaune/perso2_gauche.png",
- "images/personnages/perso2/style_2/jaune/perso2_haut.png","images/personnages/perso2/style_2/jaune/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_2/jaune/perso2_droite_d.png","images/personnages/perso2/style_2/jaune/perso2_gauche_d.png",
- "images/personnages/perso2/style_2/jaune/perso2_haut_d.png","images/personnages/perso2/style_2/jaune/perso2_bas_d.png", niveau)
- ###---Style_3---###
- elif stl == 3:
- if 608 >= x >= 457 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_3/gris/perso2_droite.png","images/personnages/perso2/style_3/gris/perso2_gauche.png",
- "images/personnages/perso2/style_3/gris/perso2_haut.png","images/personnages/perso2/style_3/gris/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_3/gris/perso2_droite_d.png","images/personnages/perso2/style_3/gris/perso2_gauche_d.png",
- "images/personnages/perso2/style_3/gris/perso2_haut_d.png","images/personnages/perso2/style_3/gris/perso2_bas_d.png", niveau)
- elif 251 >= x >= 100 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_3/marron/perso2_droite.png","images/personnages/perso2/style_3/marron/perso2_gauche.png",
- "images/personnages/perso2/style_3/marron/perso2_haut.png","images/personnages/perso2/style_3/marron/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_3/marron/perso2_droite_d.png","images/personnages/perso2/style_3/marron/perso2_gauche_d.png",
- "images/personnages/perso2/style_3/marron/perso2_haut_d.png","images/personnages/perso2/style_3/marron/perso2_bas_d.png", niveau)
- elif 790 >= x >= 639 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_3/vert/perso2_droite.png","images/personnages/perso2/style_3/vert/perso2_gauche.png",
- "images/personnages/perso2/style_3/vert/perso2_haut.png","images/personnages/perso2/style_3/vert/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_3/vert/perso2_droite_d.png","images/personnages/perso2/style_3/vert/perso2_gauche_d.png",
- "images/personnages/perso2/style_3/vert/perso2_haut_d.png","images/personnages/perso2/style_3/vert/perso2_bas_d.png", niveau)
- elif 431 >= x >= 280 and 499 >= y >= 348:
- Joueur2 = Perso("images/personnages/perso2/style_3/jaune/perso2_droite.png","images/personnages/perso2/style_3/jaune/perso2_gauche.png",
- "images/personnages/perso2/style_3/jaune/perso2_haut.png","images/personnages/perso2/style_3/jaune/perso2_bas.png", niveau)
- Joueur2_drapeau = Perso("images/personnages/perso2/style_3/jaune/perso2_droite_d.png","images/personnages/perso2/style_3/jaune/perso2_gauche_d.png",
- "images/personnages/perso2/style_3/jaune/perso2_haut_d.png","images/personnages/perso2/style_3/jaune/perso2_bas_d.png", niveau)
- elif event.type == KEYDOWN:
- if event.key == K_F1:
- perso2= Perso("images/personnages/tank_droite.png","images/personnages/tank_gauche.png","images/personnages/tank_haut.png","images/personnages/tank_bas.png",niveau)
- perso2_drapeau = Perso("images/personnages/tank_droite.png","images/personnages/tank_gauche.png","images/personnages/tank_haut.png","images/personnages/tank_bas.png",niveau)
- elif event.key == K_F2:
- perso2 = Perso("images/personnages/tnk_droite.png","images/personnages/tnk_gauche.png","images/personnages/tnk_haut.png","images/personnages/tnk_bas.png",niveau)
- perso2_drapeau = Perso("images/personnages/tnk_droite.png","images/personnages/tnk_gauche.png","images/personnages/tnk_haut.png","images/personnages/tnk_bas.png",niveau)
- ########################################
- ###---Boucle définition son du jeu---###
- ########################################
- while continuer_choix_son_jeu:
- pygame.time.Clock().tick(30)
- choix_son_jeu = pygame.image.load(image_choix_son_jeu).convert()
- fenetre.blit(choix_son_jeu, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- elif event.type == MOUSEBUTTONUP:
- x, y = event.pos
- if 104 <= x <= 216 and 167 <= y <= 403 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_jeu)
- pygame.mixer.music.play()
- elif 394 <= x <= 508 and 167 <= y <= 393 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_jeu2)
- pygame.mixer.music.play()
- elif 674 <= x <= 789 and 168 <= y <= 396 :
- pygame.mixer.music.stop()
- pygame.mixer.music.load(son_jeu3)
- pygame.mixer.music.play()
- elif 700 <= x <= 900 and 780 <= y <= 900 :
- continuer_choix_son_jeu = 0
- c = time.time()
- ########################################
- ##########---Boucle du jeu---###########
- ########################################
- while continuer_jeu:
- ###---Limitation de vitesse de la boucle---###
- pygame.time.Clock().tick(30)
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- elif event.type == KEYDOWN:
- if event.key == K_ESCAPE:
- continuer_jeu = 0
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- ###---Touche de Mouvement Joueur1---###
- elif event.key == K_d:
- Grenade_Item_Joueur1.deplacer('droite')
- ##--Collision Drapeau / person_one--##
- if niveau.structure[Joueur1.case_y][Joueur1.case_x+1] == 'i':
- niveau.structure[Joueur1.case_y][Joueur1.case_x+1]='0'
- DEM_Joueur1 += 1
- Joueur1.d1 = 0
- ##--Déplacement Joueur1--##
- Joueur1.deplacer('droite')
- direction='droite'
- elif event.key == K_a:
- Grenade_Item_Joueur1.deplacer('gauche')
- if niveau.structure[Joueur1.case_y][Joueur1.case_x-1] == 'i':
- niveau.structure[Joueur1.case_y][Joueur1.case_x-1]='0'
- DEM_Joueur1 += 1
- Joueur1.d1 = 0
- Joueur1.deplacer('gauche')
- direction='gauche'
- elif event.key == K_w:
- Grenade_Item_Joueur1.deplacer('haut')
- if niveau.structure[Joueur1.case_y-1][Joueur1.case_x] == 'i':
- niveau.structure[Joueur1.case_y-1][Joueur1.case_x]='0'
- DEM_Joueur1 += 1
- Joueur1.d1 = 0
- Joueur1.deplacer('haut')
- direction='haut'
- elif event.key == K_s:
- Grenade_Item_Joueur1.deplacer('bas')
- if niveau.structure[Joueur1.case_y+1][Joueur1.case_x] == 'i':
- niveau.structure[Joueur1.case_y+1][Joueur1.case_x]='0'
- DEM_Joueur1 += 1
- Joueur1.d1 = 0
- Joueur1.deplacer('bas')
- direction='bas'
- ##--Tir du Joueur1--##
- elif event.key == K_SPACE:
- i=0
- if Munition_Joueur1 > 0:
- son_tir.play()
- Munition_Joueur1 -= 1
- TirJoueur1(Joueur1, Joueur2, niveau, direction, i)
- ##--Rechargement Joueur1--##
- elif event.key == K_r and niveau.structure[Joueur1.case_y][Joueur1.case_x] == 'c' and Munition_Joueur1 < 24 and TempsActuel > recharge_tireJoueur1:
- recharge_tireJoueur1 = TempsActuel + 3
- print ("tps actuel =", round(TempsActuel),"seconde")
- print ("recharge tire à = ", round(recharge_tireJoueur1),"seconde")
- Munition_Joueur1 += 8
- if Munition_Joueur1 >24: #-Limitation a 24 munition-#
- Munition_Joueur1 = 24
- ###---Touche de Mouvement Joueur2---###
- elif event.key == K_RIGHT:
- if niveau.structure[Joueur2.case_y][Joueur2.case_x+1] == 'i':
- niveau.structure[Joueur2.case_y][Joueur2.case_x+1]='0'
- DEM_Joueur2 += 1
- Joueur2.d1 = 0
- Joueur2.deplacer('droite')
- direction = 'droite'
- elif event.key == K_LEFT:
- if niveau.structure[Joueur2.case_y][Joueur2.case_x-1] == 'i':
- niveau.structure[Joueur2.case_y][Joueur2.case_x-1]='0'
- DEM_Joueur2 += 1
- Joueur2.d1 = 0
- Joueur2.deplacer('gauche')
- direction = 'gauche'
- elif event.key == K_UP:
- if niveau.structure[Joueur2.case_y-1][Joueur2.case_x] == 'i':
- niveau.structure[Joueur2.case_y-1][Joueur2.case_x]='0'
- DEM_Joueur2 += 1
- Joueur2.d1 = 0
- Joueur2.deplacer('haut')
- direction = 'haut'
- elif event.key == K_DOWN:
- if niveau.structure[Joueur2.case_y+1][Joueur2.case_x] == 'i':
- niveau.structure[Joueur2.case_y+1][Joueur2.case_x]='0'
- DEM_Joueur2 += 1
- Joueur2.d1 = 0
- Joueur2.deplacer('bas')
- direction = 'bas'
- ##--Tir du Joueur2--##
- elif event.key == K_KP0:
- i=0
- if Munition_Joueur2 > 0:
- son_tir.play()
- Munition_Joueur2 -= 1
- TirJoueur2(Joueur1, Joueur2, niveau, direction, i)
- print(r1)
- ##--rechargement du Joueur2--##
- elif event.key == K_KP3 and niveau.structure[Joueur2.case_y][Joueur2.case_x] == 'c' and Munition_Joueur2 < 24 and TempsActuel > recharge_tireJoueur2:
- recharge_tireJoueur2 = TempsActuel + 3
- print ("tps actuel =", round(TempsActuel),"seconde")
- print ("recharge tire à = ", round(recharge_tireJoueur2),"seconde")
- Munition_Joueur2 += 8
- if Munition_Joueur2 >24: #-Limitation a 24 munition-#
- Munition_Joueur2 = 24
- ###---Lancement de Grenade Joueur1---###
- elif event.key == K_g:
- if len (GRENADEJoueur1) < 1:
- Grenade_Item_Joueur1.placer(niveau, Joueur1, direction, pdb)
- print(GRENADEJoueur1)
- print(EXPLOJoueur1)
- Temps_Explo_Grenade = TempsActuel + 3
- if direction == 'droite' :
- GRENADEJoueur1.append((Grenade_Item_Joueur1.case_x+pdb, Grenade_Item_Joueur1.case_y ))
- EXPLOJoueur1.append((Grenade_Item_Joueur1.case_x+pdb, Grenade_Item_Joueur1.case_y ))
- elif direction == 'gauche' :
- GRENADEJoueur1.append((Grenade_Item_Joueur1.case_x-pdb, Grenade_Item_Joueur1.case_y ))
- EXPLOJoueur1.append((Grenade_Item_Joueur1.case_x+pdb, Grenade_Item_Joueur1.case_y ))
- elif direction == 'bas' :
- GRENADEJoueur1.append((Grenade_Item_Joueur1.case_x, Grenade_Item_Joueur1.case_y+pdb ))
- EXPLOJoueur1.append((Grenade_Item_Joueur1.case_x+pdb, Grenade_Item_Joueur1.case_y ))
- elif direction == 'haut' :
- GRENADEJoueur1.append((Grenade_Item_Joueur1.case_x, Grenade_Item_Joueur1.case_y-pdb ))
- EXPLOJoueur1.append((Grenade_Item_Joueur1.case_x+pdb, Grenade_Item_Joueur1.case_y ))
- elif event.key == K_o :
- reaparition(Joueur1)
- direction='droite'
- if len(GRENADEJoueur1)!=0:
- if TempsActuel >= Temps_Explo_Grenade : #Fait exploser la bombe au bout de 3 sec
- Grenade_Item_Joueur1.exploser(GRENADEJoueur1[0])
- GRENADEJoueur1 = GRENADEJoueur1[1:]
- Temps_Sup_Explo = TempsActuel + 3
- #son_explosion.play()
- elif len(EXPLOJoueur1) !=0:
- if TempsActuel >= Temps_Sup_Explo : #Fait exploser la bombe au bout de 3 sec
- Grenade_Item_Joueur1.supprimer(EXPLOJoueur1[0])
- EXPLOJoueur1=EXPLOJoueur1[1:]
- ## elif len(BOMBES2)!=0:
- ## if time.clock()-BOMBES2[0][2] > 3:
- ## b2.exploser2(BOMBES2[0])
- ## BOMBES2=BOMBES2[1:]
- ## son_explosion.play()
- ## elif len(EXPLO2) !=0:
- ## if time.clock()-EXPLO2[0][2] > 4:
- ## b2.effacer2(EXPLO2[0])
- ## EXPLO2=EXPLO2[1:]
- ## elif r1 == 1:
- ## if Score_Joueur1 >=2 :
- ## Score_Joueur1 = Score_Joueur1 //2
- ## drapeau_spawn = Score_Joueur1 //2 # à refaire
- ##
- ## elif drapeau_spawn !=0 :
- ## drapeau_spawn -=1
- ## drapeau_spawn_list += [1]
- ## print(drapeau_spawn_list)
- elif niveau.structure[Joueur1.case_y][Joueur1.case_x] == 'e':
- reaparition(Joueur1)
- elif niveau.structure[Joueur2.case_y][Joueur2.case_x] == 'e':
- reaparition(Joueur2)
- ###---Affichages aux nouvelles positions---###
- fenetre.blit(fond, (0,0))
- niveau.afficher(fenetre)
- fenetre.blit(Joueur1.direction, (Joueur1.x, Joueur1.y))
- fenetre.blit(Joueur2.direction, (Joueur2.x, Joueur2.y))
- #-IA Passive-#
- Mouton1.deplacer("Partout")
- bele(son_mouton)
- fenetre.blit(Mouton1.direction, (Mouton1.x, Mouton1.y))
- #-Tourelle-#
- tourelle.tourne()
- fenetre.blit(tourelle.direction, (tourelle.x, tourelle.y))
- tourelle2.tourne()
- fenetre.blit(tourelle2.direction, (tourelle2.x, tourelle2.y))
- smallfont = pygame.font.SysFont("comicsansms", 25)
- ###---Score_Joueur1---###
- HUD = pygame.image.load(image_HUD).convert()
- fenetre.blit(HUD, (0,731))
- score_affJoueur1=smallfont.render(str(Score_Joueur1), True, (0,0,0))
- fenetre.blit(score_affJoueur1, (25,815))
- score_affDEM_Joueur1=smallfont.render(str(DEM_Joueur1), True, (0,0,0))
- fenetre.blit(score_affDEM_Joueur1, (75,768))
- Munition_Joueur1_aff = smallfont.render(str(Munition_Joueur1), True, (BLACK))
- fenetre.blit(Munition_Joueur1_aff, (130,815))
- ###---Score_Joueur2---###
- HUD = pygame.image.load(image_HUD).convert()
- fenetre.blit(HUD, (731,731))
- score_affJoueur2=smallfont.render(str(Score_Joueur2), True, (0,0,0))
- fenetre.blit(score_affJoueur2, (755,815))
- score_affDEM_Joueur2=smallfont.render(str(DEM_Joueur2), True, (0,0,0))
- fenetre.blit(score_affDEM_Joueur2, (805,768))
- Munition_Joueur2_aff = smallfont.render(str(Munition_Joueur2), True, (BLACK))
- fenetre.blit(Munition_Joueur2_aff, (860,815))
- ###---Chronometre---###
- Tpsi = time.time()
- TempsActuel = Tpsi-c
- Chronotxt = smallfont.render(str(round(TempsActuel)), True, (0,0,0))
- fenetre.blit(Chronotxt, (805,858))
- fenetre.blit(Chronotxt, (75,858))
- if Joueur1.d1 == 0:
- Joueur1 = Joueur1_drapeau
- if Joueur2.d1 == 0:
- Joueur2 = Joueur2_drapeau
- if p1.u !=0 or p1.v !=0 :
- fenetre.blit(p1.direction,(p1.u, p1.v))
- if p2.u !=0 or p2.v !=0 :
- fenetre.blit(Joueur2.direction,(Joueur2.u, Joueur2.v))
- drapeau_aleat(TempsActuel, Temps_Spawn_Drapeau, niveau)
- pygame.display.flip()
- ###---Collision Joueur / base ###
- if niveau.structure[Joueur1.case_y][Joueur1.case_x] == 'a' and Joueur1 == Joueur1_drapeau:
- Score_Joueur1 += DEM_Joueur1
- DEM_Joueur1 = 0
- if niveau.structure[Joueur2.case_y][Joueur2.case_x] == 'b' and Joueur2 == Joueur2_drapeau:
- Score_Joueur2 += DEM_Joueur2
- DEM_Joueur2 = 0
- ###---collision joueur/ base ennemie---###
- if niveau.structure[Joueur1.case_y][Joueur1.case_x] == 'b' and Joueur1 == Joueur1_drapeau and Score_Joueur2 >=1:
- if TempsActuel > Joueur1_Vole_DP :
- Joueur1_Vole_DP = TempsActuel + 3
- DEM_Joueur1 += 1
- Score_Joueur2 -= 1
- if niveau.structure[Joueur2.case_y][Joueur2.case_x] == 'a' and Joueur2 == Joueur2_drapeau and Score_Joueur1 >=1:
- if TempsActuel > Joueur2_Vole_DP :
- Joueur2_Vole_DP = TempsActuel + 3
- DEM_Joueur2 += 1
- Score_Joueur1 -= 1
- ###---Si joueur arrive au nombre de drapeau définit---###
- if Score_Joueur1 >= DPG:
- continuer_Victoire_Joueur2 = 0
- continuer_jeu = 0
- if Score_Joueur2 >= DPG:
- continuer_Victoire_Joueur1 = 0
- continuer_jeu = 0
- if round(TempsActuel) >= tpsf :
- print('fin')
- if Score_Joueur1 >= Score_Joueur2 :
- continuer_jeu = 0
- continuer_Victoire_Joueur2 = 0
- print('Joueur1')
- if Score_Joueur1 <= Score_Joueur2 :
- continuer_jeu = 0
- continuer_Victoire_Joueur1 = 0
- print('Joueur2')
- if Score_Joueur1 == Score_Joueur2 :
- continuer_jeu = 0
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- print ('rien')
- ########################################
- #####---Boucle de victoire Joueur1---######
- ########################################
- while continuer_Victoire_Joueur1:
- pygame.time.Clock().tick(30)
- continuer_Victoire_Joueur1 = pygame.image.load(image_VictoireJoueur1)
- fenetre.blit(continuer_Victoire_Joueur1, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
- pygame.quit()
- elif event.type == KEYDOWN:
- if event.key == K_SPACE:
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
- ########################################
- ######---Boucle de victoire Joueur2---#######
- ########################################
- while continuer_Victoire_Joueur2:
- pygame.time.Clock().tick(30)
- continuer_Victoire_Joueur2 = pygame.image.load(image_VictoireJoueur2)
- fenetre.blit(continuer_Victoire_Joueur2, (0,0))
- pygame.display.flip()
- for event in pygame.event.get():
- if event.type == QUIT or event.type == KEYDOWN and event.key == K_ESCAPE:
- pygame.quit()
- elif event.type == KEYDOWN:
- if event.key == K_SPACE:
- continuer_Victoire_Joueur1 = 0
- continuer_Victoire_Joueur2 = 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement