-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,42 @@ | ||
use crate::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
//// Superset of [`CollectableStat`], [`ZoneStat`] etc | ||
//// Added to children of Collectables and Zones for consideration in [`FindStatSteerTarget`] | ||
#[derive(Default, Component, Reflect)] | ||
#[reflect(Default, Component)] | ||
pub struct StatProvider; | ||
|
||
#[derive(Default, Component, Reflect)] | ||
|
||
/// Add this as a child of an entity to make it collectable. | ||
/// This will be able to be picked up. | ||
#[derive(Component, Reflect)] | ||
#[reflect(Default, Component)] | ||
#[require(StatProvider)] | ||
pub struct CollectableStat {} | ||
pub struct CollectableStat { | ||
pub radius: f32, | ||
} | ||
|
||
impl Default for CollectableStat { | ||
fn default() -> Self { Self { radius: 0.5 } } | ||
} | ||
|
||
|
||
pub fn pickup_collectable( | ||
mut commands: Commands, | ||
stat_map: Res<StatMap>, | ||
collectors: Query<&GlobalTransform, With<Collector>>, | ||
query: Populated<(&GlobalTransform, &CollectableStat, &StatId, &StatValue)>, | ||
) { | ||
for (transform, collectable_stat, stat_id, stat_value) in query.iter() { | ||
let rad_sq = collectable_stat.radius * collectable_stat.radius; | ||
for collector_transform in collectors.iter() { | ||
if transform | ||
.translation() | ||
.distance_squared(collector_transform.translation()) | ||
> rad_sq | ||
{ | ||
continue; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use crate::prelude::*; | ||
use bevy::prelude::*; | ||
|
||
|
||
/// Marker to indicate that an entity is a collector. | ||
#[derive(Default, Component, Reflect)] | ||
#[reflect(Default, Component)] | ||
pub struct Collector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters