ecs #58

Merged
raphael merged 70 commits from ecs into main 2023-11-03 15:29:36 +00:00
2 changed files with 20 additions and 2 deletions
Showing only changes of commit 915b122a05 - Show all commits

View file

@ -3,18 +3,27 @@ Module d'exemple de l'utilisation du moteur de jeu.
"""
from engine import Scene, start_game
from engine.ecs import World
from plugins import assets, defaults
from plugins.animation import Animation
from plugins.coroutine import Coroutine, condition, wait
from plugins.inputs import MousePosition
def super_fonction_du_turfu():
def super_fonction_du_turfu(world: World):
"""
Fonction du turfu qui s'execute sur plusieurs frames.
"""
print("LOL")
yield wait(10.0)
print("LOL 10 secondes après")
animation = Animation("animations/intro")
world.new_entity().set(animation)
print("Started animation")
yield animation.wait()
print("Animation ended")
yield condition(lambda world: world.get(MousePosition).x > 500)
print("La souris est a droite !")
@ -25,7 +34,7 @@ start_game(
Scene(
[
lambda world: world.new_entity().set(
Coroutine(super_fonction_du_turfu()),
Coroutine(super_fonction_du_turfu(world)),
)
],
[],

View file

@ -30,6 +30,13 @@ class Animation:
self.loop = loop
self.callback = callback
self.timer = 0.0
self.ended = False
def wait(self) -> Callable[[World], bool]:
"""
Utilitaire de `Coroutine` permettant d'attendre que l'animation soit finie.
"""
return lambda world: self.ended
def __update_sprite(entity: Entity, texture: pygame.Surface, assets: Assets):
@ -76,12 +83,14 @@ def __update_animations(world: World) -> None:
else:
# Sinon on supprime le composant `Animation`
del entity[Animation]
animation.ended = True
# Et on appelle la fonction de callback
animation.callback(world, entity)
else:
# Si l'animation n'est pas finie, on met à jour la texture
__update_sprite(entity, texture, assets)
animation.ended = False
PLUGIN = GlobalPlugin(