Ajout du rendu du boss fight et début de gestion

This commit is contained in:
Yannis 2023-12-28 22:38:35 +01:00
parent ed0dad0742
commit 2a8342f5a2
8 changed files with 65 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

View file

@ -3,10 +3,15 @@ from src.engine.enums import GameState
class BossFightManager: class BossFightManager:
"""Classe permettant de gérer les combats de boss."""
def __init__(self, core: "engine.Engine"): def __init__(self, core: "engine.Engine"):
self.boss_name = "none" self.boss_name = "none"
self.engine = core self.engine = core
self.current_boss_animation = "none"
self.current_player_animation = "none"
def update(self): def update(self):
"""Met à jour le combat de boss."""
if self.engine.game_state == GameState.BOSS_FIGHT: if self.engine.game_state == GameState.BOSS_FIGHT:
pass pass

View file

@ -19,6 +19,10 @@ class Renderer:
self.animations: dict[str: Anim] = {} self.animations: dict[str: Anim] = {}
self.boss_fight_animations: dict[str: Anim] = {} self.boss_fight_animations: dict[str: Anim] = {}
# Variables utilisées pour les combats de boss
self.boss_fight_boss_animations: dict[str: Anim] = {}
self.boss_fight_player_animations: dict[str: Anim] = {}
self.boss_fight_GUI_container = None
def load_tile_set(self, file_path: str, tile_size: int): def load_tile_set(self, file_path: str, tile_size: int):
"""Charge le jeu de tuiles en utilisant le fichier donné et la taille donnée.""" """Charge le jeu de tuiles en utilisant le fichier donné et la taille donnée."""
@ -60,7 +64,9 @@ class Renderer:
self.window.blit(gui_surface, (0, 0)) self.window.blit(gui_surface, (0, 0))
elif self.engine.game_state == GameState.BOSS_FIGHT: elif self.engine.game_state == GameState.BOSS_FIGHT:
self.window.fill((255, 0, 0)) self.window.fill((255, 230, 230))
self.render_boss_fight_scene(delta)
self.render_boss_fight_gui()
# Apres avoir tout rendu, on met à jour l'écran # Apres avoir tout rendu, on met à jour l'écran
display.update() display.update()
@ -69,9 +75,43 @@ class Renderer:
"""Enregistre une animation.""" """Enregistre une animation."""
self.animations[name] = animation self.animations[name] = animation
def register_boss_fight_animation(self, animation: Anim, name: str): def register_boss_fight_boss_animation(self, animation: Anim, name: str):
"""Enregistre une animation de combat de boss.""" """Ajoute une animation pour le boss lors d'un combat de boss."""
self.boss_fight_animations[name] = animation self.boss_fight_boss_animations[name] = animation
def register_boss_fight_player_animation(self, animation: Anim, name: str):
"""Ajoute une animation pour le joueur lors d'un combat de boss."""
self.boss_fight_player_animations[name] = animation
def render_boss_fight_scene(self, delta: float):
"""Rend les sprites du joueur et du boss lors d'un combat de boss."""
# On récupère l'image de l'animation du boss
boss_animation: Anim = self.boss_fight_boss_animations[self.engine.boss_fight_manager.current_boss_animation]
frame = boss_animation.get_frame(delta)
# On redimensionne l'image
frame = transform.scale(frame, (display.get_window_size()[0] / 5, display.get_window_size()[0] / 5))
# On colle le boss à droite de la fenêtre
self.window.blit(frame, (display.get_window_size()[0]-frame.get_width()-display.get_window_size()[0]/20,
display.get_window_size()[1]/4-frame.get_height()/2))
# On récupère l'image de l'animation du joueur
player_animation = self.boss_fight_player_animations[self.engine.boss_fight_manager.current_player_animation]
frame = player_animation.get_frame(delta)
# On redimensionne l'image
frame = transform.scale(frame, (display.get_window_size()[0] / 5, display.get_window_size()[0] / 5))
# On colle le joueur à gauche de la fenêtre
self.window.blit(frame, (display.get_window_size()[0]/20, display.get_window_size()[1]/4-frame.get_height()/2))
def render_boss_fight_gui(self):
"""Rend la barre d'action en bas de l'écran pendant le combat de boss."""
resized_container = transform.scale(self.boss_fight_GUI_container, (display.get_window_size()[0], self.boss_fight_GUI_container.get_height()/self.boss_fight_GUI_container.get_width()*display.get_window_size()[0]))
self.window.blit(resized_container, (0, display.get_window_size()[1]-resized_container.get_height()))
def render_entities(self, rendered_surface: surface.Surface, gui_surface: surface.Surface, delta: float): def render_entities(self, rendered_surface: surface.Surface, gui_surface: surface.Surface, delta: float):
"""Rend toutes les entités.""" """Rend toutes les entités."""

View file

@ -1,7 +1,8 @@
import random import pygame.image
from src.engine.animation import Anim from src.engine.animation import Anim
from src.engine.engine import Engine from src.engine.engine import Engine
from src.engine.enums import GameState
class Game(Engine): class Game(Engine):
@ -12,6 +13,9 @@ class Game(Engine):
self.renderer.load_tile_set("assets/textures/tiles.png", 16) self.renderer.load_tile_set("assets/textures/tiles.png", 16)
self.create_player_entity() self.create_player_entity()
self.load_boss_fight_assets()
self.game_state = GameState.NORMAL
def create_player_entity(self): def create_player_entity(self):
"""Crée une entité joueur.""" """Crée une entité joueur."""
@ -27,6 +31,17 @@ class Game(Engine):
self.camera.follow_entity(player) self.camera.follow_entity(player)
def load_boss_fight_assets(self):
"""Charge les animations de combat des combats de boss."""
player_none = Anim(1)
player_none.load_animation_from_directory("assets/textures/boss_fight/player_big/none")
self.renderer.register_boss_fight_player_animation(player_none, "none")
boss_none = Anim(1)
boss_none.load_animation_from_directory("assets/textures/boss_fight/boss_sprite/test/none")
self.renderer.register_boss_fight_boss_animation(boss_none, "none")
self.renderer.boss_fight_GUI_container = pygame.image.load("assets/textures/boss_fight/fight_actions_GUI.png")
game = Game() game = Game()
game.loop() game.loop()