mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
feat(floor): move floors on "E"
This commit is contained in:
parent
e096216806
commit
58501cf536
@ -4,7 +4,7 @@ pub mod errors;
|
||||
pub mod events;
|
||||
pub mod resources;
|
||||
mod systems;
|
||||
mod triggers;
|
||||
pub mod triggers;
|
||||
|
||||
use bevy::{ecs::system::RunSystemOnce, prelude::*};
|
||||
use components::HexMaze;
|
||||
|
||||
@ -16,7 +16,7 @@ use hexlab::prelude::{Tile as HexTile, *};
|
||||
use hexx::HexOrientation;
|
||||
use std::f32::consts::{FRAC_PI_2, FRAC_PI_3, FRAC_PI_6};
|
||||
|
||||
pub(super) fn spawn_maze(
|
||||
pub(crate) fn spawn_maze(
|
||||
trigger: Trigger<SpawnMaze>,
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
|
||||
@ -3,7 +3,7 @@ use hexx::Hex;
|
||||
|
||||
#[derive(Debug, Reflect, Component)]
|
||||
#[reflect(Component)]
|
||||
#[require(CurrentPosition, MovementSpeed, MovementTarget, TranstitionState)]
|
||||
#[require(CurrentPosition, MovementSpeed, MovementTarget)]
|
||||
pub struct Player;
|
||||
|
||||
#[derive(Debug, Reflect, Component, Deref, DerefMut, Default)]
|
||||
@ -14,13 +14,6 @@ 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.)
|
||||
|
||||
@ -6,43 +6,35 @@ use crate::{
|
||||
events::TransitionFloor,
|
||||
},
|
||||
maze::components::MazeConfig,
|
||||
player::components::{CurrentPosition, Player, TranstitionState},
|
||||
player::components::{CurrentPosition, Player},
|
||||
};
|
||||
|
||||
pub fn handle_floor_transition(
|
||||
mut player_query: Query<(&CurrentPosition, &mut TranstitionState), With<Player>>,
|
||||
mut player_query: Query<&CurrentPosition, With<Player>>,
|
||||
maze_query: Query<(&MazeConfig, &Floor), With<CurrentFloor>>,
|
||||
mut event_writer: EventWriter<TransitionFloor>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if !input.just_pressed(KeyCode::KeyE) {
|
||||
return;
|
||||
}
|
||||
|
||||
let Ok((config, floor)) = maze_query.get_single() else {
|
||||
warn!("Failed to get maze configuration for current floor - cannot ascend/descend player.");
|
||||
return;
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
for current_hex in player_query.iter_mut() {
|
||||
// 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