one click buttons + last life view
This commit is contained in:
parent
0baf9f51ba
commit
7a95723c07
28
src/main.rs
28
src/main.rs
|
@ -98,6 +98,7 @@ struct Player {
|
||||||
target_cons_name: Option<String>,
|
target_cons_name: Option<String>,
|
||||||
score: usize,
|
score: usize,
|
||||||
health: usize,
|
health: usize,
|
||||||
|
thinking: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
||||||
|
@ -204,6 +205,7 @@ fn start_ui_setup(mut commands: Commands, _asset_server: Res<AssetServer>) {
|
||||||
target_cons_name: None,
|
target_cons_name: None,
|
||||||
score: 0,
|
score: 0,
|
||||||
health: 3,
|
health: 3,
|
||||||
|
thinking: true,
|
||||||
},
|
},
|
||||||
GameOver,
|
GameOver,
|
||||||
));
|
));
|
||||||
|
@ -472,7 +474,12 @@ fn choose_constellation(
|
||||||
mut button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>, // Query to reset button colors
|
mut button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>, // Query to reset button colors
|
||||||
constellation_line_query : Query<(Entity, &ConstellationLine)>,
|
constellation_line_query : Query<(Entity, &ConstellationLine)>,
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
mut game_state: ResMut<NextState<GameState>>
|
||||||
) {
|
) {
|
||||||
|
if player.health == 0 {
|
||||||
|
info!("dead");
|
||||||
|
game_state.set(GameState::End);
|
||||||
|
}
|
||||||
if sky.content.len() >= 4 {
|
if sky.content.len() >= 4 {
|
||||||
let mut rng = rand::thread_rng();
|
let mut rng = rand::thread_rng();
|
||||||
let mut selected_constellations = sky.content.clone();
|
let mut selected_constellations = sky.content.clone();
|
||||||
|
@ -503,6 +510,8 @@ fn choose_constellation(
|
||||||
for (entity, _line) in constellation_line_query.iter() {
|
for (entity, _line) in constellation_line_query.iter() {
|
||||||
commands.entity(entity).despawn();
|
commands.entity(entity).despawn();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.thinking = true;
|
||||||
} else {
|
} else {
|
||||||
info!("Not enough constellations in the sky (need 4)");
|
info!("Not enough constellations in the sky (need 4)");
|
||||||
}
|
}
|
||||||
|
@ -516,11 +525,12 @@ fn player_input(
|
||||||
button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>, // Query to reset button colors
|
button_query: Query<(&mut BackgroundColor, &mut BorderColor), With<Button>>, // Query to reset button colors
|
||||||
constellation_line_query : Query<(Entity, &ConstellationLine)>,
|
constellation_line_query : Query<(Entity, &ConstellationLine)>,
|
||||||
commands: Commands,
|
commands: Commands,
|
||||||
|
game_state: ResMut<NextState<GameState>>
|
||||||
) {
|
) {
|
||||||
if let Ok((mut player, mut transform)) = player_query.get_single_mut() {
|
if let Ok((mut player, mut transform)) = player_query.get_single_mut() {
|
||||||
// If the space key was just pressed
|
// If the space key was just pressed
|
||||||
if keys.just_pressed(KeyCode::Space) || player.target_cons_name.is_none() {
|
if keys.just_pressed(KeyCode::Space) || player.target_cons_name.is_none() {
|
||||||
choose_constellation(&mut player, sky, text_query, button_query, constellation_line_query, commands);
|
choose_constellation(&mut player, sky, text_query, button_query, constellation_line_query, commands, game_state);
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -609,9 +619,13 @@ fn game_buttons(
|
||||||
commands: Commands,
|
commands: Commands,
|
||||||
meshes: ResMut<Assets<Mesh>>,
|
meshes: ResMut<Assets<Mesh>>,
|
||||||
materials: ResMut<Assets<StandardMaterial>>,
|
materials: ResMut<Assets<StandardMaterial>>,
|
||||||
sky: Res<Sky>,
|
sky: Res<Sky>
|
||||||
mut game_state: ResMut<NextState<GameState>>
|
|
||||||
) {
|
) {
|
||||||
|
if let Ok(mut player) = player_query.get_single_mut() {
|
||||||
|
if !player.thinking {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
let mut pressed_button: Option<String> = None;
|
let mut pressed_button: Option<String> = None;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
|
@ -628,21 +642,17 @@ fn game_buttons(
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(selected_cons) = pressed_button {
|
if let Some(selected_cons) = pressed_button {
|
||||||
if let Ok(mut player) = player_query.get_single_mut() {
|
|
||||||
if let Some(target_cons) = player.target_cons_name.clone() {
|
if let Some(target_cons) = player.target_cons_name.clone() {
|
||||||
spawn_cons_lines(commands, meshes, materials, sky, target_cons.clone());
|
spawn_cons_lines(commands, meshes, materials, sky, target_cons.clone());
|
||||||
|
|
||||||
if target_cons == selected_cons {
|
if target_cons == selected_cons {
|
||||||
info!("success");
|
|
||||||
player.score += 100;
|
player.score += 100;
|
||||||
} else {
|
} else {
|
||||||
player.health -= 1;
|
player.health -= 1;
|
||||||
if player.health == 0 {
|
|
||||||
info!("dead");
|
|
||||||
game_state.set(GameState::End);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
player.thinking = false;
|
||||||
|
|
||||||
for (
|
for (
|
||||||
_interaction,
|
_interaction,
|
||||||
mut color,
|
mut color,
|
||||||
|
|
Loading…
Reference in a new issue