add achievement for 25 points in time trial race

This commit is contained in:
yuni 2024-11-18 04:52:29 +01:00
parent 61cf744569
commit 192269c766
2 changed files with 29 additions and 3 deletions

View file

@ -24,6 +24,7 @@ pub const CHEAT_WARP_1: &str = "pizzeria";
pub const CHEAT_WARP_2: &str = "busstopclippy2"; pub const CHEAT_WARP_2: &str = "busstopclippy2";
pub const CHEAT_WARP_3: &str = "busstopclippy3"; pub const CHEAT_WARP_3: &str = "busstopclippy3";
pub const RACE_TARGET_RADIUS: f64 = 5.0; pub const RACE_TARGET_RADIUS: f64 = 5.0;
pub const RACE_SCORE_ACHIEVEMENT: u64 = 25;
pub struct GamePlugin; pub struct GamePlugin;
impl Plugin for GamePlugin { impl Plugin for GamePlugin {
@ -85,7 +86,7 @@ pub struct RaceState {
pub started: bool, pub started: bool,
pub start_countdown: f64, pub start_countdown: f64,
pub timeout: f64, pub timeout: f64,
pub score: u64, pub score: f64,
} }
#[derive(Component)] #[derive(Component)]
pub struct RaceTarget; pub struct RaceTarget;
@ -98,6 +99,7 @@ pub enum AchievementEvent {
DrinkPizza, DrinkPizza,
InJupitersShadow, InJupitersShadow,
FindEarth, FindEarth,
RaceScore,
} }
#[derive(Event)] #[derive(Event)]
@ -612,6 +614,12 @@ fn handle_achievement_event(
} }
tracker.find_earth = true; tracker.find_earth = true;
} }
AchievementEvent::RaceScore => {
if !tracker.race_score {
ew_game.send(GameEvent::Achievement(format!("Score {} Points In Time Trial", RACE_SCORE_ACHIEVEMENT)));
}
tracker.race_score = true;
}
AchievementEvent::RideVehicle(name) => { AchievementEvent::RideVehicle(name) => {
tracker.vehicles_ridden.insert(name.clone()); tracker.vehicles_ridden.insert(name.clone());
let len = tracker.vehicles_ridden.len(); let len = tracker.vehicles_ridden.len();
@ -723,6 +731,7 @@ fn handle_race(
mut settings: ResMut<Settings>, mut settings: ResMut<Settings>,
mut race: ResMut<RaceState>, mut race: ResMut<RaceState>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_achievement: EventWriter<game::AchievementEvent>,
q_player: Query<(&Position, &LinearVelocity, &Transform), With<PlayerCamera>>, q_player: Query<(&Position, &LinearVelocity, &Transform), With<PlayerCamera>>,
mut q_racetarget: Query< mut q_racetarget: Query<
(Entity, &mut Position, &mut LinearVelocity, &mut Visibility), (Entity, &mut Position, &mut LinearVelocity, &mut Visibility),
@ -759,18 +768,21 @@ fn handle_race(
if !race.initialized { if !race.initialized {
log.warning("Time Trial Race START!".to_string()); log.warning("Time Trial Race START!".to_string());
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Honk)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Honk));
race.score = 0; race.score = 0.0;
race.initialized = true; race.initialized = true;
spawn_target = true; spawn_target = true;
} }
if player_pos.distance(target_pos.0) < RACE_TARGET_RADIUS { if player_pos.distance(target_pos.0) < RACE_TARGET_RADIUS {
race.score += 1; race.score += 1.0;
spawn_target = true; spawn_target = true;
} }
if spawn_target { if spawn_target {
race.timeout = time.elapsed_seconds_f64() + 5.0; race.timeout = time.elapsed_seconds_f64() + 5.0;
if race.score >= RACE_SCORE_ACHIEVEMENT as f64 {
ew_achievement.send(game::AchievementEvent::RaceScore);
}
let difficulty = 2.0 * race.score as f64; let difficulty = 2.0 * race.score as f64;
let mut delta = DVec3::new(0.0, 0.0, 100.0); let mut delta = DVec3::new(0.0, 0.0, 100.0);
delta = (player_trans.rotation * delta.as_vec3()).as_dvec3(); delta = (player_trans.rotation * delta.as_vec3()).as_dvec3();

View file

@ -388,6 +388,7 @@ pub struct AchievementTracker {
pub drink_a_pizza: bool, pub drink_a_pizza: bool,
pub in_jupiters_shadow: bool, pub in_jupiters_shadow: bool,
pub find_earth: bool, pub find_earth: bool,
pub race_score: bool,
pub ride_every_vehicle: bool, pub ride_every_vehicle: bool,
pub vehicles_ridden: HashSet<String>, pub vehicles_ridden: HashSet<String>,
@ -407,6 +408,7 @@ impl AchievementTracker {
self.talk_to_everyone, self.talk_to_everyone,
self.find_earth, self.find_earth,
self.in_jupiters_shadow, self.in_jupiters_shadow,
self.race_score,
] ]
} }
pub fn achieve_all(&mut self) { pub fn achieve_all(&mut self) {
@ -416,6 +418,7 @@ impl AchievementTracker {
self.talk_to_everyone = true; self.talk_to_everyone = true;
self.find_earth = true; self.find_earth = true;
self.in_jupiters_shadow = true; self.in_jupiters_shadow = true;
self.race_score = true;
} }
pub fn to_textsections(&self) -> Vec<String> { pub fn to_textsections(&self) -> Vec<String> {
fn collectible(current: usize, total: usize) -> String { fn collectible(current: usize, total: usize) -> String {
@ -434,6 +437,10 @@ impl AchievementTracker {
format!("Talk To Everyone{talk}\n"), format!("Talk To Everyone{talk}\n"),
"Find Earth\n".to_string(), "Find Earth\n".to_string(),
"Enter Jupiter's Shadow\n".to_string(), "Enter Jupiter's Shadow\n".to_string(),
format!(
"Score {} Points In Time Trial\n",
game::RACE_SCORE_ACHIEVEMENT
),
] ]
} }
pub fn to_overview(&self) -> Vec<(bool, String)> { pub fn to_overview(&self) -> Vec<(bool, String)> {
@ -444,6 +451,13 @@ impl AchievementTracker {
(self.talk_to_everyone, "talk to everyone".into()), (self.talk_to_everyone, "talk to everyone".into()),
(self.find_earth, "find Earth".into()), (self.find_earth, "find Earth".into()),
(self.in_jupiters_shadow, "enter Jupiter's shadow".into()), (self.in_jupiters_shadow, "enter Jupiter's shadow".into()),
(
self.in_jupiters_shadow,
format!(
"score {} points in Time Trial",
game::RACE_SCORE_ACHIEVEMENT
),
),
] ]
} }
pub fn to_summary(&self) -> String { pub fn to_summary(&self) -> String {