explore constellations
This commit is contained in:
parent
26e54d05cf
commit
b20579f22b
|
@ -2,13 +2,19 @@ use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::Player;
|
use crate::Player;
|
||||||
use crate::GameState;
|
use crate::GameState;
|
||||||
|
use crate::Sky;
|
||||||
|
use crate::spawn_cons_lines;
|
||||||
|
|
||||||
// pub fn setup (
|
pub fn setup (
|
||||||
//
|
sky : Res<Sky>,
|
||||||
// ) {
|
mut commands: Commands,
|
||||||
// for
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
// spawn_cons_lines(commands, meshes, materials, sky, target_cons.clone());
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
// }
|
) {
|
||||||
|
for constellation in sky.content.iter() {
|
||||||
|
spawn_cons_lines(&mut commands, &mut meshes, &mut materials, constellation.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn player_mouse_move (
|
pub fn player_mouse_move (
|
||||||
buttons: Res<ButtonInput<MouseButton>>,
|
buttons: Res<ButtonInput<MouseButton>>,
|
||||||
|
|
|
@ -206,10 +206,10 @@ pub fn player_interact(
|
||||||
text_query: Query<&mut Text, With<AnswerButton>>,
|
text_query: Query<&mut Text, With<AnswerButton>>,
|
||||||
button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
|
||||||
constellation_line_query : Query<(Entity, &ConstellationModel)>,
|
constellation_line_query : Query<(Entity, &ConstellationModel)>,
|
||||||
commands: Commands,
|
|
||||||
mut game_state: ResMut<NextState<GameState>>,
|
mut game_state: ResMut<NextState<GameState>>,
|
||||||
meshes: ResMut<Assets<Mesh>>,
|
mut commands: Commands,
|
||||||
materials: ResMut<Assets<StandardMaterial>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
) {
|
) {
|
||||||
let Ok(mut player) = player_query.get_single_mut() else {
|
let Ok(mut player) = player_query.get_single_mut() else {
|
||||||
return
|
return
|
||||||
|
@ -236,7 +236,7 @@ pub fn player_interact(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
game_data.state = PlayerState::Hinted;
|
game_data.state = PlayerState::Hinted;
|
||||||
spawn_cons_lines(commands, meshes, materials, sky, target_cons);
|
spawn_cons_lines(&mut commands, &mut meshes, &mut materials, sky.get_constellation(&target_cons));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,9 +292,9 @@ pub fn ui_buttons(
|
||||||
>,
|
>,
|
||||||
mut text_query: Query<&mut Text, With<AnswerButton>>,
|
mut text_query: Query<&mut Text, With<AnswerButton>>,
|
||||||
mut game_data: ResMut<GameData>,
|
mut game_data: ResMut<GameData>,
|
||||||
commands: Commands,
|
mut commands: Commands,
|
||||||
meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<StandardMaterial>>,
|
||||||
sky: Res<Sky>
|
sky: Res<Sky>
|
||||||
) {
|
) {
|
||||||
if game_data.state == PlayerState::Answered {
|
if game_data.state == PlayerState::Answered {
|
||||||
|
@ -325,7 +325,7 @@ pub fn ui_buttons(
|
||||||
};
|
};
|
||||||
|
|
||||||
if game_data.state == PlayerState::Playing {
|
if game_data.state == PlayerState::Playing {
|
||||||
spawn_cons_lines(commands, meshes, materials, sky, target_cons.clone());
|
spawn_cons_lines(&mut commands, &mut meshes, &mut materials, sky.get_constellation(&target_cons));
|
||||||
}
|
}
|
||||||
|
|
||||||
if target_cons == selected_cons {
|
if target_cons == selected_cons {
|
||||||
|
|
24
src/main.rs
24
src/main.rs
|
@ -141,14 +141,16 @@ fn main() {
|
||||||
.add_systems(Update, game_state::player_interact.run_if(in_state(GameState::Game)))
|
.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).or_else(in_state(GameState::Explo))))
|
.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::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_buttons.run_if(in_state(GameState::Game)))
|
||||||
.add_systems(Update, constellation_opacity.run_if(in_state(GameState::Game)))
|
.add_systems(Update, constellation_opacity.run_if(in_state(GameState::Game).or_else(in_state(GameState::Explo))))
|
||||||
.add_systems(Update, game_state::ui_labels.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>)
|
.add_systems(OnExit(GameState::Game), despawn_screen::<MainGame>)
|
||||||
.add_systems(OnEnter(GameState::End), end_state::setup)
|
.add_systems(OnEnter(GameState::End), end_state::setup)
|
||||||
.add_systems(Update, end_state::player_interact.run_if(in_state(GameState::End)))
|
.add_systems(Update, end_state::player_interact.run_if(in_state(GameState::End)))
|
||||||
.add_systems(OnExit(GameState::End), despawn_screen::<GameOver>)
|
.add_systems(OnExit(GameState::End), despawn_screen::<GameOver>)
|
||||||
|
.add_systems(OnEnter(GameState::Explo), explo_state::setup)
|
||||||
|
.add_systems(Update, explo_state::player_interact.run_if(in_state(GameState::Explo)))
|
||||||
|
.add_systems(OnExit(GameState::Explo), despawn_screen::<MainGame>)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,11 +187,10 @@ fn constellation_opacity(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn spawn_cons_lines(
|
fn spawn_cons_lines(
|
||||||
mut commands: Commands,
|
commands: &mut Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
meshes: &mut ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
materials: &mut ResMut<Assets<StandardMaterial>>,
|
||||||
sky: Res<Sky>,
|
target_constellation: Constellation,
|
||||||
target_constellation_name: String,
|
|
||||||
) {
|
) {
|
||||||
let line_material = materials.add(StandardMaterial {
|
let line_material = materials.add(StandardMaterial {
|
||||||
emissive: LinearRgba::rgb(0.5, 0.5, 1.0),
|
emissive: LinearRgba::rgb(0.5, 0.5, 1.0),
|
||||||
|
@ -197,13 +198,6 @@ fn spawn_cons_lines(
|
||||||
..default()
|
..default()
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut target_constellation = sky.content[0].clone();
|
|
||||||
for constellation in sky.content.clone() {
|
|
||||||
if constellation.name == target_constellation_name {
|
|
||||||
target_constellation = constellation;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut vertices : Vec<Vec3> = vec![];
|
let mut vertices : Vec<Vec3> = vec![];
|
||||||
|
|
||||||
let mut avg_pos : Vec3 = Vec3::ZERO;
|
let mut avg_pos : Vec3 = Vec3::ZERO;
|
||||||
|
@ -231,7 +225,7 @@ fn spawn_cons_lines(
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
ConstellationModel {
|
ConstellationModel {
|
||||||
name: target_constellation_name,
|
name: target_constellation.name,
|
||||||
center: avg_pos,
|
center: avg_pos,
|
||||||
},
|
},
|
||||||
MainGame
|
MainGame
|
||||||
|
|
Loading…
Reference in a new issue