Skip to content

Commit

Permalink
feat: add some buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenMian committed Jan 15, 2024
1 parent e2154d7 commit 7091ce5
Show file tree
Hide file tree
Showing 9 changed files with 292 additions and 81 deletions.
Binary file added assets/textures/automatic_solution.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/instant_move_off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/instant_move_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/next.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/textures/previous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 11 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod systems;
use systems::input::*;
use systems::level::*;
use systems::render::*;
use systems::ui::*;

mod plugins;
use plugins::performance_matrix::*;
Expand Down Expand Up @@ -45,12 +46,21 @@ fn main() {
.add_systems(PreStartup, (setup_camera, setup_database))
.add_systems(
Startup,
(setup_window, setup_version_info, setup_hud, setup_level),
(
setup_window,
setup_version_info,
setup_button,
setup_hud,
setup_level,
),
)
.add_systems(PostStartup, spawn_board)
.add_systems(
Update,
(
button_visual_effect,
update_button_state,
button_pressed,
update_grid_position_from_board,
select_crate,
unselect_crate,
Expand Down
1 change: 1 addition & 0 deletions src/systems/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod input;
pub mod level;
pub mod render;
pub mod ui;
80 changes: 0 additions & 80 deletions src/systems/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use bevy::winit::WinitWindows;
use itertools::Itertools;

use crate::components::*;
use crate::direction::Direction;
use crate::events::*;
use crate::level::PushState;
use crate::resources::*;

use std::collections::HashSet;
Expand Down Expand Up @@ -34,84 +32,6 @@ pub fn setup_camera(mut commands: Commands) {
commands.spawn((Camera2dBundle::default(), MainCamera::default()));
}

pub fn setup_version_info(mut commands: Commands) {
const ALPHA: f32 = 0.8;
commands.spawn(
TextBundle::from_sections([TextSection::new(
"version: ".to_string() + env!("CARGO_PKG_VERSION"),
TextStyle {
font_size: 14.0,
color: Color::GRAY.with_a(ALPHA),
..default()
},
)])
.with_style(Style {
position_type: PositionType::Absolute,
bottom: Val::Px(5.0),
right: Val::Px(5.0),
..default()
}),
);
}

pub fn setup_hud(mut commands: Commands) {
const ALPHA: f32 = 0.8;
let text_section = move |color, value: &str| {
TextSection::new(
value,
TextStyle {
font_size: 18.0,
color,
..default()
},
)
};
commands.spawn((
HUD,
TextBundle::from_sections([
text_section(Color::SEA_GREEN.with_a(ALPHA), "Level : "),
text_section(Color::GOLD.with_a(ALPHA), ""),
text_section(Color::SEA_GREEN.with_a(ALPHA), "\nMoves : "),
text_section(Color::GOLD.with_a(ALPHA), ""),
text_section(Color::SEA_GREEN.with_a(ALPHA), "\nPushes: "),
text_section(Color::GOLD.with_a(ALPHA), ""),
text_section(Color::SEA_GREEN.with_a(ALPHA), "\nBest moves : "),
text_section(Color::GOLD.with_a(ALPHA), ""),
text_section(Color::SEA_GREEN.with_a(ALPHA), "\nBest pushes: "),
text_section(Color::GOLD.with_a(ALPHA), ""),
])
.with_style(Style {
position_type: PositionType::Absolute,
top: Val::Px(5.0),
right: Val::Px(5.0),
..default()
}),
));
}

pub fn update_hud(
mut hud: Query<&mut Text, With<HUD>>,
board: Query<&Board>,
level_id: Res<LevelId>,
database: Res<Database>,
) {
let mut hud = hud.single_mut();
let board = &board.single().board;

if level_id.is_changed() {
hud.sections[1].value = format!("#{}", **level_id);

let database = database.lock().unwrap();
hud.sections[7].value =
format!("{}", database.get_best_move_count(**level_id).unwrap_or(0));
hud.sections[9].value =
format!("{}", database.get_best_push_count(**level_id).unwrap_or(0));
}

hud.sections[3].value = format!("{}", board.movements.move_count());
hud.sections[5].value = format!("{}", board.movements.push_count());
}

pub fn animate_player_movement(
mut player: Query<(&mut GridPosition, &mut TextureAtlasSprite), With<Player>>,
mut crates: Query<&mut GridPosition, (With<Crate>, Without<Player>)>,
Expand Down
Loading

0 comments on commit 7091ce5

Please sign in to comment.