Finish
This commit is contained in:
parent
344ed9d5f6
commit
6dbf733262
|
@ -5,8 +5,9 @@ lancement du jeu et le temps depuis la dernière frame.
|
|||
|
||||
|
||||
from time import time
|
||||
from typing import Callable
|
||||
from engine import GlobalPlugin, KeepAlive
|
||||
from engine.ecs import World
|
||||
from engine.ecs import Entity, World
|
||||
|
||||
|
||||
class GlobalTime(KeepAlive, float):
|
||||
|
@ -34,6 +35,16 @@ def __initialize(world: World):
|
|||
world.set(GlobalTime(time()), Time(0.0))
|
||||
|
||||
|
||||
class TimedEvent:
|
||||
"""
|
||||
Composant permettant d'executer un callback après un certain temps.
|
||||
"""
|
||||
|
||||
def __init__(self, timer: float, callback: Callable[[World, Entity], object]):
|
||||
self.timer = timer
|
||||
self.callback = callback
|
||||
|
||||
|
||||
def __update(world: World):
|
||||
"""
|
||||
Met à jour les ressources de temps.
|
||||
|
@ -43,6 +54,14 @@ def __update(world: World):
|
|||
world[GlobalTime] = now
|
||||
world[Time] += delta
|
||||
|
||||
# On met à jour les `TimedEvent`
|
||||
for entity in world.query(TimedEvent):
|
||||
event = entity[TimedEvent]
|
||||
event.timer -= delta
|
||||
if event.timer <= 0:
|
||||
del entity[TimedEvent]
|
||||
event.callback(world, entity)
|
||||
|
||||
|
||||
PLUGIN = GlobalPlugin(
|
||||
[__initialize],
|
||||
|
|
|
@ -3,7 +3,7 @@ Definit un plugin qui crée un texte avec les touches frappées
|
|||
"""
|
||||
|
||||
from engine import Scene, World
|
||||
from plugins.inputs import Held, Pressed
|
||||
from plugins.inputs import Pressed
|
||||
from plugins.render import Text
|
||||
from plugins.sound import Sound
|
||||
|
||||
|
@ -26,7 +26,6 @@ def __update(world: World):
|
|||
Met a jour les entitées contenant le composant Typing
|
||||
"""
|
||||
pressed = world[Pressed]
|
||||
held = world[Held]
|
||||
for entity in world.query(Writing, Text):
|
||||
writing = entity[Writing]
|
||||
for key in pressed:
|
||||
|
|
|
@ -12,7 +12,7 @@ from plugins.click import Clickable
|
|||
from plugins.hover import HoveredTexture
|
||||
from plugins.render import SpriteBundle
|
||||
from plugins.timing import Time
|
||||
from scenes import game, send_to_server
|
||||
from scenes import game
|
||||
|
||||
|
||||
def __create_button(world: World, i: int, name: str):
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
from plugins import writing
|
||||
from engine import Plugin
|
||||
from engine import CurrentScene, Plugin
|
||||
from engine.ecs import Entity, World
|
||||
from engine.math import Vec2
|
||||
from plugins import render
|
||||
from plugins.click import Clickable
|
||||
from plugins.hover import HoveredTexture
|
||||
from plugins.render import SpriteBundle, Text, TextBundle
|
||||
from plugins.timing import TimedEvent
|
||||
from plugins.writing import Writing
|
||||
import requests as rq
|
||||
from scenes import game
|
||||
from scenes import game, thanks
|
||||
|
||||
IP = "pong.cocosol.fr"
|
||||
|
||||
|
@ -21,6 +22,12 @@ def new_score(world: World, e: Entity):
|
|||
post = {"name": name[Text], "score": world[game.Player1Score]}
|
||||
print(post)
|
||||
rq.post(f"https://{IP}/new_score", post)
|
||||
world.new_entity().set(
|
||||
TimedEvent(
|
||||
1,
|
||||
lambda world, entity: world.set(CurrentScene(thanks.THANKS)),
|
||||
)
|
||||
)
|
||||
except:
|
||||
print("Error with the serveur")
|
||||
|
||||
|
@ -51,7 +58,7 @@ def __spawn_elements(world: World):
|
|||
"...",
|
||||
0,
|
||||
50,
|
||||
position=Vec2(render.WIDTH / 2, 650),
|
||||
position=Vec2(render.WIDTH / 2, 475),
|
||||
origin=Vec2(0.5),
|
||||
),
|
||||
Writing(
|
||||
|
@ -64,7 +71,7 @@ def __spawn_elements(world: World):
|
|||
world.new_entity().set(
|
||||
SpriteBundle(
|
||||
f"button_one_player.png",
|
||||
position=Vec2(render.WIDTH / 2, render.HEIGHT / 2),
|
||||
position=Vec2(render.WIDTH / 2, 600),
|
||||
order=1,
|
||||
origin=Vec2(0.5),
|
||||
),
|
||||
|
|
37
src/scenes/thanks.py
Normal file
37
src/scenes/thanks.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
from engine import CurrentScene, Scene
|
||||
from engine.ecs import World
|
||||
from engine.math import Vec2
|
||||
from plugins import render
|
||||
from plugins.render import SpriteBundle, TextBundle
|
||||
from plugins.timing import TimedEvent
|
||||
from scenes import menu
|
||||
|
||||
|
||||
def __spawn_elements(world: World):
|
||||
world.new_entity().set(SpriteBundle("background.jpg", -5))
|
||||
world.new_entity().set(
|
||||
TextBundle(
|
||||
"Merci,",
|
||||
0,
|
||||
150,
|
||||
position=Vec2(render.WIDTH / 2, render.HEIGHT / 2 - 75),
|
||||
origin=Vec2(0.5),
|
||||
),
|
||||
TimedEvent(3, lambda world, entity: world.set(CurrentScene(menu.MENU))),
|
||||
)
|
||||
world.new_entity().set(
|
||||
TextBundle(
|
||||
"Votre score a bien été envoyé !",
|
||||
0,
|
||||
100,
|
||||
position=Vec2(render.WIDTH / 2, render.HEIGHT / 2 + 75),
|
||||
origin=Vec2(0.5),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
THANKS = Scene(
|
||||
[__spawn_elements],
|
||||
[],
|
||||
[],
|
||||
)
|
Loading…
Reference in a new issue