Something went wrong on our end
-
Kat Marchán authored
Fixes: https://github.com/zkat/big-brain/issues/10
README.md 3.58 KiB
big-brain
is a Utility AI
library for games, built for the Bevy Game Engine
It lets you define complex, intricate AI behaviors for your entities based on their perception of the world. Definitions are heavily data-driven, using plain Rust, and you only need to program Scorers (entities that look at your game world and come up with a Score), and Actions (entities that perform actual behaviors upon the world). No other code is needed for actual AI behavior.
See the documentation for more details.
Example
First, you define actions and considerations, which are just plain old Bevy
Component
s and System
s.
Scorers
Scorers
s are entities that look at the world and evaluate into Score
values.
use bevy::prelude::*;
use big_brain::prelude::*;
#[derive(Debug, Clone)]
pub struct Thirsty;
impl Thirsty {
fn build() -> ThirstyBuilder {
ThirstyBuilder
}
}
#[derive(Debug, Clone)]
pub struct ThirstyBuilder;
impl ScorerBuilder for ThirstyBuilder {
fn build(&self, cmd: &mut Commands, scorer: Entity, _actor: Entity) {
cmd.entity(scorer).insert(Thirsty);
}
}
pub fn thirsty_scorer_system(
thirsts: Query<&Thirst>,
mut query: Query<(&Actor, &mut Score), With<Thirsty>>,
) {
for (Actor(actor), mut score) in query.iter_mut() {
if let Ok(thirst) = thirsts.get(*actor) {
score.set(thirst.thirst);
}
}
}
Actions
Action
s are the actual things your entities will do.