figuring out how to work with UI
That's reminds me of CSS, but not quite
This commit is contained in:
parent
8add24d849
commit
95987c5526
Binary file not shown.
|
@ -3,6 +3,12 @@ use bevy::prelude::*;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct BoardVisual{}
|
pub struct BoardVisual{}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct HUD {}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct LockDelayText {}
|
||||||
|
|
||||||
#[derive(Component, Clone, Copy)]
|
#[derive(Component, Clone, Copy)]
|
||||||
pub struct Mino{
|
pub struct Mino{
|
||||||
pub color: Color
|
pub color: Color
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use self::{systems::*, resources::Engine};
|
use self::{systems::*, resources::Engine, ui::spawn_hud};
|
||||||
|
|
||||||
mod rotation_systems;
|
mod rotation_systems;
|
||||||
mod systems;
|
mod systems;
|
||||||
mod components;
|
mod components;
|
||||||
mod resources;
|
mod resources;
|
||||||
|
mod ui;
|
||||||
pub mod randomizers;
|
pub mod randomizers;
|
||||||
|
|
||||||
pub struct UBSGEngine;
|
pub struct UBSGEngine;
|
||||||
|
@ -16,6 +17,7 @@ impl Plugin for UBSGEngine{
|
||||||
add_state::<GameloopStates>().
|
add_state::<GameloopStates>().
|
||||||
insert_resource(Engine::default()).
|
insert_resource(Engine::default()).
|
||||||
add_systems(Startup, init_engine.run_if(in_state(GameStates::Gameplay))).
|
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, receive_input.run_if(in_state(GameStates::Gameplay))).
|
||||||
add_systems(Update, das_and_arr.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))).
|
add_systems(FixedUpdate, gameloop.run_if(in_state(GameStates::Gameplay)).run_if(in_state(GameloopStates::Falling))).
|
||||||
|
|
|
@ -238,6 +238,7 @@ pub fn das_and_arr(
|
||||||
|
|
||||||
pub fn gameloop(
|
pub fn gameloop(
|
||||||
clocks: Res<Time<Fixed>>,
|
clocks: Res<Time<Fixed>>,
|
||||||
|
mut lock_delay_text: Query<&mut Text, With<LockDelayText>>,
|
||||||
mut engine: ResMut<Engine>,
|
mut engine: ResMut<Engine>,
|
||||||
mut next_state: ResMut<NextState<GameloopStates>>,
|
mut next_state: ResMut<NextState<GameloopStates>>,
|
||||||
) {
|
) {
|
||||||
|
@ -251,7 +252,17 @@ pub fn gameloop(
|
||||||
engine.g_bucket -= 1.0;
|
engine.g_bucket -= 1.0;
|
||||||
}
|
}
|
||||||
if !engine.position_is_valid((piece.position.0, piece.position.1-1), piece.rotation){
|
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{
|
}else{
|
||||||
engine.lock_delay_left = engine.lock_delay;
|
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(
|
pub fn after_locking_routine(
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
use super::components::{HUD, LockDelayText};
|
||||||
|
use bevy::prelude::*;
|
||||||
|
|
||||||
|
pub fn spawn_hud(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
build_hud(&mut commands, &asset_server);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn build_hud(commands: &mut Commands, asset_server: &Res<AssetServer>) -> 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<Entity, With<HUD>>) {
|
||||||
|
for entity in hud_query.iter() {
|
||||||
|
commands.entity(entity).despawn_recursive();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue