Blended¶
Blended Steering Behaviors
This module implements a class that Blends a list of
KinematicSteeringBehavior
s and provides
a weighted sum of their outputs as a steering request.
This is the bread and butter of Steering Behaviors since it easily combines different behaviors that allow for semi-complex AI behaviors.
Derives from KinematicSteeringBehavior
.
Example
This is how you would normally create your own BlendedSteering
,
in this case we are making a more complex version of Arrive
where the character looks where it’s going and also tries to avoid any
obstacle in the way.
flocking_behavior = BlendedSteering(
character = character
behaviors = [
BehaviorAndWeight(kinematic.Arrive(character, target), weight = 1),
BehaviorAndWeight(kinematic.LookWhereYoureGoing(character), weight = 1),
BehaviorAndWeight(kinematic.ObstacleAvoidance(character, obstacles), weight = 2),
]
)
This module also includes a couple of pre-implemented BlendedSteering
.
Todo
Make BehaviorAndWeight prettier, maybe use named tuples?
BehaviorAndWeight¶
-
class
steering.blended.
BehaviorAndWeight
(behavior, weight)[source]¶ Container for Behavior and Weight values
Parameters: - behavior (
KinematicSteeringBehavior
) – - weight (int) –
- behavior (
BlendedSteering¶
-
class
steering.blended.
BlendedSteering
(character, behaviors)[source]¶ Base Blended Steering
This class provides methods neccesary to combine the list of steering behaviors and produce a single
SteeringOutput
.Derives from
KinematicSteeringBehavior
, currentlyBlendedSteering
withStaticSteeringBehavior
is not supported.Parameters: - character (
GameObject
) – Character with this behavior - behaviors (list(
BehaviorAndWeight
)) – List of behaviors that compose thisBlendedSteering
-
draw_indicators
(screen, offset=<function BlendedSteering.<lambda>>)[source]¶ Draws appropiate indicators for this
BlendedSteering
Draws the indicators of all
KinematicSteeringBehavior
that compose thisBlendedSteering
.Parameters: - screen (pygame.Surface) – Surface in which to draw indicators, normally this would be the screen Surface
- offset (function, optional) –
Function that applies an offset to the object’s position
This is meant to be used together with scrolling cameras, leave empty if your game doesn’t implement one,it defaults to a linear function f(pos) -> pos
-
get_steering
()[source]¶ Returns the combined steering request of this
BlendedSteering
Returns: Requested steering Return type: SteeringOutput
- character (
-
class
steering.blended.
Arrive
(character, target, obstacles, target_radius=None, slow_radius=None)[source]¶ BlendedSteering
that makes the character Arrive at a targetThis is behavior is a more complex version of
Arrive
that also Looks Where it’s Going and tries to Avoid Obstacles.Parameters: - character (
GameObject
) – - target (
GameObject
) – - obstacles (iterable(pygame.sprite.Sprite)) – Solid obstacles
- character (
-
class
steering.blended.
Flocking
(character, swarm, target)[source]¶ BlendedSteering
that makes the character move in a flock-like wayThis behavior is meant to be used with several characters, they will all try to Arive at the same target location while Looking Where They’re Going and keeping Separated from eachother.
Parameters: - character (
GameObject
) – - swarm (iterable(pygame.sprite.Sprite)) – Rest of the entities that conform the Flock
- target (
GameObject
) –
- character (
-
class
steering.blended.
Wander
(character, obstacles)[source]¶ BlendedSteering
that makes the character Wander around.This behaviors is a more complex version of
Wander
that also tries to Avoid Obstacles.Parameters: - character (
GameObject
) – - obstacles (iterable(pygame.sprite.Sprite)) – Solid obstacles
- character (