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

This commit is contained in:
4 changed files with 17 additions and 9 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
pub const FRAMES_PER_SECOND: u8 = 24; pub const FRAMES_PER_SECOND: u8 = 2;
pub const GRID_SIZE: u8 = 48; pub const GRID_SIZE: u8 = 48;
pub const HEAD_SIZE: u8 = (GRID_SIZE as f32 * 1.1) as u8; pub const HEAD_SIZE: u8 = (GRID_SIZE as f32 * 1.1) as u8;
pub const SNAKE_VELOCITY: u8 = (GRID_SIZE as f32 / 1.0) as u8; pub const SNAKE_VELOCITY: u8 = (GRID_SIZE as f32 / 1.0) as u8;
@@ -10,7 +10,7 @@ pub const SNAKE_VELOCITY: u8 = (GRID_SIZE as f32 / 1.0) as u8;
pub struct Head; pub struct Head;
/// Направление движения /// Направление движения
#[derive(Component, PartialEq)] #[derive(Component, PartialEq, Clone, Copy)]
pub enum Direction { pub enum Direction {
Up, Up,
Left, Left,
+12 -4
View File
@@ -24,7 +24,9 @@ pub fn moving(time: Res<Time>, query: Query<(&mut Transform, &mut Inert, &Direct
for (mut transform, mut inert, direction, Velocity(velocity)) in query.into_iter() { for (mut transform, mut inert, direction, Velocity(velocity)) in query.into_iter() {
let delta = velocity * time.delta_secs(); let delta = velocity * time.delta_secs();
if inert.0 == *direction { if inert.0 == *direction {
todo!() let inert_vec = inert.0.vector();
let delta_vec = inert_vec * delta;
transform.translation += delta_vec.extend(0.0);
} else { } else {
let inert_vec = inert.0.vector(); let inert_vec = inert.0.vector();
let delta_vec = inert_vec * delta; let delta_vec = inert_vec * delta;
@@ -32,10 +34,16 @@ pub fn moving(time: Res<Time>, query: Query<(&mut Transform, &mut Inert, &Direct
get_overflow(GRID_SIZE as f32, transform.translation.x, delta_vec.x), get_overflow(GRID_SIZE as f32, transform.translation.x, delta_vec.x),
get_overflow(GRID_SIZE as f32, transform.translation.y, delta_vec.y), get_overflow(GRID_SIZE as f32, transform.translation.y, delta_vec.y),
); );
transform.translation += delta_vec.extend(0.0);
todo!() if ovf_vec.x != 0. && ovf_vec.y != 0. {
transform.translation -= ovf_vec.extend(0.0);
let delta = ovf_vec.x + ovf_vec.y;
inert.0 = *direction;
let inert_vec = inert.0.vector();
let delta_vec = inert_vec * delta;
transform.translation += delta_vec.extend(0.0);
}
} }
todo!()
} }
} }
+1 -1
View File
@@ -41,5 +41,5 @@ mod domain;
mod gameplay; mod gameplay;
mod startup; mod startup;
pub use gameplay::head_rotation; pub use gameplay::{head_rotation, moving};
pub use startup::startup; pub use startup::startup;
+2 -2
View File
@@ -1,5 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use snake_game::{head_rotation, startup}; use snake_game::{head_rotation, moving, startup};
fn main() { fn main() {
App::new() App::new()
@@ -19,6 +19,6 @@ fn main() {
.insert_resource(bevy::winit::WinitSettings::desktop_app()) .insert_resource(bevy::winit::WinitSettings::desktop_app())
.insert_resource(ClearColor(Color::srgb(0.3, 0.6, 0.8))) .insert_resource(ClearColor(Color::srgb(0.3, 0.6, 0.8)))
.add_systems(Startup, startup) .add_systems(Startup, startup)
.add_systems(Update, head_rotation) .add_systems(Update, (head_rotation, moving))
.run(); .run();
} }