-
Notifications
You must be signed in to change notification settings - Fork 3
/
mapgest.py
96 lines (79 loc) · 3.42 KB
/
mapgest.py
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
#-------------------------------------------------------------------------------
# Name: Map gestionnaire
#
# Author: sl-prog
#
# Licence: <GNU GENERAL PUBLIC LICENSE>
#-------------------------------------------------------------------------------
import pygame
from pygame.locals import *
from constantes import *
import players
#Importation du module genereation aleatoire
from random import randint
from PIL import Image, ImageDraw
def mapinit(skin1, skin2, nombre_perso, viemax, fondchoix, mapchoix):
#copie image map
mapcopie = Image.open(mapchoix)
mapcopie.save("image/mapcopie.png", 'PNG')
#Chargement du fond
fond = pygame.image.load(fondchoix).convert()
#Chargement de la montagne + mask + rect
decor = pygame.sprite.Sprite()
decor.image = pygame.image.load("image/mapcopie.png").convert_alpha()
decor.rect = decor.image.get_rect()
decor.rect.topleft = 0,0
decor.mask = pygame.mask.from_surface(decor.image)
#Chargement du rectangle projectile + mask + rect
projectile = pygame.sprite.Sprite()
projectile.image = pygame.image.load("image/armes/prj1.png").convert_alpha()
projectile.rect = projectile.image.get_rect()
projectile.mask = pygame.mask.from_surface(projectile.image)
#generation des personnages :
vies1 = [viemax]*nombre_perso #on donne de la vie a chaque perso
vies2 = [viemax]*nombre_perso
rouge = [0]*nombre_perso
bleu = [0]*nombre_perso
#creer les objets personnages
for rang in range(nombre_perso):
# rouge[rang] = players.Player(rang, decor, projectile, skin1, randint(100, 700), 50, viemax, "red", tombe1)
rouge[rang] = players.Player(rang, decor, projectile, skin1, randint(20, 780), 0, viemax, "red", tombe1)
bleu[rang] = players.Player(rang, decor, projectile, skin2, randint(20, 780), 0, viemax, "blue", tombe2)
return fond, decor, rouge, bleu, vies1, vies2
def mapMAJ(nombre_perso, rouge, bleu, ximpact, yimpact, arme, fenetre):
#jouer son explosion
sonexplosion.play()
if arme == 1:
rayon = 45
fenetre.blit(expl1,(ximpact-45,yimpact-45))
if arme == 2:
rayon = 65
fenetre.blit(expl2,(ximpact-65,yimpact-65))
pygame.display.flip()
mapmaj = Image.open("image/mapcopie.png")
draw = ImageDraw.Draw(mapmaj)
#cercle transparent
draw.ellipse((ximpact-rayon, yimpact-rayon, ximpact+rayon, yimpact+rayon), fill=(0, 0, 0, 0))
mapmaj.save("image/mapcopie.png", 'PNG')
#mettre a jour la map
decor = pygame.sprite.Sprite()
decor.image = pygame.image.load("image/mapcopie.png").convert_alpha()
decor.rect = decor.image.get_rect()
decor.rect.topleft = 0,0
decor.mask = pygame.mask.from_surface(decor.image)
explosion = pygame.Rect(ximpact-rayon, yimpact-rayon, 2*rayon, 2*rayon)
for rang in range(nombre_perso):
if explosion.collidepoint(rouge[rang].rect.x,rouge[rang].rect.y):
if rouge[rang].vivant:
rouge[rang].vie -= rayon #retirer vie au perso
if rouge[rang].vie <= 0:
rouge[rang].vie = 0
if explosion.collidepoint(bleu[rang].rect.x,bleu[rang].rect.y):
if bleu[rang].vivant:
bleu[rang].vie -= rayon #retirer vie au perso
if bleu[rang].vie <= 0:
bleu[rang].vie = 0
for rang in range(nombre_perso):
rouge[rang].decor = decor
bleu[rang].decor = decor
return decor