diff --git a/src/card/drag.rs b/src/card/drag.rs index b78b23a..fdc7af7 100644 --- a/src/card/drag.rs +++ b/src/card/drag.rs @@ -2,7 +2,7 @@ use bevy::prelude::*; use crate::{ animation::transform::AnimatedTransform, - card::{Card, CardInHand, Hand, InsertCard}, + card::{Card, CardInHand, Hand}, }; #[derive(EntityEvent)] @@ -54,7 +54,7 @@ pub fn card_drag( mouse_pos: Res, ) { if let Ok(mut card) = card_transform.get_mut(event.entity) { - card.translation = mouse_pos.0; + card.translation = mouse_pos.0.truncate().extend(10.); } } diff --git a/src/card/mod.rs b/src/card/mod.rs index 594ac40..254757b 100644 --- a/src/card/mod.rs +++ b/src/card/mod.rs @@ -51,7 +51,7 @@ impl Plugin for CardPlugin { fn hand_setup(mut commands: Commands, asset_server: Res) { commands.spawn(( Hand(Vec::new()), - Transform::from_xyz(0., -360., 0.), + Transform::from_xyz(0., -360., 10.), InheritedVisibility::VISIBLE, )); @@ -86,8 +86,8 @@ fn card_add( let card = commands .spawn(( Sprite::from_image(card_image.0.clone()), - Transform::from_xyz(0., 0., 0.), - AnimatedTransform::from_xyz(0., 0., 0.), + Transform::from_xyz(0., 0., 10.), + AnimatedTransform::from_xyz(0., 0., 10.), Card, DraggableCard, CardInHand, diff --git a/src/card/playing.rs b/src/card/playing.rs index 43d8bf4..904e8e5 100644 --- a/src/card/playing.rs +++ b/src/card/playing.rs @@ -20,6 +20,7 @@ pub fn card_playing_system( let fosma = commands .spawn(( AnimatedTransform::identity(), + Transform::from_translation(mouse_position.0), Sprite::from_image(textures.fosma_texture()), )) .id(); diff --git a/src/grid.rs b/src/grid.rs index 4546b0b..f19a112 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -38,8 +38,10 @@ impl Grid { let x = index % self.columns; let y = (index / self.columns).clamp(0, self.rows - 1); - (self.bounds.min + self.cell_size() / 2. + vec2(x as f32, y as f32) * self.cell_size()) - .extend(0.) + (self.upper_left_corner() + + self.cell_size() / 2. + + vec2(x as f32, y as f32) * self.cell_size()) + .extend(0.) } pub fn is_in_grid(&self, position: Vec2) -> bool { @@ -67,13 +69,20 @@ impl Grid { true } + #[inline] fn cell_size(&self) -> Vec2 { self.bounds.size() / vec2(self.columns as f32, -(self.rows as f32)) } + #[inline] fn indexify_position(&self, position: Vec2) -> usize { - let indexified_position = (position / self.cell_size()).floor(); - indexified_position.x as usize + indexified_position.y as usize * self.columns + let indexified_position = ((position - self.bounds.min) / self.cell_size()).floor(); + indexified_position.x as usize + (5. + indexified_position.y) as usize * self.columns + } + + #[inline] + fn upper_left_corner(&self) -> Vec2 { + Vec2::new(self.bounds.min.x, self.bounds.max.y) } }