On ne peut plus ne pas sauvegarder #35
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 5.7 KiB After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 5.5 KiB |
Before Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 8.2 KiB |
Before Width: | Height: | Size: 8.7 KiB |
Before Width: | Height: | Size: 8.3 KiB |
|
@ -4,12 +4,13 @@ from engine.math import Vec2
|
|||
from plugins import render
|
||||
from plugins.click import Clickable
|
||||
from plugins.hover import HoveredTexture
|
||||
from plugins.inputs import Pressed
|
||||
from plugins.render import (
|
||||
SpriteBundle,
|
||||
TextBundle,
|
||||
)
|
||||
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):
|
||||
|
@ -36,21 +37,17 @@ def __spawn_elements(world: World):
|
|||
origin=Vec2(0.5),
|
||||
)
|
||||
)
|
||||
button_name = ["yes", "no"]
|
||||
for i, name in enumerate(button_name):
|
||||
__create_button(world, i, name)
|
||||
__create_button(world, "continue")
|
||||
|
||||
|
||||
def __create_button(world: World, i: int, name: str):
|
||||
def __create_button(world: World, 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),
|
||||
position=Vec2(render.WIDTH / 2, 800),
|
||||
order=1,
|
||||
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.
|
||||
"""
|
||||
match name:
|
||||
case "yes":
|
||||
world[CurrentScene] = send_to_server.SEND
|
||||
case "no":
|
||||
world[CurrentScene] = try_again.TRY_AGAIN
|
||||
case _:
|
||||
pass
|
||||
world.new_entity().set(KeepAlive(), Sound("click.wav"))
|
||||
|
||||
|
||||
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"))
|
||||
|
||||
|
||||
GAME_OVER = Scene(
|
||||
[__spawn_elements],
|
||||
[],
|
||||
[__enter_to_submit],
|
||||
[],
|
||||
)
|
||||
|
|
|
@ -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],
|
||||
[],
|
||||
[],
|
||||
)
|