From eca3e6d504035e0ed5c07318cba48c0cb8568688 Mon Sep 17 00:00:00 2001 From: CoCo_Sol Date: Sun, 21 May 2023 16:38:35 +0200 Subject: [PATCH] position --- src/map/identity.rs | 0 src/map/position.rs | 31 +++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/map/identity.rs create mode 100644 src/map/position.rs diff --git a/src/map/identity.rs b/src/map/identity.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/map/position.rs b/src/map/position.rs new file mode 100644 index 0000000..aef2939 --- /dev/null +++ b/src/map/position.rs @@ -0,0 +1,31 @@ +//! on stocke les donneĢes des position (fonction, enum et struct) + +use bevy::prelude::*; +use map::identity::*; + +#[derive(Component)] +/// position du block +pub struct BlockPosition { + /// la position en x + pub x: u8, + /// la position en y + pub y: u8, +} + +impl BlockPosition { + /// retourne la position en x et y dans la map en foction de la position abstraite + pub fn to_transform(&self, identity: Identity) -> Transform { + let max_y: u8 = 9; + let max_x = 10.; + let new_y = max_y - 1 - self.y; + let offset_x = new_y % 2; + + let mut new_x = (offset_x as f32).mul_add(0.5, self.x as f32); + if identity == Identity::Joueur2 { + new_x = max_x - new_x; + }; + + Transform::from_xyz(new_x, new_y as f32 * 0.42, self.y as f32) + .with_scale(Vec3::splat(1.0 / 185.0)) + } +}