-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.py
206 lines (164 loc) · 6.38 KB
/
game.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import pygame
from player import Player
from monster import Monster
from boss import Boss
from pygame.locals import *
import Classes.Level
from Classes.Level import Level
import random
class Game :
def __init__(self, level, score):
self.is_playing = False
self.menu = True
self.game_over = False
self.game_wined = False
self.tt_players = pygame.sprite.Group()
self.level = level
self.player = Player(self)
self.tt_players.add(self.player)
self.tt_monsters = pygame.sprite.Group()
self.boss = Boss(self)
self.tt_boss = pygame.sprite.Group()
self.banane_list = pygame.sprite.Group()
self.orange_list = pygame.sprite.Group()
self.fraise_list = pygame.sprite.Group()
self.date_list = pygame.sprite.Group()
self.pasteque_list = pygame.sprite.Group()
self.all_walls = pygame.sprite.Group()
self.score = score
self.all_decors = pygame.sprite.Group()
self.pressed = {}
self.fruits_graille = []
self.nb_fruits_graille = 0
self.level = level
self.nb_monstres = 0
if self.level.nblvl == 1:
self.nb_monstres = 1
self.spawn_monster()
self.nb_monstres = 2
self.spawn_monster()
self.nb_monstres = 3
self.spawn_monster()
elif self.level.nblvl == 2:
self.nb_monstres = 1
self.spawn_monster()
self.nb_monstres = 2
self.spawn_monster()
self.nb_monstres = 3
self.spawn_monster()
self.nb_monstres = 4
self.spawn_monster()
elif self.level.nblvl == 3 :
self.nb_monstres = 1
self.spawn_monster()
self.nb_monstres = 2
self.spawn_monster()
self.nb_monstres = 3
self.spawn_monster()
self.nb_monstres = 4
self.spawn_monster()
self.nb_monstres = 5
self.spawn_monster()
elif self.level.nblvl == 4 :
self.spawn_boss()
#self.levelnumber = level.getNbLvl()
self.spawn_wall()
self.spawn_fruits()
self.spawn_decors()
def check_collisionDpl(self, sprite1, sprite2):
if not pygame.sprite.collide_rect(sprite1, sprite2):
return True
def check_collisionWallX(self, sprite, group):
#r = pygame.Rect(sprite.rect.width, sprite.rect.height)
for i in group:
if (i.rect.top == sprite.rect.bottom):
return True
else :
return self.check_allCollisions(sprite, group)
return False
def check_allCollisions(self, sprite, group):
return pygame.sprite.spritecollideany(sprite, group)
def check_collisionFruit(self, sprite):
if self.check_collisionBanane(sprite, self.banane_list) :
self.fruits_graille.append("banane")
self.nb_fruits_graille += 1
return True
elif self.check_collisionOrange(sprite, self.orange_list) :
self.fruits_graille.append("orange")
self.nb_fruits_graille += 1
return True
elif self.check_collisionFraise(sprite, self.fraise_list) :
self.fruits_graille.append("fraise")
self.nb_fruits_graille += 1
return True
elif self.check_collisionDate(sprite, self.date_list) :
self.fruits_graille.append("date")
self.nb_fruits_graille += 1
return True
elif self.check_collisionPasteque(sprite, self.pasteque_list) :
self.fruits_graille.append("pasteque")
self.nb_fruits_graille += 1
return True
else :
return False
def check_collisionOrange(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, True, pygame.sprite.collide_mask)
def check_collisionBanane(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, True, pygame.sprite.collide_mask)
def check_collisionFraise(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, True, pygame.sprite.collide_mask)
def check_collisionDate(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, True, pygame.sprite.collide_mask)
def check_collisionPasteque(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, True, pygame.sprite.collide_mask)
def check_collisionMonstre(self, sprite, group):
return pygame.sprite.spritecollide(sprite, group, False, pygame.sprite.collide_mask)
def spawn_monster(self):
monster=Monster(self)
self.tt_monsters.add(monster)
def spawn_boss(self):
boss=Boss(self)
self.tt_boss.add(boss)
def spawn_wall(self):
for w in self.level.wall_list :
self.all_walls.add(w)
def spawn_fruits(self):
for f in self.level.orange_list :
self.orange_list.add(f)
for f in self.level.pasteque_list :
self.pasteque_list.add(f)
for f in self.level.fraise_list :
self.fraise_list.add(f)
for f in self.level.banane_list :
self.banane_list.add(f)
for f in self.level.date_list :
self.date_list.add(f)
def add_score(self, point):
self.score +=point
def spawn_decors(self):
for x in self.level.decor_collision_list:
self.all_decors.add(x)
def drawScore(self, surface):
if self.level.nblvl == 0 :
coul = (0,0,0)
else :
coul = (255,255,255)
self.font = pygame.font.SysFont("monospace", 22)
self.score_text = self.font.render(f"Score : {self.score}",1,coul)
surface.blit(self.score_text, (20,20))
def drawLives(self, surface, nb):
if self.level.nblvl == 0 :
coul = (0,0,0)
else :
coul = (255,255,255)
self.font = pygame.font.SysFont("monospace", 22)
self.morts_txt = self.font.render(f"Morts : {nb}",1,coul)
surface.blit(self.morts_txt, (20,40))
def updatePerso(self, a, h, s):
self.player.attack = a
self.player.health = h
self.player.max_health = h
self.player.velocity = s
def bossDead(self):
for i in self.tt_boss :
return i.health <= 0