Compare commits
3 Commits
00e5bab2a5
...
26cf4c7453
Author | SHA1 | Date |
---|---|---|
Zynh Ludwig | 26cf4c7453 | |
Zynh Ludwig | 866490795d | |
Zynh Ludwig | e57ebb51a8 |
44
src/main.rs
44
src/main.rs
|
@ -60,9 +60,19 @@ fn main() {
|
||||||
.insert_resource(WinitSettings::desktop_app())
|
.insert_resource(WinitSettings::desktop_app())
|
||||||
.add_plugins(DefaultPlugins)
|
.add_plugins(DefaultPlugins)
|
||||||
.add_systems(Startup, setup)
|
.add_systems(Startup, setup)
|
||||||
|
.add_systems(Update, rotate_board)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn rotate_board(mut board: Query<&mut Transform, With<Board>>) {
|
||||||
|
let mut board = board.get_single_mut().unwrap();
|
||||||
|
|
||||||
|
board.rotate_local_z(0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct Board;
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
|
@ -73,24 +83,34 @@ fn setup(
|
||||||
const TILES: i32 = 9;
|
const TILES: i32 = 9;
|
||||||
const TILE_SIZE: f32 = 50.;
|
const TILE_SIZE: f32 = 50.;
|
||||||
const GAP_SIZE: f32 = 10.;
|
const GAP_SIZE: f32 = 10.;
|
||||||
const OFFSET: f32 = (TILE_SIZE + GAP_SIZE) / 2.;
|
|
||||||
const TOTAL_WIDTH: f32 = (TILE_SIZE + GAP_SIZE) * TILES as f32;
|
const TOTAL_WIDTH: f32 = (TILE_SIZE + GAP_SIZE) * TILES as f32;
|
||||||
const TILE_SPACE: f32 = TOTAL_WIDTH / TILES as f32;
|
const TILE_SPACE: f32 = TOTAL_WIDTH / TILES as f32;
|
||||||
|
const OFFSET: f32 = TILE_SPACE / 2.;
|
||||||
const CENTER: f32 = TOTAL_WIDTH / 2.;
|
const CENTER: f32 = TOTAL_WIDTH / 2.;
|
||||||
|
|
||||||
let tile_mesh = Mesh2dHandle(meshes.add(Rectangle::new(TILE_SIZE, TILE_SIZE)));
|
let tile_mesh = Mesh2dHandle(meshes.add(Rectangle::new(TILE_SIZE, TILE_SIZE)));
|
||||||
let tile_color = Color::from(tailwind::NEUTRAL_700);
|
let tile_color = Color::from(tailwind::NEUTRAL_700);
|
||||||
|
|
||||||
for i in 0..TILES {
|
commands
|
||||||
for j in 0..TILES {
|
.spawn((
|
||||||
let tile_x = i as f32 * TILE_SPACE - CENTER + OFFSET;
|
SpatialBundle {
|
||||||
let tile_y = j as f32 * TILE_SPACE - CENTER + OFFSET;
|
transform: Transform::from_xyz(0., 0., 0.),
|
||||||
commands.spawn(MaterialMesh2dBundle {
|
|
||||||
mesh: tile_mesh.clone(),
|
|
||||||
material: materials.add(tile_color),
|
|
||||||
transform: Transform::from_xyz(tile_x, tile_y, 0.),
|
|
||||||
..default()
|
..default()
|
||||||
});
|
},
|
||||||
}
|
Board,
|
||||||
}
|
))
|
||||||
|
.with_children(|parent| {
|
||||||
|
for i in 0..TILES {
|
||||||
|
for j in 0..TILES {
|
||||||
|
let tile_x = i as f32 * TILE_SPACE - CENTER + OFFSET;
|
||||||
|
let tile_y = j as f32 * TILE_SPACE - CENTER + OFFSET;
|
||||||
|
parent.spawn(MaterialMesh2dBundle {
|
||||||
|
mesh: tile_mesh.clone(),
|
||||||
|
material: materials.add(tile_color),
|
||||||
|
transform: Transform::from_xyz(tile_x, tile_y, 0.),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue