WIP time trial: spawn target in front + implement canceling race
This commit is contained in:
parent
afeba6b63d
commit
d856c8487a
21
src/game.rs
21
src/game.rs
|
@ -722,16 +722,23 @@ 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>,
|
||||||
q_player: Query<(&Position, &LinearVelocity), 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),
|
||||||
(With<RaceTarget>, Without<PlayerCamera>),
|
(With<RaceTarget>, Without<PlayerCamera>),
|
||||||
>,
|
>,
|
||||||
) {
|
) {
|
||||||
|
let mut deinitialize = false;
|
||||||
if !settings.race_active {
|
if !settings.race_active {
|
||||||
|
if race.initialized {
|
||||||
|
log.warning(format!("Stopped race! Final score: {}", race.score));
|
||||||
|
deinitialize = true;
|
||||||
|
} else {
|
||||||
return;
|
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
|
val
|
||||||
} else {
|
} else {
|
||||||
error!("No player found in handle_race!");
|
error!("No player found in handle_race!");
|
||||||
|
@ -745,6 +752,7 @@ fn handle_race(
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !deinitialize {
|
||||||
let mut spawn_target = false;
|
let mut spawn_target = false;
|
||||||
|
|
||||||
if !race.initialized {
|
if !race.initialized {
|
||||||
|
@ -762,7 +770,9 @@ fn handle_race(
|
||||||
|
|
||||||
if spawn_target {
|
if spawn_target {
|
||||||
race.timeout = time.elapsed_seconds_f64() + 5.0;
|
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_v = *player_v;
|
||||||
*target_vis = Visibility::Inherited;
|
*target_vis = Visibility::Inherited;
|
||||||
commands.entity(target_entity).insert(RigidBody::Kinematic);
|
commands.entity(target_entity).insert(RigidBody::Kinematic);
|
||||||
|
@ -770,6 +780,11 @@ fn handle_race(
|
||||||
|
|
||||||
if race.timeout <= time.elapsed_seconds_f64() {
|
if race.timeout <= time.elapsed_seconds_f64() {
|
||||||
log.warning(format!("GAME OVER! Final score: {}", race.score));
|
log.warning(format!("GAME OVER! Final score: {}", race.score));
|
||||||
|
deinitialize = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if deinitialize {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerDown));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::PowerDown));
|
||||||
race.initialized = false;
|
race.initialized = false;
|
||||||
settings.race_active = false;
|
settings.race_active = false;
|
||||||
|
|
|
@ -787,7 +787,7 @@ pub fn handle_input(
|
||||||
ew_updatemenu.send(UpdateMenuEvent);
|
ew_updatemenu.send(UpdateMenuEvent);
|
||||||
}
|
}
|
||||||
MenuAction::Race => {
|
MenuAction::Race => {
|
||||||
settings.race_active = true;
|
settings.race_active ^= true;
|
||||||
ew_game.send(GameEvent::SetMenu(Turn::Off));
|
ew_game.send(GameEvent::SetMenu(Turn::Off));
|
||||||
ew_updatemenu.send(UpdateMenuEvent);
|
ew_updatemenu.send(UpdateMenuEvent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue