Проектная работа - WIP

This commit is contained in:
4 changed files with 71 additions and 8 deletions
+43 -2
View File
@@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::domain::{Direction, Head};
use crate::domain::{Direction, GRID_SIZE, Head, Inert, Velocity};
pub fn head_rotation(
input: Res<ButtonInput<KeyCode>>,
@@ -20,4 +20,45 @@ pub fn head_rotation(
}
}
pub fn moving() {}
pub fn moving(time: Res<Time>, query: Query<(&mut Transform, &mut Inert, &Direction, &Velocity)>) {
for (mut transform, mut inert, direction, Velocity(velocity)) in query.into_iter() {
let delta = velocity * time.delta_secs();
if inert.0 == *direction {
todo!()
} else {
let inert_vec = inert.0.vector();
let delta_vec = inert_vec * delta;
let ovf_vec = vec2(
get_overflow(GRID_SIZE as f32, transform.translation.x, delta_vec.x),
get_overflow(GRID_SIZE as f32, transform.translation.y, delta_vec.y),
);
todo!()
}
todo!()
}
}
fn get_overflow(grid: f32, coord: f32, delta: f32) -> f32 {
let rem = coord % grid;
let rem = if rem < 0.0 { grid + rem } else { rem };
let new = rem + delta;
if new >= 0.0 && new <= grid {
0.0
} else {
new % grid
}
}
#[cfg(test)]
mod test {
use crate::gameplay::get_overflow;
#[test]
fn test_get_overflow() {
assert_eq!(get_overflow(5.0, -6.0, 3.0), 2.0);
assert_eq!(get_overflow(5.0, 6.0, 3.0), 0.0);
assert_eq!(get_overflow(5.0, -6.0, -3.0), 0.0);
assert_eq!(get_overflow(5.0, 6.0, -3.0), -2.0);
}
}