diff --git a/assets/Horse.png b/assets/Horse.png new file mode 100644 index 0000000..d0c3d3e Binary files /dev/null and b/assets/Horse.png differ diff --git a/assets/Horse.xcf b/assets/Horse.xcf new file mode 100644 index 0000000..d57bc4a Binary files /dev/null and b/assets/Horse.xcf differ diff --git a/assets/Horse2.png b/assets/Horse2.png new file mode 100644 index 0000000..9ac19e0 Binary files /dev/null and b/assets/Horse2.png differ diff --git a/assets/blood.png b/assets/blood.png new file mode 100644 index 0000000..a059834 Binary files /dev/null and b/assets/blood.png differ diff --git a/assets/blood.xcf b/assets/blood.xcf new file mode 100644 index 0000000..15d8468 Binary files /dev/null and b/assets/blood.xcf differ diff --git a/assets/gameover.png b/assets/gameover.png new file mode 100644 index 0000000..4624aaa Binary files /dev/null and b/assets/gameover.png differ diff --git a/assets/gameover.xcf b/assets/gameover.xcf new file mode 100644 index 0000000..40a6e48 Binary files /dev/null and b/assets/gameover.xcf differ diff --git a/assets/pnj/knight.png b/assets/pnj/knight.png new file mode 100644 index 0000000..42476cc Binary files /dev/null and b/assets/pnj/knight.png differ diff --git a/game.py b/game.py index 8a4e7cd..b7ddee7 100644 --- a/game.py +++ b/game.py @@ -77,11 +77,14 @@ class Pnj: self.direction = direction self.objectif = objectif self.speed = speed + self.alive = True def avance(self): ''' VĂ©rifie que l'objectif n'est pas atteint et avance le pnj dans la direction ''' + if not self.alive: + return if self.check_objectif(): return else: @@ -127,6 +130,15 @@ class Pnj: self.objectif = new_objectif return True return False + + def kill(self): + self.sprite = pygame.transform.scale_by(pygame.image.load("assets/blood.png"), 3.0) + self.alive = False + player.killcounter += 1 + if player.killcounter == game.pnj_number: + village.final_boss() + elif player.killcounter >= game.pnj_number+8: + game.game_over() class Village: def __init__(self, nb_pnj: int) -> None: @@ -148,6 +160,19 @@ class Village: for p in self.liste_pnj: village_sprites.append((p.x, p.y, p.sprite)) return village_sprites + + def check_kill(self)->None: + player_rect = pygame.Rect(player.x-50, player.y-50, 100, 100) + for p in self.liste_pnj: + if p.alive and player_rect.collidepoint(p.x, p.y): + p.kill() + + def final_boss(self)->None: + for i in ("A", "B", "C", "D", "E", "F", "G", "H"): + start_waypoint = Waypoint(i) + objective_waypoint = start_waypoint.get_new_connected() + self.liste_pnj.append(Pnj(start_waypoint.x, start_waypoint.y, "assets/pnj/knight.png", start_waypoint.get_direction(start_waypoint, objective_waypoint), objective_waypoint, 10)) + class Player: def __init__(self)-> None: @@ -156,6 +181,7 @@ class Player: self.mov_speed = 8 self.rotate_speed = 5 self.angle = 90 + self.killcounter = 0 def rotate(self, angle: math.degrees)-> None: self.angle += angle*self.rotate_speed @@ -170,17 +196,19 @@ class Player: self.y = new_y elif(game.test_collision(pygame.Rect(new_x-50, self.y-50, 100, 100), game.collisions) == False): self.x = new_x + village.check_kill() class Game: def __init__(self): self.is_paused = False + self.pnj_number = 5 pygame.font.init() self.font = pygame.font.SysFont('Comic Sans MS', 30) self.load_sprites() self.load_collisions() def load_sprites(self): - self.perso_sprite = pygame.image.load("assets/perso_sprite.png") + self.perso_sprite = pygame.image.load("assets/Horse2.png") self.map_sprite = pygame.image.load("assets/map3.png") def load_collisions(self): @@ -200,9 +228,11 @@ class Game: angle_surface = self.font.render("angle: "+str(player.angle), False, (0, 0, 0)) x_surface = self.font.render("x: "+str(player.x), False, (0, 0, 0)) y_surface = self.font.render("y: "+str(player.y), False, (0, 0, 0)) + kill_surface = self.font.render("kills: "+str(player.killcounter), False, (0, 0, 0)) screen.blit(angle_surface, (0,0)) screen.blit(x_surface, (0,30)) screen.blit(y_surface, (0,60)) + screen.blit(kill_surface, (0,90)) #pygame.draw.rect(screen, "blue",pygame.Rect(player.x-50, player.y-50, 100, 100)) def check_input(self): @@ -218,7 +248,7 @@ class Game: def draw_player(self): #pygame.draw.rect(screen, "red", pygame.Rect(player.x, player.y, 50, 50)) - img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 0.2) + img = pygame.transform.rotozoom(self.perso_sprite, -player.angle-90, 1) screen.blit(img, (540-img.get_rect().centerx, 360-img.get_rect().centery)) def draw_village(self): @@ -227,7 +257,7 @@ class Game: def display_all(self): # fill the screen with a color to wipe away anything from last frame - screen.fill("purple") + screen.fill("gray") screen.blit(self.map_sprite, (540-player.x, 360-player.y)) self.draw_village() @@ -239,10 +269,19 @@ class Game: # flip() the display to put your work on screen pygame.display.flip() + def game_over(self)->None: + screen.blit(pygame.image.load("assets/gameover.png"), (0,0)) + # flip() the display to put your work on screen + pygame.display.flip() + while True: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + exit() + player = Player() game = Game() #pnj = Pnj(800, 900, "assets/MiniPeasant.png", "south", Waypoint("H"), 3) -village = Village(20) +village = Village(game.pnj_number) while running: # poll for events