From 41f5f12b9a540ff039a877de687c80bd4725bc2e Mon Sep 17 00:00:00 2001 From: _Corentin_ Date: Tue, 30 May 2023 10:15:17 +0200 Subject: [PATCH] fix fmt --- src/lib.rs | 4 ++-- src/render.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index d97faa3..eded9df 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ #![deny(clippy::all)] #![deny(warnings)] -use bevy::prelude::{Component, Transform}; +use bevy::prelude::*; pub mod map; pub mod render; @@ -25,7 +25,7 @@ pub struct Position { impl Position { /// Peret de recuper la position, sous form d'un transform, d'un objet sur la carte du jeu. - pub fn to_map_position(&self) -> Transform { + pub fn to_world(&self) -> Transform { let offset_x = self.y % 2; let new_x = (offset_x as f32).mul_add(0.5, self.x as f32); Transform::from_xyz(new_x, self.y as f32 * 0.42, self.y as f32 * -1.) diff --git a/src/render.rs b/src/render.rs index d748d2a..6402afd 100644 --- a/src/render.rs +++ b/src/render.rs @@ -8,7 +8,8 @@ pub struct RenderPlugin; impl Plugin for RenderPlugin { fn build(&self, app: &mut App) { - app.add_startup_system(setup_camera).add_system(render_tile); + app.add_startup_system(setup_camera) + .add_system(render_tiles); } } @@ -21,24 +22,22 @@ fn setup_camera(mut commands: Commands) { } /// Permet de rendre le tile et de les actualiser. -fn render_tile( - all_tiles: Query<(Entity, &Tile, &Position), Changed>, +fn render_tiles( + tiles: Query<(Entity, &Tile, &Position), Changed>, mut commands: Commands, asset_server: Res, ) { - for (tile_entity, tile_type, tile_pos) in all_tiles.iter() { + for (tile_entity, tile_type, tile_pos) in tiles.iter() { commands.entity(tile_entity).insert(SpriteBundle { - texture: asset_server.load(get_path_tile(tile_type)), - transform: tile_pos - .to_map_position() - .with_scale(Vec3::splat(1.0 / 185.0)), + texture: asset_server.load(get_tile_path(tile_type)), + transform: tile_pos.to_world().with_scale(Vec3::splat(1.0 / 185.0)), ..default() }); } } /// Recuper le chemin d'acces d'une case. -pub const fn get_path_tile(tile: &Tile) -> &str { +const fn get_tile_path(tile: &Tile) -> &str { match *tile { Tile::Castle => "tiles/castle.png", Tile::Wall => "tiles/wall.png",