Merge pull request 'Ajout d'un titre et d'un icon' (#16) from windows into main
Reviewed-on: #16
This commit is contained in:
commit
3dea5b126a
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue