generated from 2ndbeam/bevy-template
feat: Added Inventory and Item components
- Moved input tests into nested module - Added inventory tests
This commit is contained in:
parent
957717671a
commit
dab3134f15
4 changed files with 260 additions and 72 deletions
35
src/inventory/item.rs
Normal file
35
src/inventory/item.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
use bevy::prelude::*;
|
||||
|
||||
#[derive(Component, Clone)]
|
||||
pub struct Item {
|
||||
pub size: UVec2,
|
||||
pub position: Option<UVec2>,
|
||||
}
|
||||
|
||||
impl Item {
|
||||
pub fn new(size: UVec2) -> Self {
|
||||
Self { size, position: None }
|
||||
}
|
||||
|
||||
pub fn new_positioned(size: UVec2, position: UVec2) -> Self {
|
||||
Self { size, position: Some(position) }
|
||||
}
|
||||
|
||||
pub fn rect(&self) -> Option<URect> {
|
||||
let Some(position) = self.position else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(URect::from_corners(position, position + self.size))
|
||||
}
|
||||
|
||||
pub fn overlaps(&self, other_size: UVec2, other_position: UVec2) -> bool {
|
||||
let Some(rect) = self.rect() else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let other_rect = URect::from_corners(other_position, other_position + other_size);
|
||||
|
||||
!rect.intersect(other_rect).is_empty()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue