Improved a few things (i don't remember them)

This commit is contained in:
2025-11-26 20:55:44 +01:00
parent dff435a6d1
commit 7096849b65
4 changed files with 66 additions and 46 deletions
+31
View File
@@ -0,0 +1,31 @@
pub mod threads;
use osmium::{entity::Component, renderer::Point};
pub struct Velocity(pub Point<i32>);
impl Component for Velocity {
fn tick(&mut self, entity: &std::sync::Arc<osmium::entity::Entity>, tick: u16) {
let mut position = entity.position();
apply_velocity(tick, self.0.x, &mut position.x);
apply_velocity(tick, self.0.y, &mut position.y);
}
}
fn apply_velocity(tick: u16, velocity: i32, x: &mut u16) -> bool {
let abs_v = velocity.abs();
if abs_v == 0 {
return false;
}
let interval = (1000 / abs_v).max(1);
if tick as i32 % interval == 0 {
if velocity > 0 {
*x = x.saturating_add(1);
} else {
*x = x.saturating_sub(1);
}
return true;
}
false
}