Проектная работа - WIP
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
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 HEAD_SIZE: u8 = (GRID_SIZE as f32 * 1.1) 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;
|
||||
|
||||
/// Направление движения
|
||||
#[derive(Component, PartialEq)]
|
||||
#[derive(Component, PartialEq, Clone, Copy)]
|
||||
pub enum Direction {
|
||||
Up,
|
||||
Left,
|
||||
|
||||
@@ -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() {
|
||||
let delta = velocity * time.delta_secs();
|
||||
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 {
|
||||
let inert_vec = inert.0.vector();
|
||||
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.y, delta_vec.y),
|
||||
);
|
||||
|
||||
todo!()
|
||||
transform.translation += delta_vec.extend(0.0);
|
||||
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!()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,5 +41,5 @@ mod domain;
|
||||
mod gameplay;
|
||||
mod startup;
|
||||
|
||||
pub use gameplay::head_rotation;
|
||||
pub use gameplay::{head_rotation, moving};
|
||||
pub use startup::startup;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use snake_game::{head_rotation, startup};
|
||||
use snake_game::{head_rotation, moving, startup};
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
@@ -19,6 +19,6 @@ fn main() {
|
||||
.insert_resource(bevy::winit::WinitSettings::desktop_app())
|
||||
.insert_resource(ClearColor(Color::srgb(0.3, 0.6, 0.8)))
|
||||
.add_systems(Startup, startup)
|
||||
.add_systems(Update, head_rotation)
|
||||
.add_systems(Update, (head_rotation, moving))
|
||||
.run();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user