draw grid system

This commit is contained in:
nquidox 2026-04-17 23:26:53 +03:00
parent b95dde79a1
commit 71f6b549b7
3 changed files with 28 additions and 5 deletions

View file

@ -16,3 +16,4 @@ pub const ROUND_BALL_Z: f32 = 10.0;
pub const PINK: Color = Color::srgb_u8(250, 0, 155);
pub const BLUE: Color = Color::srgb_u8(0, 0, 255);
pub const GREEN: Color = Color::srgb_u8(0, 255, 0);
pub const DARK_GREEN: Color = Color::srgb_u8(0, 88, 88);

View file

@ -25,6 +25,7 @@ impl Plugin for LinearPlayPlugin {
Update,
(
draw_track_gizmos,
draw_grid,
spawn_round_ball,
move_round_balls,
)

View file

@ -1,4 +1,4 @@
use crate::states;
use crate::{HEIGHT, WIDTH, states, FACTOR};
use bevy::prelude::*;
use states::linear::*;
use std::f32::consts::FRAC_PI_2;
@ -22,7 +22,7 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
PathSegment::Turn { radius, left } => {
// вычисляем нормаль, центр, угол поворота арки и знак
let arc = helper_arc_calculator(current_pos, current_dir, *left, *radius);
// арки никак не хотели вставать на свои места
// gizmos.arc_2d(
// Isometry2d::new(arc.center, Rot2::degrees(current_angle)),
@ -30,7 +30,7 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
// *radius,
// GREEN,
// );
// поэтому отрисовка поворота через линии
let steps = 16;
let mut prev_point = current_pos;
@ -43,7 +43,7 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
gizmos.line_2d(prev_point, point, GREEN);
prev_point = point;
}
current_pos = arc.end_pos;
current_dir = arc.normal;
}
@ -51,4 +51,25 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
}
// рисуем финиш
gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
}
}
pub fn draw_grid(mut gizmos: Gizmos) {
let half_x = WIDTH as f32 / 2.0 * FACTOR as f32;
let half_y = HEIGHT as f32 / 2.0 * FACTOR as f32;
for i in 0..WIDTH {
gizmos.line_2d(
Vec2::new((i as f32 - 8.0) * FACTOR as f32, half_y),
Vec2::new((i as f32 - 8.0) * FACTOR as f32, -half_y),
DARK_GREEN,
);
}
for i in 0..HEIGHT {
gizmos.line_2d(
Vec2::new(-half_x, (i as f32 - 4.0) * FACTOR as f32),
Vec2::new(half_x, (i as f32 - 4.0) * FACTOR as f32),
DARK_GREEN,
)
}
}