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
|
import pygame,sys,random
from pygame.locals import * #Importation
import pygame as pg
# Ennemi et Tank
Ennemi=pygame.image.load("Ennemi.png")
Tank=pygame.image.load("Tank.png")
xMaxEnnemi = 1300
xMinEnnemi = 50
yMinEnnemi = 50
yMaxEnnemi = 600
NbZombies=10
pygame.init()
pygame.display.set_caption('TMDC') #Initialisation Fenêtre
fen=pygame.display.set_mode((1407,737))
fond = pygame.image.load("Plan de jeu.png")
fen.blit(fond,(0,0))
###########################################
# Son ambiance
son2 = pygame.mixer.Sound("ambiance.wav")
son2.play(-1) #joue le son2 en boucle.
rectTank=fen.blit(Tank,(1360,690))
pygame.display.update
def ListeCoordsZombies():
liste=[]
for i in range(NbZombies):
x=random.randint(xMinEnnemi,xMaxEnnemi)
y=random.randint(yMinEnnemi,yMaxEnnemi)
liste.append([x,y])
return liste
LCZ=ListeCoordsZombies()
def affiche():
for i in range(NbZombies):
fen.blit(Ennemi,(LCZ[i][0],LCZ[i][1]))
fin=0
def collision():
for i in range(NbZombies):
rectEnnemiG=fen.blit(Ennemi,(LCZ[i][0],LCZ[i][1]))
if rectTank.colliderect(rectEnnemiG)==True:
LCZ[i][0]+=1000000
global fin
fin=fin+1
print(fin)
fen.blit(Tank,rectTank)
pygame.display.update()
start_ticks=pygame.time.get_ticks()
while True:
secondes=(pygame.time.get_ticks()-start_ticks)/1000
pygame.key.set_repeat(40,20)
collision()
for evenement in pygame.event.get():
if evenement.type==QUIT:
pygame.quit()
sys.exit
if evenement.type==KEYDOWN:
listeTouche = pygame.key.get_pressed()
if listeTouche[K_RIGHT]:
if rectTank.x<1400:
rectTank.x=rectTank.x+25
if listeTouche[K_LEFT]:
if rectTank.x>10:
rectTank.x=rectTank.x-25
if listeTouche[K_UP]:
if rectTank.y>10:
rectTank.y=rectTank.y-25
if listeTouche[K_DOWN]:
if rectTank.y<700:
rectTank.y=rectTank.y+25
fen.blit(fond,(0,0))
affiche()
fen.blit(Tank,rectTank)
pygame.display.update()
if fin==10:
pygame.display.quit()
sys.exit
print ("Félicitation, vous avez gagné !")
print (secondes) |
Partager