diff --git a/assets/EurostileRound-Regular.ttf b/assets/EurostileRound-Regular.ttf new file mode 100755 index 0000000..1f4c411 Binary files /dev/null and b/assets/EurostileRound-Regular.ttf differ diff --git a/src/engine/components.rs b/src/engine/components.rs index f29f935..2d0d702 100644 --- a/src/engine/components.rs +++ b/src/engine/components.rs @@ -3,6 +3,12 @@ use bevy::prelude::*; #[derive(Component)] pub struct BoardVisual{} +#[derive(Component)] +pub struct HUD {} + +#[derive(Component)] +pub struct LockDelayText {} + #[derive(Component, Clone, Copy)] pub struct Mino{ pub color: Color diff --git a/src/engine/mod.rs b/src/engine/mod.rs index b6cc9f7..b24a178 100644 --- a/src/engine/mod.rs +++ b/src/engine/mod.rs @@ -1,10 +1,11 @@ use bevy::prelude::*; -use self::{systems::*, resources::Engine}; +use self::{systems::*, resources::Engine, ui::spawn_hud}; mod rotation_systems; mod systems; mod components; mod resources; +mod ui; pub mod randomizers; pub struct UBSGEngine; @@ -16,6 +17,7 @@ impl Plugin for UBSGEngine{ add_state::(). insert_resource(Engine::default()). add_systems(Startup, init_engine.run_if(in_state(GameStates::Gameplay))). + add_systems(Startup, spawn_hud). add_systems(Update, receive_input.run_if(in_state(GameStates::Gameplay))). add_systems(Update, das_and_arr.run_if(in_state(GameStates::Gameplay))). add_systems(FixedUpdate, gameloop.run_if(in_state(GameStates::Gameplay)).run_if(in_state(GameloopStates::Falling))). diff --git a/src/engine/systems.rs b/src/engine/systems.rs index 27478cf..64ea343 100644 --- a/src/engine/systems.rs +++ b/src/engine/systems.rs @@ -238,6 +238,7 @@ pub fn das_and_arr( pub fn gameloop( clocks: Res>, + mut lock_delay_text: Query<&mut Text, With>, mut engine: ResMut, mut next_state: ResMut>, ) { @@ -251,7 +252,17 @@ pub fn gameloop( engine.g_bucket -= 1.0; } if !engine.position_is_valid((piece.position.0, piece.position.1-1), piece.rotation){ - engine.lock_delay_left -= 1; + match engine.rotation_system.lock_delay_mode { + super::rotation_systems::LockDelayMode::Disabled => { + engine.lock_current_piece(); + next_state.set(GameloopStates::AfterLocking); + return; + }, + super::rotation_systems::LockDelayMode::Gravity => {engine.need_to_lock = true;}, + super::rotation_systems::LockDelayMode::ResetOnYChange => {}, + super::rotation_systems::LockDelayMode::ResetOnMovementLimited => {engine.lock_delay_left -= 1;}, + super::rotation_systems::LockDelayMode::ResetOnMovement => {engine.lock_delay_left -= 1;} + } }else{ engine.lock_delay_left = engine.lock_delay; } @@ -264,6 +275,9 @@ pub fn gameloop( }, } + for mut text in lock_delay_text.iter_mut() { + text.sections[0].value = format!("{}; {}", engine.lock_delay_resets_left, engine.lock_delay_left); + } } pub fn after_locking_routine( diff --git a/src/engine/ui.rs b/src/engine/ui.rs new file mode 100644 index 0000000..11ec13c --- /dev/null +++ b/src/engine/ui.rs @@ -0,0 +1,58 @@ +use super::components::{HUD, LockDelayText}; +use bevy::prelude::*; + +pub fn spawn_hud(mut commands: Commands, asset_server: Res) { + build_hud(&mut commands, &asset_server); +} + +pub fn build_hud(commands: &mut Commands, asset_server: &Res) -> Entity { + let hud_entity = commands + .spawn(( + NodeBundle { + style: Style { + display: Display::Flex, + flex_direction: FlexDirection::Column, + justify_items: JustifyItems::Center, + align_items: AlignItems::Center, + ..default() + }, + ..default() + }, + HUD {}, + )) + .with_children(|parent| { + // Enemy Text + parent.spawn(( + TextBundle { + style: Style { + // position_type: PositionType::Absolute, + // top: Val::Percent(50.0), + // left: Val::Percent(50.0), + ..default() + }, + text: Text { + sections: vec![TextSection::new( + "0", + TextStyle { + font: asset_server.load("EurostileRound-Regular.ttf"), + font_size: 64.0, + color: Color::rgb(1.0, 1.0, 1.0), + }, + )], + alignment: TextAlignment::Center, + ..default() + }, + ..default() + }, + LockDelayText {}, + )); + }) + .id(); + hud_entity +} + +pub fn despawn_hud(mut commands: Commands, hud_query: Query>) { + for entity in hud_query.iter() { + commands.entity(entity).despawn_recursive(); + } +} \ No newline at end of file