ecs #58
13
src/main.py
13
src/main.py
|
@ -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)),
|
||||
)
|
||||
],
|
||||
[],
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in a new issue