Gameplay de la recherche dans les dossiers #44
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
|
@ -3,8 +3,11 @@ Scène du jeu dans lequel on se cache de Edmond dans les dossiers.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
import random
|
||||||
from engine import (
|
from engine import (
|
||||||
|
Animation,
|
||||||
Centered,
|
Centered,
|
||||||
|
Delta,
|
||||||
Display,
|
Display,
|
||||||
Entity,
|
Entity,
|
||||||
Hovered,
|
Hovered,
|
||||||
|
@ -21,10 +24,10 @@ from engine import (
|
||||||
from plugins import smooth
|
from plugins import smooth
|
||||||
|
|
||||||
|
|
||||||
__LINES = 3
|
LINES = 3
|
||||||
__COLUMNS = 5
|
COLUMNS = 5
|
||||||
__WAITING_SPACING = 150
|
WAITING_SPACING = 200
|
||||||
__SEARCHING_SPACING = 200
|
SEARCHING_SPACING = 200
|
||||||
|
|
||||||
|
|
||||||
class State(Enum):
|
class State(Enum):
|
||||||
|
@ -32,7 +35,7 @@ class State(Enum):
|
||||||
Etat de la scène.
|
Etat de la scène.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
WAITING = 0
|
MOVING = 0
|
||||||
SEARCHING = 1
|
SEARCHING = 1
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +49,18 @@ class SelectedDirectory:
|
||||||
self.position = start_position
|
self.position = start_position
|
||||||
|
|
||||||
|
|
||||||
|
class AttackTimer(float):
|
||||||
|
"""
|
||||||
|
Ressource qui stoque un timer pour l'attaque.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class AttackSpeed(float):
|
||||||
|
"""
|
||||||
|
Ressource qui dit le temps de l'attaque.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DirectoryPosition:
|
class DirectoryPosition:
|
||||||
"""
|
"""
|
||||||
La position d'un dossier dans la grille.
|
La position d'un dossier dans la grille.
|
||||||
|
@ -60,6 +75,21 @@ class DirectoryPosition:
|
||||||
return self.x == value.x and self.y == value.y
|
return self.x == value.x and self.y == value.y
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def screen_position(self, state: State) -> Vec2:
|
||||||
|
"""
|
||||||
|
Calcule la position de l'entité sur l'ecran.
|
||||||
|
"""
|
||||||
|
size = Vec2(WAITING_SPACING if state == State.MOVING else SEARCHING_SPACING)
|
||||||
|
offset = -(size * Vec2(COLUMNS - 1, LINES - 1) / 2)
|
||||||
|
first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset
|
||||||
|
return first_position + Vec2(self.x, self.y) * size
|
||||||
|
|
||||||
|
|
||||||
|
class AttackPoint(DirectoryPosition):
|
||||||
|
"""
|
||||||
|
Composant qui marque un point d'attaque.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class DirectoryName:
|
class DirectoryName:
|
||||||
"""
|
"""
|
||||||
|
@ -70,11 +100,19 @@ class DirectoryName:
|
||||||
self.entity = entity
|
self.entity = entity
|
||||||
|
|
||||||
|
|
||||||
|
class UserDirectory:
|
||||||
|
"""
|
||||||
|
Composant qui marque le dossier que l'utilisateur doit protéger.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def __initialize_world(world: World):
|
def __initialize_world(world: World):
|
||||||
"""
|
"""
|
||||||
Initialise le monde de la scène.
|
Initialise le monde de la scène.
|
||||||
"""
|
"""
|
||||||
world[State] = State.WAITING
|
world[State] = State.MOVING
|
||||||
|
world[AttackTimer] = AttackTimer(0.0)
|
||||||
|
world[AttackSpeed] = AttackSpeed(5.0)
|
||||||
names = [
|
names = [
|
||||||
"Classique",
|
"Classique",
|
||||||
"Menteur",
|
"Menteur",
|
||||||
|
@ -83,7 +121,7 @@ def __initialize_world(world: World):
|
||||||
"Je t'aime",
|
"Je t'aime",
|
||||||
"Hello",
|
"Hello",
|
||||||
"Cheval",
|
"Cheval",
|
||||||
"La Mort",
|
"Defender",
|
||||||
"Dansons",
|
"Dansons",
|
||||||
"Secrets",
|
"Secrets",
|
||||||
"Edmond",
|
"Edmond",
|
||||||
|
@ -92,17 +130,20 @@ def __initialize_world(world: World):
|
||||||
"Films",
|
"Films",
|
||||||
"Cinéma",
|
"Cinéma",
|
||||||
]
|
]
|
||||||
for y in range(__LINES):
|
for y in range(LINES):
|
||||||
for x in range(__COLUMNS):
|
for x in range(COLUMNS):
|
||||||
entity = world.create_entity(
|
entity = world.create_entity(
|
||||||
Position(0, 0),
|
Position(0, 0),
|
||||||
Order(1),
|
Order(1),
|
||||||
Centered(),
|
Centered(),
|
||||||
Texture("directory.png"),
|
Texture("directory.png"),
|
||||||
# HoveredTexture("directory_hover.png"),
|
|
||||||
DirectoryPosition(x, y),
|
DirectoryPosition(x, y),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if x == 2 and y == 1:
|
||||||
|
entity[UserDirectory] = UserDirectory()
|
||||||
|
entity[Texture] = Texture("user_directory.png")
|
||||||
|
|
||||||
world.create_entity(
|
world.create_entity(
|
||||||
Position(0, 0),
|
Position(0, 0),
|
||||||
Order(1),
|
Order(1),
|
||||||
|
@ -113,10 +154,51 @@ def __initialize_world(world: World):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def __attacks(world: World):
|
||||||
|
"""
|
||||||
|
Déclenche les attaques de Edmond.
|
||||||
|
"""
|
||||||
|
world[AttackTimer] = AttackTimer(world[AttackTimer] + world[Delta])
|
||||||
|
timer = world[AttackTimer]
|
||||||
|
if timer >= world[AttackSpeed] and world[State] == State.MOVING:
|
||||||
|
world[State] = State.SEARCHING
|
||||||
|
for entity in world.query(AttackPoint):
|
||||||
|
position = entity[AttackPoint]
|
||||||
|
for directory_entity in world.query(DirectoryPosition):
|
||||||
|
if directory_entity[DirectoryPosition] == position:
|
||||||
|
directory_entity[Animation] = Animation("search_directory")
|
||||||
|
del entity[AttackPoint]
|
||||||
|
del entity[Position]
|
||||||
|
del entity[Order]
|
||||||
|
del entity[Centered]
|
||||||
|
del entity[Texture]
|
||||||
|
elif timer >= world[AttackSpeed] + 5 and world[State] == State.SEARCHING:
|
||||||
|
world[State] = State.MOVING
|
||||||
|
for _ in range(10):
|
||||||
|
position = AttackPoint(
|
||||||
|
random.randint(0, COLUMNS - 1),
|
||||||
|
random.randint(0, LINES - 1),
|
||||||
|
)
|
||||||
|
world.create_entity(
|
||||||
|
position,
|
||||||
|
Position(position.screen_position(State.MOVING)),
|
||||||
|
Order(50),
|
||||||
|
Centered(),
|
||||||
|
Texture("attack_point.png"),
|
||||||
|
)
|
||||||
|
world[AttackTimer] = AttackTimer(0.0)
|
||||||
|
world[AttackSpeed] = AttackSpeed(world[AttackSpeed] * 0.9)
|
||||||
|
|
||||||
|
|
||||||
def __move_directories(world: World):
|
def __move_directories(world: World):
|
||||||
"""
|
"""
|
||||||
Permet de déplacer les dossiers avec la souris.
|
Permet de déplacer les dossiers avec la souris.
|
||||||
"""
|
"""
|
||||||
|
# Si on n'est pas dans le bon state on annule
|
||||||
|
if world[State] != State.MOVING:
|
||||||
|
return
|
||||||
|
|
||||||
|
# On met à jour la séléction
|
||||||
mouse = world[Mouse]
|
mouse = world[Mouse]
|
||||||
for entity in world.query(Hovered, DirectoryPosition):
|
for entity in world.query(Hovered, DirectoryPosition):
|
||||||
if mouse.is_button_pressed(1):
|
if mouse.is_button_pressed(1):
|
||||||
|
@ -151,11 +233,11 @@ def __move_directories(world: World):
|
||||||
movements: list[tuple[int, int]] = []
|
movements: list[tuple[int, int]] = []
|
||||||
if directory_position.x != 0:
|
if directory_position.x != 0:
|
||||||
movements.append((-1, 0))
|
movements.append((-1, 0))
|
||||||
if directory_position.x != __COLUMNS - 1:
|
if directory_position.x != COLUMNS - 1:
|
||||||
movements.append((1, 0))
|
movements.append((1, 0))
|
||||||
if directory_position.y != 0:
|
if directory_position.y != 0:
|
||||||
movements.append((0, -1))
|
movements.append((0, -1))
|
||||||
if directory_position.y != __LINES - 1:
|
if directory_position.y != LINES - 1:
|
||||||
movements.append((0, 1))
|
movements.append((0, 1))
|
||||||
if len(movements) == 0:
|
if len(movements) == 0:
|
||||||
return
|
return
|
||||||
|
@ -195,14 +277,7 @@ def __update_positions(world: World):
|
||||||
"""
|
"""
|
||||||
for entity in world.query(DirectoryPosition):
|
for entity in world.query(DirectoryPosition):
|
||||||
position = entity[DirectoryPosition]
|
position = entity[DirectoryPosition]
|
||||||
size = Vec2(
|
entity[smooth.Target] = smooth.Target(position.screen_position(world[State]))
|
||||||
__WAITING_SPACING if world[State] == State.WAITING else __SEARCHING_SPACING
|
|
||||||
)
|
|
||||||
offset = -(size * Vec2(__COLUMNS - 1, __LINES - 1) / 2)
|
|
||||||
first_position = Vec2(Display.WIDTH / 2, Display.HEIGHT / 2) + offset
|
|
||||||
entity[smooth.Target] = smooth.Target(
|
|
||||||
first_position + Vec2(position.x, position.y) * size
|
|
||||||
)
|
|
||||||
entity[Order] = Order(position.y + 1)
|
entity[Order] = Order(position.y + 1)
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,7 +294,7 @@ def __update_directory_names(world: World):
|
||||||
SCENE = (
|
SCENE = (
|
||||||
Scene(
|
Scene(
|
||||||
[__initialize_world],
|
[__initialize_world],
|
||||||
[__move_directories, __update_positions],
|
[__attacks, __move_directories, __update_positions],
|
||||||
[],
|
[],
|
||||||
)
|
)
|
||||||
+ smooth.PLUGIN
|
+ smooth.PLUGIN
|
||||||
|
|
Loading…
Reference in a new issue