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

This commit is contained in:
7 changed files with 1465 additions and 38 deletions
+1395 -31
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -4,8 +4,8 @@ version = "0.1.0"
edition = "2024"
[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" }
# bevy = { version = "0.18", default-features = false, features = ["2d_bevy_render", "bevy_log", "bevy_winit", "bevy_text", "bevy_ui", "debug"] }
bevy = { version = "0.18" }
tracing = "0.1"
tracing-subscriber = "0.3"
+42
View File
@@ -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");
}
+4
View File
@@ -32,3 +32,7 @@ pub struct End;
/// Скорость движения
#[derive(Component)]
pub struct Velocity(pub f32);
/// Еда
#[derive(Component)]
pub struct Meal;
+3 -1
View File
@@ -16,12 +16,14 @@ impl GridBarier {
}
}
/// Событие роста змеи
#[derive(Event)]
pub struct GrowUp;
/// Событие столкновения змеи
#[derive(Event, Debug)]
pub enum Collision {
Bounds,
Tail,
Meal,
Meal(Entity),
}
+18 -3
View File
@@ -1,7 +1,7 @@
use bevy::prelude::*;
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,
};
@@ -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 (x, y) = (head_transform.translation.x, head_transform.translation.y);
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));
}
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ pub fn handle_collisions(
query: Query<(&mut Velocity, &mut Sprite), Or<(With<Head>, With<Tail>, With<End>)>>,
) {
match event.event() {
Collision::Meal => {
Collision::Meal(entity) => {
todo!()
}
Collision::Bounds | Collision::Tail => {