add coordinate and chessboard

This commit is contained in:
lemon-cat committed 2026-09-16 00:09:21 +03:00
1 parent a2ea0a3aaf
commit ffe4b48479
7 files changed
+117 -1

No files matched your search

+1 -1
View File
@@ -6,6 +6,6 @@
Cargo.lock
# асеты
assets/**/*
#assets/**/*
!assets/shaders/
!assets/shaders/**/*
+8
View File
@@ -4,3 +4,11 @@ version = "0.1.0"
edition = "2024"
[dependencies]
bevy = "0.18"
[profildev]
opt-level = 1
debug = true
[profile.dev.package."*"]
opt-level = 3
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 589 KiB

+108
View File
@@ -1,3 +1,111 @@
use bevy::{prelude::*, ui::RelativeCursorPosition};
fn main() {
println!("Hello, world!");
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
resolution: (800, 800).into(),
title: "local-chess".into(),
..default()
}),
..default()
}))
.add_systems(Startup, setup)
.add_systems(Update, relative_cursor_position_system)
.run();
}
fn setup(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2d);
commands
.spawn((
Node {
width: percent(100),
height: percent(100),
..default()
},
Sprite::from_image(assets.load("scene/chessboard.png"))
))
.insert(RelativeCursorPosition::default());
commands
.spawn(Node {
width: percent(100),
height: percent(100),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
..default()
})
.with_children(|parent| {
parent.spawn((
Text::new("who"),
TextFont {
font: assets.load("fonts/Baskerville Bold Italic.ttf").into(),
//font_size: FontSize::Px(33.0),
font_size: 50.0,
..default()
},
TextColor(Color::srgb(0.1, 0.1, 0.1)),
));
});
}
fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){
let mut output_text = text.into_inner();
if let Some(pos) = rcp.normalized{
let x = ((pos.x + 0.5) * 10.0) as i8;
let mut coordinate_x: char;
match x {
1 => {coordinate_x = 'a'}
2 => {coordinate_x = 'b'}
3 => {coordinate_x = 'c'}
4 => {coordinate_x = 'd'}
5 => {coordinate_x = 'e'}
6 => {coordinate_x = 'f'}
7 => {coordinate_x = 'g'}
8 => {coordinate_x = 'h'}
_ => {coordinate_x = ' '}
}
let y = ((pos.y * -1. + 0.5) * 10.0) as i8;
let mut coordinate_y: char;
match y {
1 => {coordinate_y = '1'}
2 => {coordinate_y = '2'}
3 => {coordinate_y = '3'}
4 => {coordinate_y = '4'}
5 => {coordinate_y = '5'}
6 => {coordinate_y = '6'}
7 => {coordinate_y = '7'}
8 => {coordinate_y = '8'}
_ => {coordinate_y = ' '}
}
** output_text = format!("{}{}", coordinate_x, coordinate_y);
} else {
** output_text = "uncnown".to_string();
}
}
/*
fn relative_cursor_position_system(
relative_cursor_position: Single<&RelativeCursorPosition>,
output_query: Single<(&mut Text, &mut TextColor)>,
) {
let (mut output, mut text_color) = output_query.into_inner();
**output = if let Some(relative_cursor_position) = relative_cursor_position.normalized {
format!(
"({}, {})",
relative_cursor_position.x, relative_cursor_position.y
)
} else {
"unknown".to_string()
};
}
#[derive(Component)]
pub struct Chess {}
*/