do not repeat already guessed cons
This commit is contained in:
parent
447dfc9f22
commit
a00a66ab1e
|
@ -33,6 +33,8 @@ pub struct HintLabel;
|
|||
|
||||
pub fn setup(
|
||||
mut commands: Commands,
|
||||
mut game_data: ResMut<GameData>,
|
||||
sky: Res<Sky>,
|
||||
) {
|
||||
let container_node = NodeBundle {
|
||||
style: Style {
|
||||
|
@ -162,6 +164,9 @@ pub fn setup(
|
|||
let hint_label = commands.spawn((hint_label_node, MainGame, HintLabel)).id();
|
||||
|
||||
commands.entity(centered_container).push_children(&[hint_label]);
|
||||
|
||||
*game_data = GameData::default();
|
||||
game_data.content = sky.as_string();
|
||||
}
|
||||
|
||||
|
||||
|
@ -330,6 +335,8 @@ pub fn ui_buttons(
|
|||
game_data.health -= 1;
|
||||
}
|
||||
|
||||
game_data.content.retain(|x| x != &target_cons);
|
||||
|
||||
game_data.state = PlayerState::Answered;
|
||||
|
||||
for (
|
||||
|
@ -369,14 +376,18 @@ fn choose_constellation(
|
|||
if game_data.health == 0 {
|
||||
game_state.set(GameState::End);
|
||||
}
|
||||
if sky.content.len() >= 4 {
|
||||
|
||||
if game_data.content.len() < 4 {
|
||||
game_state.set(GameState::End);
|
||||
}
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
let mut selected_constellations = sky.content.clone();
|
||||
selected_constellations.shuffle(&mut rng);
|
||||
let constellations = &selected_constellations[0..4];
|
||||
let mut cons_names = game_data.content.clone();
|
||||
cons_names.shuffle(&mut rng);
|
||||
let selected_cons_names = &cons_names[0..4];
|
||||
|
||||
let target_index = rng.next_u32().rem_euclid(4) as usize;
|
||||
let target_constellation = &constellations[target_index];
|
||||
let target_constellation = sky.get_constellation(&selected_cons_names[target_index]);
|
||||
|
||||
player.target_rotation = Some(constellation_center(target_constellation.clone()));
|
||||
game_data.target_cons_name = Some(target_constellation.name.clone());
|
||||
|
@ -384,7 +395,7 @@ fn choose_constellation(
|
|||
info!("Target constellation: {}", target_constellation.name);
|
||||
|
||||
for (i, mut text) in text_query.iter_mut().enumerate() {
|
||||
text.sections[0].value = constellations[i].name.clone();
|
||||
text.sections[0].value = selected_cons_names[i].clone();
|
||||
}
|
||||
|
||||
for (mut bg_color, mut border_color) in &mut button_query {
|
||||
|
@ -397,9 +408,6 @@ fn choose_constellation(
|
|||
}
|
||||
|
||||
game_data.state = PlayerState::Playing;
|
||||
} else {
|
||||
info!("Not enough constellations in the sky (need 4)");
|
||||
}
|
||||
}
|
||||
|
||||
fn constellation_center(target_constellation: Constellation) -> Quat {
|
||||
|
|
51
src/main.rs
51
src/main.rs
|
@ -41,30 +41,28 @@ struct StarData {
|
|||
name: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
#[derive(Resource, Default, Clone)]
|
||||
struct Sky {
|
||||
content: Vec<Constellation>,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GameData {
|
||||
seen: Vec<Constellation>,
|
||||
score: usize,
|
||||
health: usize,
|
||||
state: PlayerState,
|
||||
target_cons_name: Option<String>,
|
||||
impl Sky {
|
||||
fn as_string(&self) -> Vec<String> {
|
||||
let mut cons_names : Vec<String> = vec![];
|
||||
for cons in self.content.clone() {
|
||||
cons_names.push(cons.name.clone());
|
||||
}
|
||||
return cons_names;
|
||||
}
|
||||
|
||||
impl Default for GameData {
|
||||
fn default() -> Self {
|
||||
GameData {
|
||||
seen: vec![],
|
||||
score: 0,
|
||||
health: 3,
|
||||
state: PlayerState::Playing,
|
||||
target_cons_name: None,
|
||||
fn get_constellation(&self, name: &str) -> Constellation {
|
||||
for cons in self.content.clone() {
|
||||
if &cons.name == name {
|
||||
return cons;
|
||||
}
|
||||
}
|
||||
return self.content[0].clone();
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
|
@ -111,6 +109,27 @@ struct Player {
|
|||
dragging_pos: Option<Vec2>,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
struct GameData {
|
||||
content: Vec<String>,
|
||||
score: usize,
|
||||
health: usize,
|
||||
state: PlayerState,
|
||||
target_cons_name: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for GameData {
|
||||
fn default() -> Self {
|
||||
GameData {
|
||||
content: vec![],
|
||||
score: 0,
|
||||
health: 3,
|
||||
state: PlayerState::Playing,
|
||||
target_cons_name: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq)]
|
||||
enum PlayerState {
|
||||
#[default]
|
||||
|
|
|
@ -3,7 +3,6 @@ use std::f64::consts::PI;
|
|||
//use bevy::input::mouse::MouseMotion;
|
||||
use crate::GameState;
|
||||
use crate::StartMenu;
|
||||
use crate::GameData;
|
||||
use crate::Player;
|
||||
|
||||
#[derive(Component)]
|
||||
|
@ -19,7 +18,6 @@ pub fn audio_setup(asset_server: Res<AssetServer>, mut commands: Commands) {
|
|||
|
||||
pub fn setup(
|
||||
mut commands: Commands,
|
||||
mut game_data: ResMut<GameData>
|
||||
) {
|
||||
let container_node = NodeBundle {
|
||||
style: Style {
|
||||
|
@ -63,8 +61,6 @@ pub fn setup(
|
|||
let bottom_text = commands.spawn((bottom_text_node, StartMenu)).id();
|
||||
|
||||
commands.entity(container).push_children(&[top_text, bottom_text]);
|
||||
|
||||
*game_data = GameData::default();
|
||||
}
|
||||
|
||||
pub fn player_interact(
|
||||
|
|
Loading…
Reference in a new issue