Gameplay de la recherche dans les dossiers #44
|
@ -4,13 +4,14 @@ Example de l'utilisation du moteur de jeu.
|
||||||
|
|
||||||
|
|
||||||
from engine import start_game
|
from engine import start_game
|
||||||
from scenes import menu
|
from scenes import folder_hide, menu
|
||||||
|
|
||||||
|
|
||||||
start_game(
|
start_game(
|
||||||
{
|
{
|
||||||
"menu": menu.SCENE,
|
"menu": menu.SCENE,
|
||||||
|
"folder_hide": folder_hide.SCENE,
|
||||||
},
|
},
|
||||||
"menu",
|
"folder_hide",
|
||||||
title="Guess The Number",
|
title="Guess The Number",
|
||||||
)
|
)
|
||||||
|
|
37
src/plugins/smooth.py
Normal file
37
src/plugins/smooth.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
"""
|
||||||
|
Un plugin permettant de faire des déplacements fluides des entités.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import math
|
||||||
|
from engine import Delta, Position, Scene, Vec2, World
|
||||||
|
|
||||||
|
|
||||||
|
class Target(Vec2):
|
||||||
|
"""
|
||||||
|
Composant donnant la position voulue de l'entité.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Speed(float):
|
||||||
|
"""
|
||||||
|
Composant donnant la vittesse de déplacement de l'entité.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def __update_positions(world: World):
|
||||||
|
"""
|
||||||
|
Met à jour la position des entités pour se rapprocher de la position voulue.
|
||||||
|
"""
|
||||||
|
for entity in world.query(Position, Target):
|
||||||
|
position = entity[Position]
|
||||||
|
target = entity[Target]
|
||||||
|
speed = entity[Speed] if Speed in entity else Speed(500)
|
||||||
|
blend = math.pow(0.5, world[Delta] * speed)
|
||||||
|
entity[Position] = Position(position + ((target - position) * blend))
|
||||||
|
|
||||||
|
|
||||||
|
PLUGIN = Scene(
|
||||||
|
[],
|
||||||
|
[__update_positions],
|
||||||
|
[],
|
||||||
|
)
|
53
src/scenes/folder_hide.py
Normal file
53
src/scenes/folder_hide.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
"""
|
||||||
|
Scène du jeu dans lequel on se cache de Edmond dans les dossiers.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from engine import Centered, Display, Order, Position, Scene, Texture, Vec2, World
|
||||||
|
from plugins import smooth
|
||||||
|
|
||||||
|
|
||||||
|
class FolderPosition:
|
||||||
|
"""
|
||||||
|
La position d'un dossier dans la grille.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, x: int, y: int):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
|
||||||
|
def __initialize_world(world: World):
|
||||||
|
"""
|
||||||
|
Initialise le monde de la scène.
|
||||||
|
"""
|
||||||
|
for x in range(5):
|
||||||
|
for y in range(2):
|
||||||
|
world.create_entity(
|
||||||
|
Position(0, 0),
|
||||||
|
Order(1),
|
||||||
|
Centered(),
|
||||||
|
Texture("directory.png"),
|
||||||
|
FolderPosition(x, y),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def __update_positions(world: World):
|
||||||
|
"""
|
||||||
|
Met à jour la position cible des dossiers.
|
||||||
|
"""
|
||||||
|
for entity in world.query(FolderPosition):
|
||||||
|
position = entity[FolderPosition]
|
||||||
|
first_position = Vec2(Display.WIDTH / 2 - 300, Display.HEIGHT / 2 - 50)
|
||||||
|
entity[smooth.Target] = smooth.Target(
|
||||||
|
first_position + Vec2(position.x * 150, position.y * 100)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
SCENE = (
|
||||||
|
Scene(
|
||||||
|
[__initialize_world],
|
||||||
|
[__update_positions],
|
||||||
|
[],
|
||||||
|
)
|
||||||
|
+ smooth.PLUGIN
|
||||||
|
)
|
Loading…
Reference in a new issue