mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
fix(player): block movement during floor transition
This commit is contained in:
parent
a4e819b4b6
commit
2c3a1a2fff
@ -6,10 +6,12 @@ pub struct Floor(pub u8);
|
||||
|
||||
#[derive(Debug, Reflect, Component)]
|
||||
#[reflect(Component)]
|
||||
#[require(Floor)]
|
||||
pub struct CurrentFloor;
|
||||
|
||||
#[derive(Debug, Reflect, Component, Deref, DerefMut)]
|
||||
#[reflect(Component)]
|
||||
#[require(Floor)]
|
||||
pub struct FloorYTarget(pub f32);
|
||||
|
||||
impl Default for Floor {
|
||||
|
||||
@ -12,10 +12,7 @@ use bevy::prelude::*;
|
||||
|
||||
pub fn move_floors(
|
||||
mut commands: Commands,
|
||||
mut maze_query: Query<
|
||||
(Entity, &mut Transform, &FloorYTarget),
|
||||
(With<HexMaze>, With<FloorYTarget>),
|
||||
>,
|
||||
mut maze_query: Query<(Entity, &mut Transform, &FloorYTarget), With<FloorYTarget>>,
|
||||
player_query: Query<&MovementSpeed, With<Player>>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
|
||||
@ -3,7 +3,7 @@ use hexx::Hex;
|
||||
|
||||
#[derive(Debug, Reflect, Component)]
|
||||
#[reflect(Component)]
|
||||
#[require(CurrentPosition, MovementSpeed, MovementTarget)]
|
||||
#[require(CurrentPosition, MovementSpeed, MovementTarget, TranstitionState)]
|
||||
pub struct Player;
|
||||
|
||||
#[derive(Debug, Reflect, Component, Deref, DerefMut, Default)]
|
||||
@ -14,6 +14,13 @@ pub struct CurrentPosition(pub Hex);
|
||||
#[reflect(Component)]
|
||||
pub struct MovementSpeed(pub f32);
|
||||
|
||||
#[derive(Debug, Reflect, Component, Default)]
|
||||
#[reflect(Component)]
|
||||
pub struct TranstitionState {
|
||||
pub just_transitioned: bool,
|
||||
pub last_position: Hex,
|
||||
}
|
||||
|
||||
impl Default for MovementSpeed {
|
||||
fn default() -> Self {
|
||||
Self(100.)
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
floor::components::CurrentFloor,
|
||||
floor::components::{CurrentFloor, FloorYTarget},
|
||||
maze::components::MazeConfig,
|
||||
player::components::{CurrentPosition, MovementTarget, Player},
|
||||
};
|
||||
@ -10,12 +10,16 @@ use hexx::{EdgeDirection, HexOrientation};
|
||||
pub(super) fn player_input(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut player_query: Query<(&mut MovementTarget, &CurrentPosition), With<Player>>,
|
||||
maze_query: Query<(&Maze, &MazeConfig), With<CurrentFloor>>,
|
||||
maze_query: Query<(&Maze, &MazeConfig, Has<FloorYTarget>), With<CurrentFloor>>,
|
||||
) {
|
||||
let Ok((maze, maze_config)) = maze_query.get_single() else {
|
||||
let Ok((maze, maze_config, has_y_target)) = maze_query.get_single() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if has_y_target {
|
||||
return;
|
||||
}
|
||||
|
||||
for (mut target_pos, current_pos) in player_query.iter_mut() {
|
||||
if target_pos.is_some() {
|
||||
continue;
|
||||
|
||||
@ -6,11 +6,11 @@ use crate::{
|
||||
events::TransitionFloor,
|
||||
},
|
||||
maze::components::MazeConfig,
|
||||
player::components::{CurrentPosition, Player},
|
||||
player::components::{CurrentPosition, Player, TranstitionState},
|
||||
};
|
||||
|
||||
pub fn handle_floor_transition(
|
||||
player_query: Query<&CurrentPosition, With<Player>>,
|
||||
mut player_query: Query<(&CurrentPosition, &mut TranstitionState), With<Player>>,
|
||||
maze_query: Query<(&MazeConfig, &Floor), With<CurrentFloor>>,
|
||||
mut event_writer: EventWriter<TransitionFloor>,
|
||||
) {
|
||||
@ -19,17 +19,30 @@ pub fn handle_floor_transition(
|
||||
return;
|
||||
};
|
||||
|
||||
for current_hex in player_query.iter() {
|
||||
for (current_hex, mut transition_state) in player_query.iter_mut() {
|
||||
// Reset transition state if moved to a new position
|
||||
if current_hex.0 != transition_state.last_position {
|
||||
transition_state.just_transitioned = false;
|
||||
}
|
||||
transition_state.last_position = current_hex.0;
|
||||
|
||||
// Skip if transition just happened
|
||||
if transition_state.just_transitioned {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check for ascending
|
||||
if current_hex.0 == config.end_pos {
|
||||
info!("Ascending");
|
||||
event_writer.send(TransitionFloor::Ascend);
|
||||
transition_state.just_transitioned = true;
|
||||
}
|
||||
|
||||
// Check for descending
|
||||
if current_hex.0 == config.start_pos && floor.0 != 1 {
|
||||
info!("Descending");
|
||||
event_writer.send(TransitionFloor::Descend);
|
||||
transition_state.just_transitioned = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user