explore constellations

This commit is contained in:
WanderingPenwing 2024-10-07 22:25:58 +02:00
parent 26e54d05cf
commit b20579f22b
3 changed files with 30 additions and 30 deletions

View file

@ -2,13 +2,19 @@ use bevy::prelude::*;
use crate::Player;
use crate::GameState;
use crate::Sky;
use crate::spawn_cons_lines;
// pub fn setup (
//
// ) {
// for
// spawn_cons_lines(commands, meshes, materials, sky, target_cons.clone());
// }
pub fn setup (
sky : Res<Sky>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
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 (
buttons: Res<ButtonInput<MouseButton>>,

View file

@ -206,10 +206,10 @@ pub fn player_interact(
text_query: Query<&mut Text, With<AnswerButton>>,
button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>,
constellation_line_query : Query<(Entity, &ConstellationModel)>,
commands: Commands,
mut game_state: ResMut<NextState<GameState>>,
meshes: ResMut<Assets<Mesh>>,
materials: ResMut<Assets<StandardMaterial>>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
let Ok(mut player) = player_query.get_single_mut() else {
return
@ -236,7 +236,7 @@ pub fn player_interact(
return;
};
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;
}
@ -292,9 +292,9 @@ pub fn ui_buttons(
>,
mut text_query: Query<&mut Text, With<AnswerButton>>,
mut game_data: ResMut<GameData>,
commands: Commands,
meshes: ResMut<Assets<Mesh>>,
materials: ResMut<Assets<StandardMaterial>>,
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
sky: Res<Sky>
) {
if game_data.state == PlayerState::Answered {
@ -325,7 +325,7 @@ pub fn ui_buttons(
};
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 {

View file

@ -141,14 +141,16 @@ fn main() {
.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::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, 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(OnExit(GameState::Game), despawn_screen::<MainGame>)
.add_systems(OnEnter(GameState::End), end_state::setup)
.add_systems(Update, end_state::player_interact.run_if(in_state(GameState::End)))
.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();
}
@ -185,25 +187,17 @@ fn constellation_opacity(
}
fn spawn_cons_lines(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
sky: Res<Sky>,
target_constellation_name: String,
commands: &mut Commands,
meshes: &mut ResMut<Assets<Mesh>>,
materials: &mut ResMut<Assets<StandardMaterial>>,
target_constellation: Constellation,
) {
let line_material = materials.add(StandardMaterial {
emissive: LinearRgba::rgb(0.5, 0.5, 1.0),
alpha_mode: AlphaMode::Blend,
..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 avg_pos : Vec3 = Vec3::ZERO;
@ -231,7 +225,7 @@ fn spawn_cons_lines(
..default()
},
ConstellationModel {
name: target_constellation_name,
name: target_constellation.name,
center: avg_pos,
},
MainGame