Compare commits
No commits in common. "43b163fbd90dace43aad4fa10b8bf26992497c20" and "1837591ba52547ed3cb7ebad27c8aa43b392b06d" have entirely different histories.
43b163fbd9
...
1837591ba5
11
src/core.rs
11
src/core.rs
|
@ -479,17 +479,6 @@ impl From<&dyn PointLike> for (i32, i32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TransformExt {
|
|
||||||
fn yaw(&self) -> Angle;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TransformExt for Transform {
|
|
||||||
fn yaw(&self) -> Angle {
|
|
||||||
let forward = self.right();
|
|
||||||
Angle::Radians(forward.y.atan2(forward.x))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait GlobalTransformExt {
|
pub trait GlobalTransformExt {
|
||||||
fn yaw(&self) -> Angle;
|
fn yaw(&self) -> Angle;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ struct SnapTimer(Timer);
|
||||||
|
|
||||||
impl Default for SnapTimer {
|
impl Default for SnapTimer {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self(Timer::from_seconds(0.2, false))
|
Self(Timer::from_seconds(0.25, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,9 +171,8 @@ fn snap(
|
||||||
>,
|
>,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
for (entity, actions, mut transform, mut velocity, direction) in query.iter_mut() {
|
for (entity, actions, mut transform, mut velocity, direction) in query.iter_mut() {
|
||||||
if snap_timers.contains_key(&entity) {
|
if actions.just_pressed(NavigationAction::SnapLeft) {
|
||||||
continue;
|
println!("snap left");
|
||||||
} else if actions.pressed(NavigationAction::SnapLeft) {
|
|
||||||
snap_timers.insert(entity, SnapTimer::default());
|
snap_timers.insert(entity, SnapTimer::default());
|
||||||
transform.rotation = Quat::from_rotation_z(match direction {
|
transform.rotation = Quat::from_rotation_z(match direction {
|
||||||
CardinalDirection::North => PI,
|
CardinalDirection::North => PI,
|
||||||
|
@ -182,7 +181,9 @@ fn snap(
|
||||||
CardinalDirection::West => -PI / 2.,
|
CardinalDirection::West => -PI / 2.,
|
||||||
});
|
});
|
||||||
velocity.angvel = 0.;
|
velocity.angvel = 0.;
|
||||||
} else if actions.pressed(NavigationAction::SnapRight) {
|
}
|
||||||
|
if actions.just_pressed(NavigationAction::SnapRight) {
|
||||||
|
println!("Snap right");
|
||||||
snap_timers.insert(entity, SnapTimer::default());
|
snap_timers.insert(entity, SnapTimer::default());
|
||||||
transform.rotation = Quat::from_rotation_z(match direction {
|
transform.rotation = Quat::from_rotation_z(match direction {
|
||||||
CardinalDirection::North => 0.,
|
CardinalDirection::North => 0.,
|
||||||
|
@ -191,15 +192,18 @@ fn snap(
|
||||||
CardinalDirection::West => PI / 2.,
|
CardinalDirection::West => PI / 2.,
|
||||||
});
|
});
|
||||||
velocity.angvel = 0.;
|
velocity.angvel = 0.;
|
||||||
} else if actions.pressed(NavigationAction::SnapReverse) {
|
}
|
||||||
|
if actions.just_pressed(NavigationAction::SnapCardinal) {
|
||||||
snap_timers.insert(entity, SnapTimer::default());
|
snap_timers.insert(entity, SnapTimer::default());
|
||||||
transform.rotate(Quat::from_rotation_z(PI));
|
|
||||||
velocity.angvel = 0.;
|
|
||||||
} else if actions.pressed(NavigationAction::SnapCardinal) {
|
|
||||||
let yaw: Angle = direction.into();
|
let yaw: Angle = direction.into();
|
||||||
let yaw = yaw.radians();
|
let yaw = yaw.radians();
|
||||||
transform.rotation = Quat::from_rotation_z(yaw);
|
transform.rotation = Quat::from_rotation_z(yaw);
|
||||||
|
velocity.angvel = 0.;
|
||||||
tts.speak(direction.to_string(), true)?;
|
tts.speak(direction.to_string(), true)?;
|
||||||
|
}
|
||||||
|
if actions.just_pressed(NavigationAction::SnapReverse) {
|
||||||
|
snap_timers.insert(entity, SnapTimer::default());
|
||||||
|
transform.rotate(Quat::from_rotation_z(PI));
|
||||||
velocity.angvel = 0.;
|
velocity.angvel = 0.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,19 +237,13 @@ fn update_direction(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remove_direction(
|
fn remove_direction(mut commands: Commands, removed: RemovedComponents<Transform>) {
|
||||||
mut commands: Commands,
|
|
||||||
removed: RemovedComponents<Transform>,
|
|
||||||
directions: Query<&CardinalDirection>,
|
|
||||||
) {
|
|
||||||
for entity in removed.iter() {
|
for entity in removed.iter() {
|
||||||
if directions.contains(entity) {
|
|
||||||
commands.run_if_exists(entity, |mut entity| {
|
commands.run_if_exists(entity, |mut entity| {
|
||||||
entity.remove::<CardinalDirection>();
|
entity.remove::<CardinalDirection>();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn speak_direction(
|
fn speak_direction(
|
||||||
mut tts: ResMut<Tts>,
|
mut tts: ResMut<Tts>,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user