Skip to content
Snippets Groups Projects
Unverified Commit 5fd1cf09 authored by Kat Marchán's avatar Kat Marchán
Browse files

privatize score values, and require they be betweeen 0.0 and 100.0

parent e857fcf0
No related branches found
No related tags found
No related merge requests found
...@@ -31,7 +31,7 @@ pub fn score_thirst_system( ...@@ -31,7 +31,7 @@ pub fn score_thirst_system(
) { ) {
for (Parent(actor), mut score) in query.iter_mut() { for (Parent(actor), mut score) in query.iter_mut() {
if let Ok(thirst) = thirsts.get(*actor) { if let Ok(thirst) = thirsts.get(*actor) {
score.0 = thirst.thirst; score.set(thirst.thirst);
} }
} }
} }
......
...@@ -103,11 +103,8 @@ pub fn thirsty_scorer_system( ...@@ -103,11 +103,8 @@ pub fn thirsty_scorer_system(
// generally "the higher the better", and "first across the finish // generally "the higher the better", and "first across the finish
// line", but that's all configurable using Pickers! // line", but that's all configurable using Pickers!
// //
// In a real-world application, you might want to do a fancier // The score here must be between 0.0 and 100.0.
// calculation here, possibly to clamp the value to a range, add a score.set(thirst.thirst);
// curve, etc. In our case, we'll just assume thirst goes from
// 0.0..100.0, to keep things simple.
score.0 = thirst.thirst;
} }
} }
} }
......
...@@ -3,7 +3,16 @@ use bevy::prelude::*; ...@@ -3,7 +3,16 @@ use bevy::prelude::*;
use crate::ScorerEnt; use crate::ScorerEnt;
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct Score(pub f32); pub struct Score(pub(crate) f32);
impl Score {
pub fn set(&mut self, value: f32) {
if !(0.0..=100.0).contains(&value) {
panic!("Score value must be between 0.0 and 100.0");
}
self.0 = value;
}
}
/** /**
This trait defines new Scorers. In general, you should use the [derive macro](derive.Scorer.html) instead. This trait defines new Scorers. In general, you should use the [derive macro](derive.Scorer.html) instead.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment