//----------------------------------------------------------------------------- // Behavior.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using Microsoft.Xna.Framework; namespace Flocking { /// /// Behavior is the base class for the four flock behaviors in this sample: /// aligning, cohesion, separation and fleeing. It is an abstract class, /// leaving the implementation of Update up to its subclasses. Animal objects /// can have an arbitrary number of behaviors, after the entity calls Update /// on the behavior the reaction results are stored in reaction so the owner /// can query it. /// public abstract class Behavior { /// /// Keep track of the animal that this behavior belongs to. /// public Animal Animal { get { return animal; } set { animal = value; } } private Animal animal; /// /// Store the behavior reaction here. /// public Vector2 Reaction { get { return reaction; } } protected Vector2 reaction; /// /// Store if the behavior has reaction results here. /// public bool Reacted { get { return reacted; } } protected bool reacted; protected Behavior(Animal animal) { this.animal = animal; } /// /// Abstract function that the subclass must impliment. Figure out the /// Behavior reaction here. /// /// the Animal to react to /// the Behaviors' parameters public abstract void Update(Animal otherAnimal, AIParameters aiParams); /// /// Reset the behavior reactions from the last Update /// protected void ResetReaction() { reacted = false; reaction = Vector2.Zero; } } }