explore game state
This commit is contained in:
parent
a00a66ab1e
commit
3217fbdfbe
|
@ -1,12 +1,14 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
use crate::Player;
|
||||
use crate::GameState;
|
||||
|
||||
pub fn player_mouse_move (
|
||||
buttons: Res<ButtonInput<MouseButton>>,
|
||||
mut player_query: Query<(&mut Player, &Camera, &mut GlobalTransform)>,
|
||||
window_query: Query<&Window, With<bevy::window::PrimaryWindow>>,
|
||||
) {
|
||||
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<ButtonInput<KeyCode>>,
|
||||
mut game_state: ResMut<NextState<GameState>>,
|
||||
//mut player_query: Query<(&mut Player, &mut Transform)>,
|
||||
) {
|
||||
if keys.just_pressed(KeyCode::Escape) {
|
||||
game_state.set(GameState::Start);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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::<StartMenu>)
|
||||
.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::<MainGame>)
|
||||
|
|
|
@ -19,48 +19,62 @@ pub fn audio_setup(asset_server: Res<AssetServer>, 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);
|
||||
|
|
Loading…
Reference in a new issue