Beispiel #1
0
 public static AnimalType <T> WithSensing <T>(this AnimalType <T> animal, float hearingDistance = 5f, float viewDistance = 5f, float viewSize = 2.4f)
 {
     animal.HearingDistance = hearingDistance;
     animal.ViewDistance    = viewDistance;
     animal.ViewSize        = viewSize;
     return(animal);
 }
Beispiel #2
0
 public static AnimalType <T> WithAsset <T>(this AnimalType <T> animal, AnimationDefintion anim, Vector2 size, Vector2?origin = null)
 {
     animal.Asset       = anim;
     animal.AssetOrigin = origin ?? animal.AssetOrigin;
     animal.Size        = size;
     return(animal);
 }
Beispiel #3
0
        public AnimalEntity(Scene scene, Vector2 location, AnimalType <T> animal, float rotation = 0) : base(scene, EntityType.Game, location, bodyType: BodyType.Dynamic)
        {
            AnimalType             = animal;
            AddComponent(animation = new AnimatedSpriteComponent(animal.Asset, animal.Size, animal.AssetOrigin));
            AddComponent(new PhysicsComponent(animal.CollisionShape));
            AddComponent(viewSensor = new SensorComponent("view",
                                                          new PolygonShape(PolygonTools.CreateCapsule(animal.ViewDistance, animal.ViewSize / 2, 4, animal.ViewSize, 8), 1),
                                                          e => e is PlayerEntity && ((PlayerEntity)e).State == PlayerState.Luring));

            AddComponent(hearingSensor = new SensorComponent("hearing",
                                                             new CircleShape(animal.HearingDistance, 1),
                                                             e => e is PlayerEntity && ((PlayerEntity)e).State == PlayerState.Shouting));

            AddComponent(new MovementBasicsComponent());
            AddComponent(new RaycastSensorComponent(animal.ViewDistance));
            AddComponent(new AudioSourceComponent());

            aiComponent = new StateBasedAIComponent <T>(animal.InitalState);

            AddComponent(aiComponent);
            aiComponent.StateChanged += AiComponent_StateChanged1;

            // [FOREACH PERFORMANCE] Should not allocate garbage
            foreach (var b in animal.Behaviors)
            {
                AddComponent(b());
            }

            Body.Rotation = rotation;
        }
Beispiel #4
0
 public static AnimalType <T> DefaultAnimation <T>(this AnimalType <T> animal, string animationState)
 {
     animal.DefaultAnimation = animationState;
     return(animal);
 }
Beispiel #5
0
 public static AnimalType <T> StateToAnimation <T>(this AnimalType <T> animal, T state, string animationState)
 {
     animal.AnimationMappings.Add(state, animationState);
     return(animal);
 }
Beispiel #6
0
 public static AnimalType <T> WithBehaviour <T>(this AnimalType <T> animal, Func <StateBasedAIBehaviorComponent <T> > behaviour)
 {
     animal.Behaviors.Add(behaviour);
     return(animal);
 }
Beispiel #7
0
 public static AnimalType <T> WithCollisionShape <T>(this AnimalType <T> animal, Vector2[] vertices, float densitiy = 1)
 {
     animal.CollisionShape = new PolygonShape(new Vertices(vertices), densitiy);
     return(animal);
 }
Beispiel #8
0
 public static AnimalType <T> WithCollisionShape <T>(this AnimalType <T> animal, float radius, float densitiy = 1)
 {
     animal.CollisionShape = new CircleShape(radius, densitiy);
     return(animal);
 }