diff options
author | tom barrett <spalf0@gmail.com> | 2019-06-28 08:37:07 -0500 |
---|---|---|
committer | tom barrett <spalf0@gmail.com> | 2019-06-28 08:37:07 -0500 |
commit | 39ea81bea4a61baf8c95a33bcc979b0e65ce660e (patch) | |
tree | e1a535ba04c72c3db630548966ba854388f7848f /src/math.rs | |
parent | a76efb8444af9d4a0ee558e72903c67bc2cff5d3 (diff) |
unified interfaces
Diffstat (limited to 'src/math.rs')
-rw-r--r-- | src/math.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs index c7ea7f6..b6f53ed 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,5 +1,23 @@ +use ggez::graphics::Rect; use std::f32::consts::PI; +use std::time::Instant; pub fn convert_angle_to_rad(angle: f32) -> f32 { angle * (PI / 180.0) } + +pub fn next_source( + source: Rect, + animation: &Option<Vec<(usize, Rect)>>, + timer: Instant, +) -> (Rect, Instant) { + if let Some(animation) = animation { + if let Some(mut i) = animation.iter().position(|a| a.1 == source) { + if timer.elapsed().as_millis() > animation[i].0 as u128 { + i = if i == animation.len() - 1 { 0 } else { i + 1 }; + return (animation[i].1, Instant::now()); + } + } + } + (source, timer) +} |