Проектная работа - WIP
This commit is contained in:
Generated
+1395
-31
File diff suppressed because it is too large
Load Diff
@@ -4,8 +4,8 @@ version = "0.1.0"
|
|||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.18", default-features = false, features = ["2d_bevy_render", "bevy_log", "bevy_winit", "bevy_text", "bevy_ui", "debug"] }
|
# bevy = { version = "0.18", default-features = false, features = ["2d_bevy_render", "bevy_log", "bevy_winit", "bevy_text", "bevy_ui", "debug"] }
|
||||||
# bevy = { version = "0.18" }
|
bevy = { version = "0.18" }
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-subscriber = "0.3"
|
tracing-subscriber = "0.3"
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
use bevy::{app::FixedMain, prelude::*};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
App::new() //
|
||||||
|
.add_plugins(DefaultPlugins)
|
||||||
|
.add_systems(StateTransition, state_transition)
|
||||||
|
.add_systems(PreStartup, pre_startup)
|
||||||
|
.add_systems(Startup, startup)
|
||||||
|
.add_systems(PostStartup, post_startup)
|
||||||
|
.add_systems(First, first)
|
||||||
|
.add_systems(PreUpdate, pre_update)
|
||||||
|
.add_systems(FixedMain, fixed_main)
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn state_transition() {
|
||||||
|
info!("StateTransition");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pre_startup() {
|
||||||
|
info!("PreStartup");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn startup() {
|
||||||
|
info!("Startup");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn post_startup() {
|
||||||
|
info!("PostStartup");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn first() {
|
||||||
|
info!("First");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn pre_update() {
|
||||||
|
info!("PreUpdate");
|
||||||
|
}
|
||||||
|
|
||||||
|
fn fixed_main() {
|
||||||
|
info!("FixedMain");
|
||||||
|
}
|
||||||
@@ -32,3 +32,7 @@ pub struct End;
|
|||||||
/// Скорость движения
|
/// Скорость движения
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct Velocity(pub f32);
|
pub struct Velocity(pub f32);
|
||||||
|
|
||||||
|
/// Еда
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Meal;
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ impl GridBarier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Событие роста змеи
|
||||||
#[derive(Event)]
|
#[derive(Event)]
|
||||||
pub struct GrowUp;
|
pub struct GrowUp;
|
||||||
|
|
||||||
|
/// Событие столкновения змеи
|
||||||
#[derive(Event, Debug)]
|
#[derive(Event, Debug)]
|
||||||
pub enum Collision {
|
pub enum Collision {
|
||||||
Bounds,
|
Bounds,
|
||||||
Tail,
|
Tail,
|
||||||
Meal,
|
Meal(Entity),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
domain::{Collision, Direction, FIELD_SIZE, GRID_SIZE, GridBarier, Head, Position, SnakePath, Tail, Velocity},
|
domain::{Collision, Direction, FIELD_SIZE, GRID_SIZE, GridBarier, Head, Meal, Position, SnakePath, Tail, Velocity},
|
||||||
tools::split_by_grid,
|
tools::split_by_grid,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,7 +111,10 @@ pub fn snake_moving(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Система отслеживания столкновений с границей
|
/// Система отслеживания столкновений с границей
|
||||||
pub fn check_bounds_colisions(head: Single<(&Transform,), (With<Head>,)>, mut commands: Commands) {
|
pub fn check_bounds_colisions(
|
||||||
|
head: Single<(&Transform,), (With<Head>,)>,
|
||||||
|
mut commands: Commands, //
|
||||||
|
) {
|
||||||
let (head_transform,) = head.into_inner();
|
let (head_transform,) = head.into_inner();
|
||||||
let (x, y) = (head_transform.translation.x, head_transform.translation.y);
|
let (x, y) = (head_transform.translation.x, head_transform.translation.y);
|
||||||
const SIDE: f32 = (FIELD_SIZE as f32 / 2.0) * GRID_SIZE as f32;
|
const SIDE: f32 = (FIELD_SIZE as f32 / 2.0) * GRID_SIZE as f32;
|
||||||
@@ -139,4 +142,16 @@ pub fn check_tail_colisions(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Система отслеживания столкновений с едой
|
/// Система отслеживания столкновений с едой
|
||||||
pub fn check_meal_collisions() {}
|
pub fn check_meal_collisions(
|
||||||
|
head: Single<(&Transform,), (With<Head>,)>,
|
||||||
|
query: Query<(&Transform, Entity), (With<Meal>,)>,
|
||||||
|
mut commands: Commands, //
|
||||||
|
) {
|
||||||
|
let (head_transform,) = head.into_inner();
|
||||||
|
for (meal_transform, meal_entity) in query.into_iter() {
|
||||||
|
let distance = head_transform.translation.distance(meal_transform.translation);
|
||||||
|
if distance < GRID_SIZE as f32 {
|
||||||
|
commands.trigger(Collision::Meal(meal_entity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ pub fn handle_collisions(
|
|||||||
query: Query<(&mut Velocity, &mut Sprite), Or<(With<Head>, With<Tail>, With<End>)>>,
|
query: Query<(&mut Velocity, &mut Sprite), Or<(With<Head>, With<Tail>, With<End>)>>,
|
||||||
) {
|
) {
|
||||||
match event.event() {
|
match event.event() {
|
||||||
Collision::Meal => {
|
Collision::Meal(entity) => {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
Collision::Bounds | Collision::Tail => {
|
Collision::Bounds | Collision::Tail => {
|
||||||
|
|||||||
Reference in New Issue
Block a user