Проектная работа - WIP
This commit is contained in:
+41
-10
@@ -1,17 +1,29 @@
|
||||
use std::time::Duration;
|
||||
|
||||
use bevy::{ecs::spawn, prelude::*, winit::WinitSettings};
|
||||
use bevy::{prelude::*, winit::WinitSettings};
|
||||
|
||||
use crate::domain::{Direction, FRAMES_PER_SECOND, GRID_SIZE, Inert, SNAKE_VELOCITY, Velocity};
|
||||
use crate::domain::Tail;
|
||||
|
||||
/// Инициализация игрового мира
|
||||
pub fn startup(mut commands: Commands, mut winit: ResMut<WinitSettings>) {
|
||||
use crate::domain::{HEAD_SIZE, Head};
|
||||
/// Настройка частоты кадров
|
||||
pub fn setup_frame_rate(mut winit: ResMut<WinitSettings>) {
|
||||
use crate::domain::FRAMES_PER_SECOND;
|
||||
|
||||
winit.focused_mode =
|
||||
bevy::winit::UpdateMode::reactive(Duration::from_secs_f32(1. / FRAMES_PER_SECOND as f32));
|
||||
winit.unfocused_mode =
|
||||
bevy::winit::UpdateMode::reactive(Duration::from_secs_f32(1. / FRAMES_PER_SECOND as f32));
|
||||
}
|
||||
|
||||
/// Инициализация игрового мира
|
||||
pub fn startup(mut commands: Commands) {
|
||||
spawn_snake(&mut commands);
|
||||
spawn_grid(&mut commands);
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
/// Создать голову змеи
|
||||
fn spawn_snake(commands: &mut Commands) {
|
||||
use crate::domain::{Direction, HEAD_SIZE, Head, Inert, SNAKE_VELOCITY, Velocity};
|
||||
|
||||
let head = commands
|
||||
.spawn((
|
||||
@@ -24,7 +36,7 @@ pub fn startup(mut commands: Commands, mut winit: ResMut<WinitSettings>) {
|
||||
vec2(HEAD_SIZE as f32, HEAD_SIZE as f32),
|
||||
),
|
||||
Transform {
|
||||
translation: vec3(0., 0., 0.),
|
||||
translation: vec3(0.0, 0.0, 1.0),
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
@@ -35,7 +47,7 @@ pub fn startup(mut commands: Commands, mut winit: ResMut<WinitSettings>) {
|
||||
vec2(HEAD_SIZE as f32 * 0.3, HEAD_SIZE as f32 * 0.3),
|
||||
),
|
||||
Transform {
|
||||
translation: vec3(HEAD_SIZE as f32 * -0.25, HEAD_SIZE as f32 * 0.25, 0.),
|
||||
translation: vec3(HEAD_SIZE as f32 * -0.25, HEAD_SIZE as f32 * 0.25, 0.0),
|
||||
..Default::default()
|
||||
},
|
||||
ChildOf(head),
|
||||
@@ -46,12 +58,33 @@ pub fn startup(mut commands: Commands, mut winit: ResMut<WinitSettings>) {
|
||||
vec2(HEAD_SIZE as f32 * 0.2, HEAD_SIZE as f32 * 0.2),
|
||||
),
|
||||
Transform {
|
||||
translation: vec3(HEAD_SIZE as f32 * 0.25, HEAD_SIZE as f32 * 0.25, 0.),
|
||||
translation: vec3(HEAD_SIZE as f32 * 0.25, HEAD_SIZE as f32 * 0.25, 0.0),
|
||||
..Default::default()
|
||||
},
|
||||
ChildOf(head),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Tail(0),
|
||||
Direction::default(),
|
||||
Inert::default(),
|
||||
Velocity(0.0),
|
||||
Sprite::from_color(
|
||||
Color::srgb(0.7, 0.7, 0.7),
|
||||
vec2(HEAD_SIZE as f32 * 0.8, HEAD_SIZE as f32 * 0.8),
|
||||
),
|
||||
Transform {
|
||||
translation: vec3(0.0, 0.0, 0.0),
|
||||
..Default::default()
|
||||
},
|
||||
// ChildOf(head),
|
||||
));
|
||||
}
|
||||
|
||||
/// Создать координатную сетку
|
||||
fn spawn_grid(commands: &mut Commands) {
|
||||
use crate::domain::GRID_SIZE;
|
||||
|
||||
for x in -20..=20 {
|
||||
commands.spawn((
|
||||
Sprite::from_color(Color::srgb(1.0, 1.0, 0.5), vec2(1.0, 2000.0)),
|
||||
@@ -70,6 +103,4 @@ pub fn startup(mut commands: Commands, mut winit: ResMut<WinitSettings>) {
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user