This commit is contained in:
CoCo_Sol 2023-05-21 16:38:35 +02:00
parent 2afbb13a0e
commit eca3e6d504
2 changed files with 31 additions and 0 deletions

0
src/map/identity.rs Normal file
View file

31
src/map/position.rs Normal file
View file

@ -0,0 +1,31 @@
//! on stocke les donné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))
}
}