1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
| #importation des modules
import pygame , math , random , time
from pygame.locals import *
pygame.init()
#definition des différente couche
fenetre = pygame.display.set_mode((480, 480))
fond = pygame.image.load("image/background.png").convert_alpha()#arriere plan
monstre = pygame.image.load("image/monstre.png").convert_alpha()#monstre en png 38x64
hero1 = pygame.image.load("image/Blue_knight.png").convert_alpha()#chevalier en png 34x52
hero2 = pygame.image.load("image/Purple_knight.png").convert_alpha()#chevalier en png 34x52
hero3 = pygame.image.load("image/Red_knight.png").convert_alpha()#chevalier en png 34x52
plan = pygame.image.load("image/plan.png").convert_alpha()#plan a mettre par dessus le plan pour faire deux couches
afficher_scoreNEGA = pygame.image.load("imageNEGA.png").convert_alpha() #image en forme de moins
afficher_score0 = pygame.image.load("image0.png").convert_alpha() #image en forme de 0
afficher_score1 = pygame.image.load("image1.png").convert_alpha() #image en forme de 1
afficher_score2 = pygame.image.load("image2.png").convert_alpha() #image en forme de 2
afficher_score3 = pygame.image.load("image3.png").convert_alpha() #image en forme de 3
afficher_score4 = pygame.image.load("image4.png").convert_alpha() #image en forme de 4
afficher_score5 = pygame.image.load("image5.png").convert_alpha() #image en forme de 5
hero = [hero1, hero2,hero3]
son = pygame.mixer.Sound("son/reussi.wav") #son pour quand on touche le monstre
fail = pygame.mixer.Sound("son/rater.wav") #son pour quand on touche le chevalier
intro = pygame.image.load("intro.png").convert() #image qui va defiler pour raconter une histoire 480x960
continuer = 1
score = 0
timer = 3 #je predefinis un timer
# boucle pour faire defiler l'image d'introduction
a = 0
while a >= -480:
fenetre.blit(intro, (0,a))
time.sleep(0.01)
a = a-1
# boucle principale
while score <= 5 and continuer == 1:
#Chargement du fond
fenetre.blit(fond, (0,0))
#Chargement du monstre (le monstre fais 38 par 64)
x = random.randint(38,442)
y = random.randint(64,416)
rect_monstre= fenetre.blit(monstre,(x,y)) #créé une variable définissant le rectangle ou se situe le monstre
w = random.randint(34,446)
z = random.randint(52,428)
color = random.choice(hero) #couleur du hero choisi aléatoirement
rect_hero= fenetre.blit(color,(w,z))#créé une variable définissant le rectangle ou se situe le héro
fenetre.blit(plan, (0,0)) #rajouter le plan par dessus pour enfermer entre deux plan les personage
#affichage des scores
if score == 0:
fenetre.blit(afficher_score0, (420,5))
if score == 1 or -1:
fenetre.blit(afficher_score1, (420,5))
elif score == 2 or -2:
fenetre.blit(afficher_score2, (420,5))
elif score == 3 or -3:
fenetre.blit(afficher_score3, (420,5))
elif score == 4 or -4:
fenetre.blit(afficher_score4, (420,5))
elif score == 5 or -5:
fenetre.blit(afficher_score5, (420,5))
time.sleep(2)
score = 6
if score <= -1:
fenetre.blit(afficher_scoreNEGA, (400,5))
pos_souris= pygame.mouse.get_pos()
for event in pygame.event.get():
if event.type == MOUSEBUTTONDOWN and event.button == 1 and rect_monstre.collidepoint(pos_souris): #action si on touche le monstre
son.play()
score = score + 1
print("monstre",score)
pygame.display.flip()
if event.type == MOUSEBUTTONDOWN and event.button == 1 and rect_hero.collidepoint(pos_souris): #action si on touche le hero
fail.play()
score = score - 1
print("hero",score)
pygame.display.flip()
if event.type == KEYDOWN and event.key == K_F1:
continuer = 0
score = 6
pygame.display.flip()
time.sleep(timer)
pygame.quit() |