diff --git a/src/explo_state.rs b/src/explo_state.rs index e994226..10d9ba4 100644 --- a/src/explo_state.rs +++ b/src/explo_state.rs @@ -1,12 +1,14 @@ use bevy::prelude::*; use crate::Player; +use crate::GameState; pub fn player_mouse_move ( buttons: Res>, mut player_query: Query<(&mut Player, &Camera, &mut GlobalTransform)>, window_query: Query<&Window, With>, ) { + info!("-"); let Ok((mut player, camera, global_transform)) = player_query.get_single_mut() else { return; }; @@ -68,3 +70,33 @@ fn rotate_to_align(ray_1: Ray3d, ray_2: Ray3d) -> Quat { Quat::from_axis_angle(axis_of_rotation, angle_of_rotation) } + +pub fn rotate_camera( + mut player_query : Query<(&mut Player, &mut Transform)> +) { + let Ok((mut player, mut transform)) = player_query.get_single_mut() else { + return; + }; + + let Some(target_rotation) = player.target_rotation else { + return; + }; + + let current_rotation = transform.rotation; + + transform.rotation = current_rotation.slerp(target_rotation, 0.1); + + if transform.rotation.angle_between(target_rotation) < 0.01 { + player.target_rotation = None; + } +} + +pub fn player_interact( + keys: Res>, + mut game_state: ResMut>, + //mut player_query: Query<(&mut Player, &mut Transform)>, +) { + if keys.just_pressed(KeyCode::Escape) { + game_state.set(GameState::Start); + } +} diff --git a/src/game_state.rs b/src/game_state.rs index 419caaf..c928a83 100644 --- a/src/game_state.rs +++ b/src/game_state.rs @@ -239,16 +239,6 @@ pub fn player_interact( player.target_rotation = Some(constellation_center(target_constellation)); } - - if let Some(target_rotation) = player.target_rotation { - let current_rotation = transform.rotation; - - transform.rotation = current_rotation.slerp(target_rotation, 0.1); - - if transform.rotation.angle_between(target_rotation) < 0.01 { - player.target_rotation = None; - } - } } pub fn ui_labels( diff --git a/src/main.rs b/src/main.rs index b9a05e7..b34e4b6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -142,6 +142,7 @@ enum PlayerState { enum GameState { #[default] Start, + Explo, Game, End, } @@ -160,7 +161,9 @@ fn main() { .add_systems(OnExit(GameState::Start), despawn_screen::) .add_systems(OnEnter(GameState::Game), game_state::setup) .add_systems(Update, game_state::player_interact.run_if(in_state(GameState::Game))) - .add_systems(Update, explo_state::player_mouse_move.run_if(in_state(GameState::Game))) + .add_systems(Update, explo_state::player_mouse_move.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo)))) + .add_systems(Update, explo_state::rotate_camera.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo)))) + .add_systems(Update, explo_state::player_interact.run_if(in_state(GameState::Explo))) .add_systems(Update, game_state::ui_buttons.run_if(in_state(GameState::Game))) .add_systems(Update, game_state::ui_labels.run_if(in_state(GameState::Game))) .add_systems(OnExit(GameState::Game), despawn_screen::) diff --git a/src/start_state.rs b/src/start_state.rs index 9ae9ba3..664f48b 100644 --- a/src/start_state.rs +++ b/src/start_state.rs @@ -19,48 +19,62 @@ pub fn audio_setup(asset_server: Res, mut commands: Commands) { pub fn setup( mut commands: Commands, ) { - let container_node = NodeBundle { + let main_container_node = NodeBundle { style: Style { width: Val::Percent(100.0), height: Val::Percent(100.0), flex_direction: FlexDirection::Column, justify_content: JustifyContent::Center, align_items: AlignItems::Center, + ..default() }, ..default() }; - let container = commands.spawn(container_node).id(); + let main_container = commands.spawn(main_container_node).id(); - let top_text_style = TextStyle { + let title_text_style = TextStyle { font_size: 50.0, color: Color::WHITE, // font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font if needed ..default() }; - let bottom_text_style = TextStyle { + let start_text_style = TextStyle { font_size: 30.0, color: Color::WHITE, // font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed ..default() }; - let top_text_node = TextBundle::from_section( + let explo_text_style = TextStyle { + font_size: 30.0, + color: Color::srgb(0.4,0.4,0.4), + // font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed + ..default() + }; + + let title_text_node = TextBundle::from_section( "Astraea", - top_text_style, + title_text_style, ); - let bottom_text_node = TextBundle::from_section( + let start_text_node = TextBundle::from_section( "Press Space to Begin", - bottom_text_style, + start_text_style, ); - let top_text = commands.spawn((top_text_node, StartMenu)).id(); - let bottom_text = commands.spawn((bottom_text_node, StartMenu)).id(); + let explo_text_node = TextBundle::from_section( + "Press E to Explore", + explo_text_style, + ); - commands.entity(container).push_children(&[top_text, bottom_text]); + let title_text = commands.spawn((title_text_node, StartMenu)).id(); + let start_text = commands.spawn((start_text_node, StartMenu)).id(); + let explo_text = commands.spawn((explo_text_node, StartMenu)).id(); + + commands.entity(main_container).push_children(&[title_text, start_text, explo_text]); } pub fn player_interact( @@ -69,10 +83,13 @@ pub fn player_interact( mut player_query: Query<(&mut Player, &mut Transform)>, ) { if keys.just_pressed(KeyCode::Space) { - info!("start space"); game_state.set(GameState::Game); } + if keys.just_pressed(KeyCode::KeyE) { + game_state.set(GameState::Explo); + } + if let Ok((_player, mut transform)) = player_query.get_single_mut() { let mut rotation = Quat::IDENTITY; rotation *= Quat::from_rotation_y((PI / 6000.0) as f32);