Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
big-brain
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis
big-brain
Commits
b3fd892b
Commit
b3fd892b
authored
3 years ago
by
Kat Marchán
Browse files
Options
Downloads
Patches
Plain Diff
format: cargo format example
parent
7bbc7d5f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/thirst.rs
+13
-3
13 additions, 3 deletions
examples/thirst.rs
with
13 additions
and
3 deletions
examples/thirst.rs
+
13
−
3
View file @
b3fd892b
...
@@ -46,7 +46,10 @@ pub fn thirst_system(time: Res<Time>, mut thirsts: Query<&mut Thirst>) {
...
@@ -46,7 +46,10 @@ pub fn thirst_system(time: Res<Time>, mut thirsts: Query<&mut Thirst>) {
// implements Clone. So, the Clone derive matters here. This is enough in most
// implements Clone. So, the Clone derive matters here. This is enough in most
// cases.
// cases.
#[derive(Clone,
Component,
Debug)]
#[derive(Clone,
Component,
Debug)]
pub
struct
Drink
{
until
:
f32
,
per_second
:
f32
}
pub
struct
Drink
{
until
:
f32
,
per_second
:
f32
,
}
// Action systems execute according to a state machine, where the states are
// Action systems execute according to a state machine, where the states are
// labeled by ActionState.
// labeled by ActionState.
...
@@ -67,7 +70,8 @@ fn drink_action_system(
...
@@ -67,7 +70,8 @@ fn drink_action_system(
}
}
ActionState
::
Executing
=>
{
ActionState
::
Executing
=>
{
println!
(
"drinking some water"
);
println!
(
"drinking some water"
);
thirst
.thirst
-=
drink
.per_second
*
(
time
.delta
()
.as_micros
()
as
f32
/
1_000_000.0
);
thirst
.thirst
-=
drink
.per_second
*
(
time
.delta
()
.as_micros
()
as
f32
/
1_000_000.0
);
if
thirst
.thirst
<=
drink
.until
{
if
thirst
.thirst
<=
drink
.until
{
// To "finish" an action, we set its state to Success or
// To "finish" an action, we set its state to Success or
// Failure.
// Failure.
...
@@ -124,7 +128,13 @@ pub fn init_entities(mut cmd: Commands) {
...
@@ -124,7 +128,13 @@ pub fn init_entities(mut cmd: Commands) {
.picker
(
FirstToScore
{
threshold
:
0.8
})
.picker
(
FirstToScore
{
threshold
:
0.8
})
// Technically these are supposed to be ActionBuilders and
// Technically these are supposed to be ActionBuilders and
// ScorerBuilders, but our Clone impls simplify our code here.
// ScorerBuilders, but our Clone impls simplify our code here.
.when
(
Thirsty
,
Drink
{
until
:
70.0
,
per_second
:
5.0
}),
.when
(
Thirsty
,
Drink
{
until
:
70.0
,
per_second
:
5.0
,
},
),
);
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment