WIP time trial: spawn target in front + implement canceling race

This commit is contained in:
yuni 2024-11-18 04:02:12 +01:00
parent afeba6b63d
commit d856c8487a
2 changed files with 41 additions and 26 deletions

View file

@ -722,16 +722,23 @@ fn handle_race(
mut settings: ResMut<Settings>,
mut race: ResMut<RaceState>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_player: Query<(&Position, &LinearVelocity), With<PlayerCamera>>,
q_player: Query<(&Position, &LinearVelocity, &Transform), With<PlayerCamera>>,
mut q_racetarget: Query<
(Entity, &mut Position, &mut LinearVelocity, &mut Visibility),
(With<RaceTarget>, Without<PlayerCamera>),
>,
) {
let mut deinitialize = false;
if !settings.race_active {
if race.initialized {
log.warning(format!("Stopped race! Final score: {}", race.score));
deinitialize = true;
} else {
return;
}
let (player_pos, player_v) = if let Ok(val) = q_player.get_single() {
}
let (player_pos, player_v, player_trans) = if let Ok(val) = q_player.get_single() {
val
} else {
error!("No player found in handle_race!");
@ -745,6 +752,7 @@ fn handle_race(
return;
};
if !deinitialize {
let mut spawn_target = false;
if !race.initialized {
@ -762,7 +770,9 @@ fn handle_race(
if spawn_target {
race.timeout = time.elapsed_seconds_f64() + 5.0;
*target_pos = Position(player_pos.0 + DVec3::new(100.0, 0.0, 0.0));
let mut delta = DVec3::new(0.0, 0.0, 100.0);
delta = (player_trans.rotation * delta.as_vec3()).as_dvec3();
*target_pos = Position(player_pos.0 + delta);
*target_v = *player_v;
*target_vis = Visibility::Inherited;
commands.entity(target_entity).insert(RigidBody::Kinematic);
@ -770,6 +780,11 @@ fn handle_race(
if race.timeout <= time.elapsed_seconds_f64() {
log.warning(format!("GAME OVER! Final score: {}", race.score));
deinitialize = true;
}
}
if deinitialize {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerDown));
race.initialized = false;
settings.race_active = false;

View file

@ -787,7 +787,7 @@ pub fn handle_input(
ew_updatemenu.send(UpdateMenuEvent);
}
MenuAction::Race => {
settings.race_active = true;
settings.race_active ^= true;
ew_game.send(GameEvent::SetMenu(Turn::Off));
ew_updatemenu.send(UpdateMenuEvent);
}