Skip to content

Commit

Permalink
Merge pull request #19 from slindaue/sll/useLatest-rusty_time
Browse files Browse the repository at this point in the history
Use latest version of rusty_timer
  • Loading branch information
CleanCut committed Jan 19, 2024
2 parents 576f155 + a2a06f3 commit 5df8468
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ license = "MIT OR Apache-2.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
crossterm = "0.26.1"
crossterm = "0.27.0"
rusty_audio = "1.2"
rusty_time = "0.12"
rusty_time = "1.1.0"
16 changes: 8 additions & 8 deletions src/invaders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
frame::{Drawable, Frame},
{NUM_COLS, NUM_ROWS},
};
use rusty_time::timer::Timer;
use rusty_time::Timer;
use std::{cmp::max, time::Duration};

pub struct Invader {
Expand Down Expand Up @@ -38,13 +38,13 @@ impl Invaders {
Self {
army,
total_count,
move_timer: Timer::from_millis(2000),
move_timer: Timer::new(Duration::from_millis(2000)),
direction: 1,
}
}
pub fn update(&mut self, delta: Duration) -> bool {
self.move_timer.update(delta);
if self.move_timer.ready {
self.move_timer.tick(delta);
if self.move_timer.finished() {
self.move_timer.reset();
let mut downwards = false;
if self.direction == -1 {
Expand All @@ -61,8 +61,8 @@ impl Invaders {
}
}
if downwards {
let new_duration = max(self.move_timer.duration.as_millis() - 250, 250);
self.move_timer = Timer::from_millis(new_duration as u64);
let new_duration = max(self.move_timer.duration().as_millis() - 250, 250);
self.move_timer.set_duration(Duration::from_millis(new_duration as u64));
for invader in self.army.iter_mut() {
invader.y += 1;
}
Expand Down Expand Up @@ -105,8 +105,8 @@ impl Default for Invaders {
impl Drawable for Invaders {
fn draw(&self, frame: &mut Frame) {
for invader in self.army.iter() {
frame[invader.x][invader.y] = if (self.move_timer.time_left.as_secs_f32()
/ self.move_timer.duration.as_secs_f32())
frame[invader.x][invader.y] = if (self.move_timer.remaining().as_secs_f32()
/ self.move_timer.duration().as_secs_f32())
> 0.5
{
'x'
Expand Down
12 changes: 6 additions & 6 deletions src/shot.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::frame::{Drawable, Frame};
use rusty_time::timer::Timer;
use rusty_time::Timer;
use std::time::Duration;

pub struct Shot {
Expand All @@ -15,12 +15,12 @@ impl Shot {
x,
y,
exploding: false,
timer: Timer::from_millis(50),
timer: Timer::new(Duration::from_millis(50)),
}
}
pub fn update(&mut self, delta: Duration) {
self.timer.update(delta);
if self.timer.ready && !self.exploding {
self.timer.tick(delta);
if self.timer.finished() && !self.exploding {
if self.y > 0 {
self.y -= 1;
}
Expand All @@ -29,10 +29,10 @@ impl Shot {
}
pub fn explode(&mut self) {
self.exploding = true;
self.timer = Timer::from_millis(250);
self.timer = Timer::new(Duration::from_millis(250));
}
pub fn dead(&self) -> bool {
(self.exploding && self.timer.ready) || (self.y == 0)
(self.exploding && self.timer.finished()) || (self.y == 0)
}
}

Expand Down

0 comments on commit 5df8468

Please sign in to comment.