On ne peut plus ne pas sauvegarder (#35)

Reviewed-on: #35
Reviewed-by: Corentin <solois.corentin@gmail.com>
Co-authored-by: Tipragot <contact@tipragot.fr>
Co-committed-by: Tipragot <contact@tipragot.fr>
This commit is contained in:
Tipragot 2024-01-07 13:39:54 +00:00 committed by Corentin
parent 647e053cae
commit c090e5fc67
9 changed files with 16 additions and 91 deletions

View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View file

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

View file

@ -4,12 +4,13 @@ from engine.math import Vec2
from plugins import render from plugins import render
from plugins.click import Clickable from plugins.click import Clickable
from plugins.hover import HoveredTexture from plugins.hover import HoveredTexture
from plugins.inputs import Pressed
from plugins.render import ( from plugins.render import (
SpriteBundle, SpriteBundle,
TextBundle, TextBundle,
) )
from plugins.sound import Sound from plugins.sound import Sound
from scenes import game, send_to_server, try_again from scenes import game, send_to_server
def __spawn_elements(world: World): def __spawn_elements(world: World):
@ -36,21 +37,17 @@ def __spawn_elements(world: World):
origin=Vec2(0.5), origin=Vec2(0.5),
) )
) )
button_name = ["yes", "no"] __create_button(world, "continue")
for i, name in enumerate(button_name):
__create_button(world, i, name)
def __create_button(world: World, i: int, name: str): def __create_button(world: World, name: str):
""" """
Ajoute un bouton au monde. Ajoute un bouton au monde.
""" """
if i == 0:
i = -1
world.new_entity().set( world.new_entity().set(
SpriteBundle( SpriteBundle(
f"button_{name}.png", f"button_{name}.png",
position=Vec2(render.WIDTH / 2 + 300 * i, 800), position=Vec2(render.WIDTH / 2, 800),
order=1, order=1,
origin=Vec2(0.5), origin=Vec2(0.5),
), ),
@ -66,18 +63,21 @@ def __on_click_butons(world: World, _entity: Entity, name: str):
""" """
Fonction qui s'execute quand on clique sur un bouton. Fonction qui s'execute quand on clique sur un bouton.
""" """
match name:
case "yes":
world[CurrentScene] = send_to_server.SEND world[CurrentScene] = send_to_server.SEND
case "no": world.new_entity().set(KeepAlive(), Sound("click.wav"))
world[CurrentScene] = try_again.TRY_AGAIN
case _:
pass def __enter_to_submit(world: World):
"""
Envoit le score losre que l'utilisateur appuie sur entrée.
"""
if "return" in world[Pressed]:
world[CurrentScene] = send_to_server.SEND
world.new_entity().set(KeepAlive(), Sound("click.wav")) world.new_entity().set(KeepAlive(), Sound("click.wav"))
GAME_OVER = Scene( GAME_OVER = Scene(
[__spawn_elements], [__spawn_elements],
[], [__enter_to_submit],
[], [],
) )

View file

@ -1,75 +0,0 @@
"""
La scène du menu principal du jeu.
Dans cette scène nous pouvons choisir le mode de jeu.
"""
from plugins.sound import Sound
from engine import CurrentScene, KeepAlive, Scene
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, TextBundle
from scenes import game, menu
def __create_button(world: World, i: int, name: str):
"""
Ajoute un bouton au monde.
"""
if i == 0:
i = -1
world.new_entity().set(
SpriteBundle(
f"button_{name}.png",
position=Vec2(render.WIDTH / 2 + 300 * i, 800),
order=1,
origin=Vec2(0.5),
),
HoveredTexture(
f"button_{name}.png",
f"button_{name}_hover.png",
),
Clickable(lambda world, entity: __on_click_butons(world, entity, name)),
)
def __on_click_butons(world: World, _entity: Entity, name: str):
"""
Fonction qui s'execute quand on clique sur un bouton.
"""
match name:
case "yes":
world[CurrentScene] = menu.MENU
case "no":
world[CurrentScene] = game.ONE_PLAYER
case _:
pass
world.new_entity().set(KeepAlive(), Sound("click.wav"))
def __spawn_elements(world: World):
"""
Ajoute les éléments du menu dans le monde.
"""
world.new_entity().set(SpriteBundle("background.png", -5))
world.new_entity().set(
TextBundle(
"Voulez vous changer de mode de jeu ?",
0,
position=Vec2(render.WIDTH / 2, 350),
origin=Vec2(0.5),
),
)
scenes_name = ["yes", "no"]
for i, name in enumerate(scenes_name):
__create_button(world, i, name)
TRY_AGAIN = Scene(
[__spawn_elements],
[],
[],
)