Compare commits
No commits in common. "895193778b3f7f63a5bce139da00518143a368f9" and "c1e53bdab034b09565a51270b4f3d14373bcd198" have entirely different histories.
895193778b
...
c1e53bdab0
16 changed files with 12 additions and 203 deletions
|
|
@ -13,7 +13,6 @@ mod ui;
|
||||||
use crate::states::game::state::MainGameState;
|
use crate::states::game::state::MainGameState;
|
||||||
use crate::states::main_menu::state::MainMenuState;
|
use crate::states::main_menu::state::MainMenuState;
|
||||||
use crate::states::settings_menu::state::SettingsMenuState;
|
use crate::states::settings_menu::state::SettingsMenuState;
|
||||||
use crate::states::linear::plugin::LinearPlugin;
|
|
||||||
|
|
||||||
const FACTOR: u32 = 80;
|
const FACTOR: u32 = 80;
|
||||||
const WIDTH: u32 = 16;
|
const WIDTH: u32 = 16;
|
||||||
|
|
@ -37,7 +36,6 @@ fn main() {
|
||||||
MainMenuState,
|
MainMenuState,
|
||||||
SettingsMenuState,
|
SettingsMenuState,
|
||||||
MainGameState,
|
MainGameState,
|
||||||
LinearPlugin,
|
|
||||||
))
|
))
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
.add_systems(Update, exit_system)
|
.add_systems(Update, exit_system)
|
||||||
|
|
|
||||||
|
|
@ -8,5 +8,4 @@ pub enum AppState {
|
||||||
GameState,
|
GameState,
|
||||||
GameRestart,
|
GameRestart,
|
||||||
LevelState,
|
LevelState,
|
||||||
LinearState,
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ pub fn restart_game_button_system(
|
||||||
) {
|
) {
|
||||||
for interaction in &interaction_query {
|
for interaction in &interaction_query {
|
||||||
if matches!(interaction, Interaction::Pressed) {
|
if matches!(interaction, Interaction::Pressed) {
|
||||||
println!("Сброс состояния");
|
println!("🔄 Кнопка Restart нажата! Переход в Restarting...");
|
||||||
next_state.set(AppState::GameRestart);
|
next_state.set(AppState::GameRestart);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct LinearStateMarker;
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
#[derive(Component)]
|
|
||||||
pub struct Track{
|
|
||||||
pub start_point: Vec2,
|
|
||||||
pub start_direction: Vec2, // будет нормализовано при построении
|
|
||||||
pub segments: Vec<PathSegment>,
|
|
||||||
}
|
|
||||||
|
|
||||||
// линия всегда строится от точки старта по направлению
|
|
||||||
// направление изменяется сегментами поворота
|
|
||||||
// left при истине - поворот против часовой стрелки, ложь - по часовой
|
|
||||||
#[derive(Clone, Copy)]
|
|
||||||
pub enum PathSegment{
|
|
||||||
Line { length: f32 },
|
|
||||||
Turn { radius: f32, left: bool },
|
|
||||||
}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
pub mod plugin;
|
|
||||||
|
|
||||||
mod components;
|
|
||||||
pub use components::*;
|
|
||||||
|
|
||||||
mod systems;
|
|
||||||
pub use systems::*;
|
|
||||||
|
|
||||||
mod components_track;
|
|
||||||
pub use components_track::*;
|
|
||||||
|
|
||||||
mod systems_track;
|
|
||||||
pub use systems_track::*;
|
|
||||||
|
|
@ -1,22 +0,0 @@
|
||||||
use bevy::prelude::*;
|
|
||||||
use crate::states::AppState::LinearState;
|
|
||||||
use crate::states::linear::*;
|
|
||||||
|
|
||||||
pub struct LinearPlugin;
|
|
||||||
|
|
||||||
impl Plugin for LinearPlugin {
|
|
||||||
fn build(&self, app: &mut App) {
|
|
||||||
app
|
|
||||||
.add_systems(OnEnter (LinearState), (setup, setup_linear_track).chain())
|
|
||||||
.add_systems(Update, (draw_track_gizmos).run_if(in_state(LinearState)))
|
|
||||||
.add_systems(OnExit (LinearState), cleanup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn setup(mut commands: Commands) {}
|
|
||||||
|
|
||||||
fn cleanup(mut commands: Commands, query: Query<Entity, With<LinearStateMarker>>) {
|
|
||||||
for entity in query.iter() {
|
|
||||||
commands.entity(entity).despawn();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
use crate::states;
|
|
||||||
use bevy::prelude::*;
|
|
||||||
use states::linear::*;
|
|
||||||
use std::f32::consts::{FRAC_PI_2, PI};
|
|
||||||
|
|
||||||
const PINK: Color = Color::srgb_u8(250, 0, 155);
|
|
||||||
const BLUE: Color = Color::srgb_u8(0, 0, 255);
|
|
||||||
const GREEN: Color = Color::srgb_u8(0, 255, 0);
|
|
||||||
|
|
||||||
pub fn draw_track_gizmos(query: Query<&Track>, mut gizmos: Gizmos) {
|
|
||||||
println!("Рисуем трек из примитивов");
|
|
||||||
for track in &query {
|
|
||||||
let mut current_pos = track.start_point;
|
|
||||||
let mut current_dir = track.start_direction.normalize();
|
|
||||||
|
|
||||||
// точка старта
|
|
||||||
gizmos.circle_2d(current_pos, 5.0, BLUE);
|
|
||||||
|
|
||||||
// рисуем сегменты
|
|
||||||
for segment in &track.segments {
|
|
||||||
match segment {
|
|
||||||
PathSegment::Line { length } => {
|
|
||||||
let end_pos = current_pos + current_dir * length;
|
|
||||||
gizmos.line_2d(current_pos, end_pos, PINK);
|
|
||||||
current_pos = end_pos
|
|
||||||
}
|
|
||||||
|
|
||||||
PathSegment::Turn { radius, left } => {
|
|
||||||
// вычисляем направление поворота и знак для угла
|
|
||||||
let (normal, sign): (Vec2, f32) = if *left {
|
|
||||||
(Vec2::new(-current_dir.y, current_dir.x), -1.0)
|
|
||||||
} else {
|
|
||||||
(Vec2::new(current_dir.y, -current_dir.x), 1.0)
|
|
||||||
};
|
|
||||||
|
|
||||||
let center = current_pos + normal * radius;
|
|
||||||
let start_vec = current_pos - center;
|
|
||||||
let initial_vec = if *left {
|
|
||||||
-start_vec.perp()
|
|
||||||
} else {
|
|
||||||
-start_vec
|
|
||||||
};
|
|
||||||
|
|
||||||
gizmos.arc_2d(
|
|
||||||
Isometry2d::new(center, Rot2::radians(initial_vec.to_angle())),
|
|
||||||
FRAC_PI_2,
|
|
||||||
*radius,
|
|
||||||
GREEN,
|
|
||||||
);
|
|
||||||
// current_pos = center + current_dir * radius;
|
|
||||||
// current_pos = center + normal.perp() * radius;
|
|
||||||
current_pos = center + normal.perp() * radius * sign;
|
|
||||||
current_dir = normal;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// рисуем финиш
|
|
||||||
gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
use crate::states::linear::*;
|
|
||||||
use crate::{FACTOR, HEIGHT, WIDTH};
|
|
||||||
use bevy::prelude::*;
|
|
||||||
|
|
||||||
pub const CENTER_X: f32 = 0.0;
|
|
||||||
pub const CENTER_Y: f32 = 0.0;
|
|
||||||
|
|
||||||
// pub const FACTOR_RADIUS: f32 = FACTOR as f32 / 2.0;
|
|
||||||
|
|
||||||
pub const STEP: f32 = FACTOR as f32 / SCALE;
|
|
||||||
pub const SCALE: f32 = 2.0;
|
|
||||||
|
|
||||||
|
|
||||||
pub fn setup_linear_track(mut commands: Commands) {
|
|
||||||
println!("Построение трека начато");
|
|
||||||
|
|
||||||
commands.spawn((
|
|
||||||
Track {
|
|
||||||
start_point: Vec2 {
|
|
||||||
x: CENTER_X - FACTOR as f32 * 7.0,
|
|
||||||
y: CENTER_Y - FACTOR as f32 * 4.0,
|
|
||||||
},
|
|
||||||
start_direction: Vec2::X,
|
|
||||||
segments: vec![
|
|
||||||
PathSegment::Line { length: STEP * 2.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
PathSegment::Line { length: STEP },
|
|
||||||
PathSegment::Turn { radius: STEP, left: false },
|
|
||||||
PathSegment::Line { length: STEP * 10.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
PathSegment::Line { length: STEP * 4.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
PathSegment::Turn { radius: STEP, left: false },
|
|
||||||
PathSegment::Line { length: STEP * 2.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
PathSegment::Line { length: STEP * 6.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
PathSegment::Line { length: STEP * 1.0 },
|
|
||||||
PathSegment::Turn { radius: STEP, left: true },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
LinearStateMarker,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
@ -8,6 +8,3 @@ pub struct MainMenuNewGameButton;
|
||||||
|
|
||||||
#[derive(Component, Copy, Clone)]
|
#[derive(Component, Copy, Clone)]
|
||||||
pub struct MainMenuSettingsButton;
|
pub struct MainMenuSettingsButton;
|
||||||
|
|
||||||
#[derive(Component, Copy, Clone)]
|
|
||||||
pub struct MainMenuLinearButton;
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
pub(crate) mod state;
|
pub mod state;
|
||||||
pub use state::*;
|
pub mod components;
|
||||||
mod components;
|
|
||||||
pub use components::*;
|
pub use components::*;
|
||||||
mod systems;
|
pub mod systems;
|
||||||
pub use systems::*;
|
|
||||||
pub mod plugin;
|
pub mod plugin;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use crate::states::main_menu::*;
|
use crate::states::main_menu::{MainMenuNewGameButton, MainMenuSettingsButton};
|
||||||
use crate::ui::button_click::ButtonClickMessage;
|
use crate::ui::button_click::ButtonClickMessage;
|
||||||
use crate::ui::click::handle_click_system;
|
use crate::ui::click::handle_click_system;
|
||||||
|
|
||||||
|
|
@ -12,13 +12,11 @@ impl Plugin for MainMenuUiPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_message::<ButtonClickMessage<MainMenuNewGameButton>>()
|
app.add_message::<ButtonClickMessage<MainMenuNewGameButton>>()
|
||||||
.add_message::<ButtonClickMessage<MainMenuSettingsButton>>()
|
.add_message::<ButtonClickMessage<MainMenuSettingsButton>>()
|
||||||
.add_message::<ButtonClickMessage<MainMenuLinearButton>>()
|
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
(
|
(
|
||||||
handle_click_system::<MainMenuNewGameButton>,
|
handle_click_system::<MainMenuNewGameButton>,
|
||||||
handle_click_system::<MainMenuSettingsButton>,
|
handle_click_system::<MainMenuSettingsButton>,
|
||||||
handle_click_system::<MainMenuLinearButton>,
|
|
||||||
).in_set(MainMenuButtonSet)
|
).in_set(MainMenuButtonSet)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::states::*;
|
use crate::states::AppState;
|
||||||
use crate::states::main_menu::*;
|
use crate::states::main_menu::{MainMenuNewGameButton, MainMenuRootMarker, MainMenuSettingsButton};
|
||||||
|
use crate::states::main_menu::systems::*;
|
||||||
use crate::ui::button_hover::button_hover;
|
use crate::ui::button_hover::button_hover;
|
||||||
use crate::ui::{ButtonStyle, spawn_background, spawn_button};
|
use crate::ui::{ButtonStyle, spawn_background, spawn_button};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
@ -19,7 +20,6 @@ impl Plugin for MainMenuState {
|
||||||
button_hover,
|
button_hover,
|
||||||
new_game_button_system,
|
new_game_button_system,
|
||||||
settings_button_system,
|
settings_button_system,
|
||||||
linear_button_system,
|
|
||||||
)
|
)
|
||||||
.run_if(in_state(AppState::MainMenu)),
|
.run_if(in_state(AppState::MainMenu)),
|
||||||
)
|
)
|
||||||
|
|
@ -92,14 +92,6 @@ fn setup_main_menu(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
MainMenuNewGameButton,
|
MainMenuNewGameButton,
|
||||||
);
|
);
|
||||||
|
|
||||||
spawn_button(
|
|
||||||
&mut commands,
|
|
||||||
menu_root,
|
|
||||||
"Линейное",
|
|
||||||
&mm_button_style,
|
|
||||||
MainMenuLinearButton,
|
|
||||||
);
|
|
||||||
|
|
||||||
spawn_button(
|
spawn_button(
|
||||||
&mut commands,
|
&mut commands,
|
||||||
menu_root,
|
menu_root,
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::states::AppState;
|
use crate::states::AppState;
|
||||||
use crate::states::main_menu::*;
|
use crate::states::main_menu::{MainMenuNewGameButton, MainMenuSettingsButton};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
pub fn new_game_button_system(
|
pub fn new_game_button_system(
|
||||||
|
|
@ -23,15 +23,3 @@ pub fn settings_button_system(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn linear_button_system(
|
|
||||||
interaction_query: Query<&Interaction, (Changed<Interaction>, With<MainMenuLinearButton>)>,
|
|
||||||
mut next_state: ResMut<NextState<AppState>>,
|
|
||||||
) {
|
|
||||||
for interaction in &interaction_query {
|
|
||||||
if matches!(interaction, Interaction::Pressed) {
|
|
||||||
println!("Линейное нажата");
|
|
||||||
next_state.set(AppState::LinearState);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -6,4 +6,3 @@ pub mod main_menu;
|
||||||
pub mod settings_menu;
|
pub mod settings_menu;
|
||||||
pub mod game;
|
pub mod game;
|
||||||
mod level;
|
mod level;
|
||||||
pub mod linear;
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue