Compare commits
2
Commits
0bf78729a1
...
lemon-cat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9ce81ff07 | ||
|
|
ffe4b48479 |
No files matched your search
+1
-1
@@ -6,6 +6,6 @@
|
||||
Cargo.lock
|
||||
|
||||
# асеты
|
||||
assets/**/*
|
||||
#assets/**/*
|
||||
!assets/shaders/
|
||||
!assets/shaders/**/*
|
||||
@@ -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: 771 KiB |
+93
@@ -1,3 +1,96 @@
|
||||
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),
|
||||
align_items: AlignItems::Center,
|
||||
justify_content: JustifyContent::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
..default()
|
||||
})
|
||||
.with_children(|parent| {
|
||||
parent
|
||||
.spawn((
|
||||
Node {
|
||||
width: px(512),
|
||||
height: px(512),
|
||||
margin: UiRect::bottom(px(15)),
|
||||
..default()
|
||||
},
|
||||
ImageNode::new(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,
|
||||
left: percent(-40.0),
|
||||
top: percent(-40.0),
|
||||
..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(1.0, 0.5, 1.0)),
|
||||
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
fn relative_cursor_position_system(rcp: Single<&RelativeCursorPosition>, text: Single<&mut Text>){
|
||||
//let ratio;
|
||||
let is_white = true;
|
||||
let mut output_text = text.into_inner();
|
||||
if let Some(pos) = rcp.normalized{
|
||||
|
||||
let mut x = ((pos.x + 0.5) * 8.0) as usize + 1;
|
||||
let mut y;
|
||||
if is_white {
|
||||
y = ((pos.y - 0.5) * -8.0 ) as usize + 1;
|
||||
} else {
|
||||
y = ((pos.y + 0.5) * 8.0) as usize + 1;
|
||||
}
|
||||
let m = ((y - 1) * 8) + x-1;
|
||||
x = (pos.x > -0.5 && pos.x < 0.5) as usize * x;
|
||||
let cx = [' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
|
||||
y = (pos.y > -0.5 && pos.y < 0.5) as usize * y;
|
||||
let cy = [' ', '1', '2', '3', '4', '5', '6', '7', '8'];
|
||||
|
||||
** output_text = format!("{}|{}|{}", cx[x], cy[y], m);
|
||||
} else {
|
||||
** output_text = " ".to_string();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user