-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
118 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use bevy::prelude::*; | ||
|
||
/// Helper for building triggers that have firing conditions governed by elapsed time. | ||
#[derive(Default, Debug)] | ||
pub struct HeldTimer { | ||
/// If set to `true`, [`Time::relative_speed`] will be applied to the held duration. | ||
/// | ||
/// By default is set to `false`. | ||
pub relative_to_speed: bool, | ||
|
||
duration: f32, | ||
} | ||
|
||
impl HeldTimer { | ||
pub fn relative_to_speed(relative_to_speed: bool) -> Self { | ||
Self { | ||
relative_to_speed, | ||
duration: 0.0, | ||
} | ||
} | ||
|
||
pub fn update(&mut self, world: &World, mut delta: f32) { | ||
if self.relative_to_speed { | ||
let time = world.resource::<Time<Virtual>>(); | ||
delta *= time.relative_speed() | ||
} | ||
|
||
self.duration += delta; | ||
} | ||
|
||
pub fn reset(&mut self) { | ||
self.duration = 0.0; | ||
} | ||
|
||
pub fn duration(&self) -> f32 { | ||
self.duration | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.