better hints
This commit is contained in:
parent
ba17c16042
commit
bd704008f2
|
@ -7,8 +7,15 @@ pub fn player_mouse_move (
|
||||||
buttons: Res<ButtonInput<MouseButton>>,
|
buttons: Res<ButtonInput<MouseButton>>,
|
||||||
mut player_query: Query<(&mut Player, &Camera, &mut GlobalTransform)>,
|
mut player_query: Query<(&mut Player, &Camera, &mut GlobalTransform)>,
|
||||||
window_query: Query<&Window, With<bevy::window::PrimaryWindow>>,
|
window_query: Query<&Window, With<bevy::window::PrimaryWindow>>,
|
||||||
|
ui_query: Query<&Interaction, With<Button>>,
|
||||||
) {
|
) {
|
||||||
info!("-");
|
for interaction in ui_query.iter() {
|
||||||
|
if *interaction == Interaction::Pressed {
|
||||||
|
// Button clicked
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let Ok((mut player, camera, global_transform)) = player_query.get_single_mut() else {
|
let Ok((mut player, camera, global_transform)) = player_query.get_single_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,6 @@ use crate::MainGame;
|
||||||
use crate::Sky;
|
use crate::Sky;
|
||||||
use crate::Constellation;
|
use crate::Constellation;
|
||||||
use crate::ConstellationLine;
|
use crate::ConstellationLine;
|
||||||
use crate::PlayerState;
|
|
||||||
use crate::GameData;
|
|
||||||
|
|
||||||
use crate::celestial_to_cartesian;
|
use crate::celestial_to_cartesian;
|
||||||
use crate::spawn_cons_lines;
|
use crate::spawn_cons_lines;
|
||||||
|
@ -30,6 +28,37 @@ pub struct ScoreLabel;
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct HintLabel;
|
pub struct HintLabel;
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct GameData {
|
||||||
|
content: Vec<String>,
|
||||||
|
pub score: usize,
|
||||||
|
health: usize,
|
||||||
|
state: PlayerState,
|
||||||
|
target_cons_name: Option<String>,
|
||||||
|
target_cons_focused: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for GameData {
|
||||||
|
fn default() -> Self {
|
||||||
|
GameData {
|
||||||
|
content: vec![],
|
||||||
|
score: 0,
|
||||||
|
health: 3,
|
||||||
|
state: PlayerState::Playing,
|
||||||
|
target_cons_name: None,
|
||||||
|
target_cons_focused: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default, PartialEq, Debug)]
|
||||||
|
enum PlayerState {
|
||||||
|
#[default]
|
||||||
|
Playing,
|
||||||
|
Hinted,
|
||||||
|
Answered,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setup(
|
pub fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut game_data: ResMut<GameData>,
|
mut game_data: ResMut<GameData>,
|
||||||
|
@ -186,6 +215,10 @@ pub fn player_interact(
|
||||||
return
|
return
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if player.dragging_pos.is_some() {
|
||||||
|
game_data.target_cons_focused = false;
|
||||||
|
}
|
||||||
|
|
||||||
if keys.just_pressed(KeyCode::Space) || game_data.target_cons_name.is_none() {
|
if keys.just_pressed(KeyCode::Space) || game_data.target_cons_name.is_none() {
|
||||||
choose_constellation(&mut player, sky, text_query, button_query, constellation_line_query, commands, game_state, game_data);
|
choose_constellation(&mut player, sky, text_query, button_query, constellation_line_query, commands, game_state, game_data);
|
||||||
return
|
return
|
||||||
|
@ -195,61 +228,53 @@ pub fn player_interact(
|
||||||
game_state.set(GameState::Start);
|
game_state.set(GameState::Start);
|
||||||
}
|
}
|
||||||
|
|
||||||
if keys.pressed(KeyCode::KeyI) && game_data.state == PlayerState::Playing {
|
if keys.pressed(KeyCode::KeyI) {
|
||||||
if let Some(target_cons) = game_data.target_cons_name.clone() {
|
if game_data.state != PlayerState::Playing {
|
||||||
game_data.state = PlayerState::Hinted;
|
info!("Invalid state : {:?}", game_data.state);
|
||||||
spawn_cons_lines(commands, meshes, materials, sky, target_cons);
|
}
|
||||||
return
|
let Some(target_cons) = game_data.target_cons_name.clone() else {
|
||||||
}
|
return;
|
||||||
|
};
|
||||||
|
game_data.state = PlayerState::Hinted;
|
||||||
|
spawn_cons_lines(commands, meshes, materials, sky, target_cons);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if keys.pressed(KeyCode::KeyR) {
|
|
||||||
if let Some(target_constellation_name) = game_data.target_cons_name.clone() {
|
|
||||||
let mut target_constellation = sky.content[0].clone();
|
|
||||||
for constellation in sky.content.clone() {
|
|
||||||
if constellation.name == target_constellation_name {
|
|
||||||
target_constellation = constellation
|
|
||||||
}
|
|
||||||
}
|
|
||||||
player.target_rotation = Some(constellation_center(target_constellation));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if keys.pressed(KeyCode::KeyW) {
|
if keys.pressed(KeyCode::KeyW) {
|
||||||
let target_constellation_name: String = "Ursa Minor".into();
|
game_data.target_cons_focused = true;
|
||||||
|
let Some(target_constellation_name) = game_data.target_cons_name.clone() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
let mut target_constellation = sky.content[0].clone();
|
let mut target_constellation = sky.content[0].clone();
|
||||||
for constellation in sky.content.clone() {
|
for constellation in sky.content.clone() {
|
||||||
if constellation.name == target_constellation_name {
|
if constellation.name == target_constellation_name {
|
||||||
target_constellation = constellation
|
target_constellation = constellation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
player.target_rotation = Some(constellation_center(target_constellation));
|
player.target_rotation = Some(constellation_center(target_constellation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui_labels(
|
pub fn ui_labels(
|
||||||
mut param_set: ParamSet<(
|
mut label_query: Query<(&mut Text, Option<&HealthLabel>, Option<&ScoreLabel>, Option<&HintLabel>)>,
|
||||||
Query<&mut Text, With<HealthLabel>>,
|
|
||||||
Query<&mut Text, With<ScoreLabel>>,
|
|
||||||
Query<&mut Text, With<HintLabel>>,
|
|
||||||
)>,
|
|
||||||
game_data: Res<GameData>
|
game_data: Res<GameData>
|
||||||
) {
|
) {
|
||||||
if let Ok(mut health_text) = param_set.p0().get_single_mut() {
|
|
||||||
health_text.sections[0].value = "# ".repeat(game_data.health);
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(mut score_text) = param_set.p1().get_single_mut() {
|
for (mut text, health_label, score_label, hint_label) in label_query.iter_mut() {
|
||||||
score_text.sections[0].value = format!("{}", game_data.score);
|
if health_label.is_some() {
|
||||||
}
|
text.sections[0].value = "# ".repeat(game_data.health);
|
||||||
|
} else if score_label.is_some() {
|
||||||
if let Ok(mut hint_text) = param_set.p2().get_single_mut() {
|
text.sections[0].value = format!("{}", game_data.score);
|
||||||
if game_data.state == PlayerState::Answered {
|
} else if hint_label.is_some() {
|
||||||
hint_text.sections[0].value = "press space to continue".into();
|
if !game_data.target_cons_focused {
|
||||||
} else {
|
text.sections[0].value = "press z to re-center".into();
|
||||||
hint_text.sections[0].value = "press i to get an hint".into();
|
} else if game_data.state == PlayerState::Playing {
|
||||||
|
text.sections[0].value = "press i to get an hint".into();
|
||||||
|
} else if game_data.state == PlayerState::Answered {
|
||||||
|
text.sections[0].value = "press space to continue".into();
|
||||||
|
} else {
|
||||||
|
text.sections[0].value = "guess the constellation".into();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,6 +411,7 @@ fn choose_constellation(
|
||||||
}
|
}
|
||||||
|
|
||||||
game_data.state = PlayerState::Playing;
|
game_data.state = PlayerState::Playing;
|
||||||
|
game_data.target_cons_focused = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn constellation_center(target_constellation: Constellation) -> Quat {
|
fn constellation_center(target_constellation: Constellation) -> Quat {
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -10,6 +10,8 @@ mod start_state;
|
||||||
mod game_state;
|
mod game_state;
|
||||||
mod explo_state;
|
mod explo_state;
|
||||||
|
|
||||||
|
use game_state::GameData;
|
||||||
|
|
||||||
const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
|
const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
|
||||||
const WRONG_BUTTON: Color = Color::srgb(0.50, 0.15, 0.15);
|
const WRONG_BUTTON: Color = Color::srgb(0.50, 0.15, 0.15);
|
||||||
const RIGHT_BUTTON: Color = Color::srgb(0.15, 0.50, 0.15);
|
const RIGHT_BUTTON: Color = Color::srgb(0.15, 0.50, 0.15);
|
||||||
|
@ -109,35 +111,6 @@ struct Player {
|
||||||
dragging_pos: Option<Vec2>,
|
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]
|
|
||||||
Playing,
|
|
||||||
Hinted,
|
|
||||||
Answered,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
#[derive(Clone, Copy, Default, Eq, PartialEq, Debug, Hash, States)]
|
||||||
enum GameState {
|
enum GameState {
|
||||||
#[default]
|
#[default]
|
||||||
|
|
Loading…
Reference in a new issue