Ajout d'un titre et d'un icon

This commit is contained in:
Tipragot 2023-10-26 20:08:07 +02:00
parent 95fa11b1f9
commit 47e7bb3a78
3 changed files with 12 additions and 4 deletions

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 KiB

View file

@ -4,7 +4,7 @@ Définit un plugin qui gère les évenements pygame.
from engine import *
from engine.math import Vec2
import pygame
import pygame, os
class PygamePlugin(Plugin):
@ -12,6 +12,9 @@ class PygamePlugin(Plugin):
Plugin qui gère les évenements pygame.
"""
def __init__(self, title: str = "Game") -> None:
self.title = title
@staticmethod
def _find_surface_rect() -> tuple[float, float, float, float]:
width, height = pygame.display.get_surface().get_size()
@ -26,11 +29,14 @@ class PygamePlugin(Plugin):
return rect
@staticmethod
def _initialize(world: World) -> None:
def _initialize(world: World, title: str) -> None:
"""
Initialize pygame et les ressources.
"""
pygame.init()
if os.path.exists("icon.png"):
pygame.display.set_icon(pygame.image.load("icon.png"))
pygame.display.set_caption(title)
pygame.display.set_mode((800, 600), pygame.RESIZABLE)
# Initialisation des ressources
@ -112,7 +118,9 @@ class PygamePlugin(Plugin):
Paramètres:
game: Le jeu auquel appliquer le plugin.
"""
game.add_pre_startup_tasks(self._initialize)
game.add_pre_startup_tasks(
lambda world: PygamePlugin._initialize(world, self.title)
)
game.add_pre_update_tasks(self._check_events)
game.add_post_render_tasks(self._update_display)
game.add_post_shutdown_tasks(self._terminate)

View file

@ -19,7 +19,7 @@ from random import random
# Initialisation
game = Game(TimePlugin(), PygamePlugin(), RenderPlugin())
game = Game(TimePlugin(), PygamePlugin("Guess The Number"), RenderPlugin())
# On créer une tache pour afficher des sprites