-
Notifications
You must be signed in to change notification settings - Fork 0
/
monster.py
162 lines (141 loc) · 5.49 KB
/
monster.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import pygame
import random
class Monster(pygame.sprite.Sprite):
def __init__(self, game):
super().__init__()
self.game = game
self.health = 100
self.max_health = 100
self.attack = 1
if game.level.nblvl == 1:
monst = self.image = pygame.image.load("images/oliveMs.png")
self.rect = monst.get_rect()
if game.nb_monstres == 1 :
self.rect.x = 704
self.rect.y = 130
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
elif game.nb_monstres == 2 :
self.rect.x = 192
self.rect.y = 260
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
elif game.nb_monstres == 3 :
self.rect.x = 416
self.rect.y = 606
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
elif game.level.nblvl == 2:
self.max_health = 150
self.health = self.max_health
monst = self.image = pygame.image.load("images/oignon.png")
self.rect = monst.get_rect()
if game.nb_monstres == 1 :
self.rect.x = 640
self.rect.y = 50
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 2 :
self.rect.x = 576
self.rect.y = 250
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 3 :
self.rect.x = 64
self.rect.y = 310
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 4 :
self.rect.x = 512
self.rect.y = 600
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
elif game.level.nblvl == 3:
self.max_health = 200
self.health = self.max_health
monst = self.image = pygame.image.load("images/concombre.png")
self.rect = monst.get_rect()
if game.nb_monstres == 1 :
self.rect.x = 960
self.rect.y = 35
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 2 :
self.rect.x = 160
self.rect.y = 65
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 3 :
self.rect.x = 180
self.rect.y = 455
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 4 :
self.rect.x = 480
self.rect.y = 650
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
if game.nb_monstres == 5 :
self.rect.x = 1000
self.rect.y = 390
self.xg = (self.rect.x)-100
self.xd = self.rect.x
self.count = 1
self.velocity = 2
def damage(self, amount):
#infliger les degats
self.health -= amount
#verifier si ses pv <= 0
if self.health <= 0:
if self.game.level.nblvl == 1:
self.game.add_score(20)
elif self.game.level.nblvl == 2:
self.game.add_score(30)
elif self.game.level.nblvl == 3:
self.game.add_score(40)
#Supprimer le monstre
self.game.tt_monsters.remove(self) #fais gaffe ça supprime tous les monstres
#ajout du score
def update_health_bar(self, surface):
#couleur de la jauge (vert)
bar_color = (111, 210, 46)
#couleur de l'arriere plan de la jauge
back_bar_color = (60,63,60)
#definir la position de note jauge de vie
#ainsi que sa largeur et son epaisseur
bar_position = [self.rect.x - 15, self.rect.y, self.health ,5]
#definir la position de l'arriere plan
#de la jauge de vie
back_bar_position = [self.rect.x - 15, self.rect.y, self.max_health ,5]
#dessiner notre barre de vie
pygame.draw.rect(surface, back_bar_color, back_bar_position)
pygame.draw.rect(surface,bar_color, bar_position)
def deplaM(self):
if self.rect.x == self.xd:
self.count *= -1
if self.rect.x == self.xg:
self.count *= -1
if self.count > 0 :
if self.rect.x < self.xd:
if not self.game.check_collisionMonstre(self,self.game.tt_players):
self.rect.x += self.velocity
#si le monstre est en collision avec le joueur il inflige des degats
else:
self.game.player.damage(self.attack)
if self.count < 0 :
if self.rect.x > self.xg:
if not self.game.check_collisionMonstre(self,self.game.tt_players):
self.rect.x -= self.velocity
else:
self.game.player.damage(self.attack)