Ajout du menu principal pour l'exemple
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 30 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
@ -29,6 +29,18 @@ class World:
|
|||
self._entities: dict[type[object], set[Entity]] = {}
|
||||
self.__resources: dict[type[object], object] = {}
|
||||
|
||||
def create_entity(self, *components: object) -> "Entity":
|
||||
"""
|
||||
Crée une nouvelle entité avec les composants donnés et l'ajoute au monde.
|
||||
|
||||
Paramètres:
|
||||
*components: les composants de l'entité.
|
||||
|
||||
Retourne:
|
||||
L'entité.
|
||||
"""
|
||||
return Entity(self, *components)
|
||||
|
||||
def __setitem__(self, resource_type: type[__T], resource: __T):
|
||||
if resource_type != type(resource):
|
||||
raise TypeError()
|
||||
|
|
36
src/main.py
|
@ -2,39 +2,15 @@
|
|||
Example de l'utilisation du moteur de jeu.
|
||||
"""
|
||||
|
||||
from engine import (
|
||||
Centered,
|
||||
Clickable,
|
||||
Display,
|
||||
Entity,
|
||||
Game,
|
||||
HoveredTexture,
|
||||
Order,
|
||||
Position,
|
||||
Scene,
|
||||
Texture,
|
||||
World,
|
||||
start_game,
|
||||
)
|
||||
|
||||
|
||||
def initialize_world(world: World):
|
||||
"""
|
||||
Initialise le monde.
|
||||
"""
|
||||
Entity(
|
||||
world,
|
||||
Position(Display.WIDTH / 2, Display.HEIGHT / 2),
|
||||
Order(0),
|
||||
Centered(),
|
||||
Texture("button_classique.png"),
|
||||
HoveredTexture("button_classique_hover.png"),
|
||||
Clickable(lambda w, e: w[Game].change_scene("test")),
|
||||
)
|
||||
from engine import start_game
|
||||
from scenes import menu
|
||||
|
||||
|
||||
start_game(
|
||||
{"example": Scene([initialize_world], [], []), "test": Scene([], [], [])},
|
||||
"example",
|
||||
{
|
||||
"menu": menu.SCENE,
|
||||
},
|
||||
"menu",
|
||||
title="Guess The Number",
|
||||
)
|
||||
|
|
3
src/plugins/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
Contient des plugins pour certaines features du jeu.
|
||||
"""
|
3
src/scenes/__init__.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
"""
|
||||
Contient toutes les scènes du jeu.
|
||||
"""
|
51
src/scenes/menu.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
Définis la scène du menu du jeu.
|
||||
"""
|
||||
|
||||
from engine import (
|
||||
Centered,
|
||||
Clickable,
|
||||
Display,
|
||||
Game,
|
||||
HoveredTexture,
|
||||
Order,
|
||||
Position,
|
||||
Scene,
|
||||
Text,
|
||||
TextSize,
|
||||
Texture,
|
||||
World,
|
||||
)
|
||||
|
||||
|
||||
def __initialize_world(world: World):
|
||||
"""
|
||||
Initialise le monde du menu.
|
||||
"""
|
||||
world.create_entity(Position(), Order(0), Texture("menu/background.png"))
|
||||
|
||||
world.create_entity(
|
||||
Position(Display.WIDTH / 2, 200),
|
||||
Order(1),
|
||||
Centered(),
|
||||
Text("Guess The Number"),
|
||||
TextSize(200),
|
||||
)
|
||||
|
||||
scenes_name = ["classique", "menteur", "tricheur", "histoire"]
|
||||
for i, name in enumerate(scenes_name):
|
||||
world.create_entity(
|
||||
Position(Display.WIDTH / 2, 450 + 150 * i),
|
||||
Order(1),
|
||||
Centered(),
|
||||
Texture(f"menu/button_{name}.png"),
|
||||
HoveredTexture(f"menu/button_{name}_hover.png"),
|
||||
Clickable(lambda world, entity: world[Game].change_scene(name)),
|
||||
)
|
||||
|
||||
|
||||
SCENE = Scene(
|
||||
[__initialize_world],
|
||||
[],
|
||||
[],
|
||||
)
|