Skip to content

Commit

Permalink
wip: collectables
Browse files Browse the repository at this point in the history
  • Loading branch information
mrchantey committed Nov 9, 2024
1 parent d5162fb commit a0780eb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
15 changes: 8 additions & 7 deletions crates/beet_sim/examples/sim_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,12 @@ fn kids_crying(mut commands: Commands, stat_map: Res<StatMap>) {
Emoji::new("1F476"), //👶
Transform::from_xyz(0., -1., 0.),
MaxSpeed::default(),
CollectableStat::default(),
))
.with_children(|parent| {
let agent = parent.parent_entity();
parent.spawn((
Name::new("Behavior"),
Name::new("Seek Agent"),
Emoji::new("1F5FA"), //🗺️
orbital_child(0, 2),
TargetEntity(agent),
Expand All @@ -149,7 +150,7 @@ fn kids_crying(mut commands: Commands, stat_map: Res<StatMap>) {
orbital_child(1, 2),
stat_map.get_id_by_name(STRESS).unwrap(),
StatValue::new(0.1),
CollectableStat::default(),
StatProvider::default(),
));
});
}
Expand All @@ -166,14 +167,14 @@ fn alcohol(mut commands: Commands, stat_map: Res<StatMap>) {
orbital_child(0, 2),
stat_map.get_id_by_name(STRESS).unwrap(),
StatValue::new(-0.1),
CollectableStat::default(),
StatProvider::default(),
))
.with_child((
Name::new(SELF_CONTROL),
orbital_child(1, 2),
stat_map.get_id_by_name(SELF_CONTROL).unwrap(),
StatValue::new(-0.1),
CollectableStat::default(),
StatProvider::default(),
));
}

Expand All @@ -182,21 +183,21 @@ fn short_stroll(mut commands: Commands, stat_map: Res<StatMap>) {
.spawn((
Name::new("Short Stroll"),
Emoji::new("1F6B6"), //🚶
CollectableStat::default(),
ZoneStat::default(),
Transform::from_xyz(3., -1.5, 0.),
))
.with_child((
Name::new(STRESS),
orbital_child(0, 2),
stat_map.get_id_by_name(STRESS).unwrap(),
StatValue::new(-0.1),
ZoneStat::default(),
StatProvider::default(),
))
.with_child((
Name::new(SELF_CONTROL),
orbital_child(1, 2),
stat_map.get_id_by_name(SELF_CONTROL).unwrap(),
StatValue::new(0.1),
ZoneStat::default(),
StatProvider::default(),
));
}
2 changes: 1 addition & 1 deletion crates/beet_sim/src/plugins/beet_sim_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ impl Plugin for BeetSimPlugin {
FindStatSteerTarget,
)>::default(),
))
.add_systems(Update, render_valency);
.add_systems(Update, (render_valency, pickup_collectable));
}
}
37 changes: 34 additions & 3 deletions crates/beet_sim/src/stats/collectable_stat.rs
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;
}
}
}
}
8 changes: 8 additions & 0 deletions crates/beet_sim/src/stats/collector.rs
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;
3 changes: 3 additions & 0 deletions crates/beet_sim/src/stats/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
pub mod collectable_stat;
#[allow(unused_imports)]
pub use self::collectable_stat::*;
pub mod collector;
#[allow(unused_imports)]
pub use self::collector::*;
pub mod find_stat_steer_target;
#[allow(unused_imports)]
pub use self::find_stat_steer_target::*;
Expand Down

0 comments on commit a0780eb

Please sign in to comment.