Ejemplo n.º 1
0
 /// <summary>
 /// Copy all fields from another instance to the current one.
 /// (e.g. for re-use of object, avoiding new object creation)
 /// </summary>
 public void CopyFrom(BTAIContext other)
 {
     SimTime = other.SimTime;
     BTComp  = other.BTComp;
     Dt      = other.Dt;
     Entity  = other.Entity;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Factory method to create new Red Guard
        /// </summary>
        /// <returns></returns>
        public static Entity Create()
        {
            ChaseBehavior ChasingHero;
            //ChaseBehavior ChasingCompanions;
            AlwaysTurnRightBehavior Turning;
            RandomWanderBehavior    Wandering;
            AttackEnemyBehavior     Attacking;

            var e  = GameFactory.CreateThing(ThingType.RED_GUARD, true);
            var ai = new BTAIComp();

            e.AddComponent(ai);
            var sub = new PrioritySelector();

            ai.rootNode = sub;

            var tc = e.GetComponent <ThingComp>();

            tc.IsCollisionFree = false;
            tc.Color           = new Color(255, 10, 4);
            tc.Faction         = Faction.EVIL;

            var rwc = new RandomWanderComp();

            e.AddComponent(rwc);
            rwc.MinDirectionChangeTime = 2.7;
            rwc.MaxDirectionChangeTime = 11.3;

            // attack hero or companions
            Attacking = new AttackEnemyBehavior(attackString);

            // chase companions that are very close

            /*
             * ChasingCompanions = new ChaseBehavior(typeof(Companion));
             * ChasingCompanions.DeltaTimeBetweenMoves = RandomMath.RandomBetween(0.43f, 0.65f);
             * ChasingCompanions.ChaseRange = 1.5f; // RandomMath.RandomBetween(12f, 40f);
             * sub.AddChild(ChasingCompanions);
             */

            // chase hero
            ChasingHero = new ChaseBehavior(Level.Current.Hero);
            ChasingHero.DeltaTimeBetweenMoves = RandomMath.RandomBetween(0.47f, 0.75f);
            ChasingHero.ChaseRange            = 15f; // RandomMath.RandomBetween(12f, 40f);
            sub.AddChild(ChasingHero);

            Turning = new AlwaysTurnRightBehavior();                           // patrolling
            Turning.DeltaTimeBetweenMoves = ChasingHero.DeltaTimeBetweenMoves; //RandomMath.RandomBetween(0.57f, 1.05f);
            Turning.DeltaTimeBetweenMoves = 0.7f;
            sub.AddChild(Turning);

            Wandering = new RandomWanderBehavior();
            Wandering.DeltaTimeBetweenMoves = 0.7f;
            sub.AddChild(Wandering);

            e.Refresh();
            return(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// create an active ball with given position and random velocity and some weird (AI) behaviors
        /// </summary>
        /// <returns></returns>
        public Entity CreateHyperActiveBall(Vector2 pos)
        {
            var ball = CreateBall(0.08f + 0.07f * (float)rnd.NextDouble());

            // position and velocity set
            ball.GetComponent <PositionComp>().Position2D = pos;
            ball.GetComponent <VelocityComp>().Velocity   = 0.2f * new Vector3((float)rnd.NextDouble() - 0.5f, (float)rnd.NextDouble() - 0.5f, 0f);
            //ball.Motion.Rotate = (float)(Math.PI * 2 * rnd.NextDouble());
            //ball.Timing.StartTime = 10f * (float)rnd.NextDouble();

            // duration of entity
            ball.AddComponent(new ExpiresComp(4 + 500 * rnd.NextDouble()));

            // blink
            //ball.AddComponent(new BlinkComp(0.3+5*rnd.NextDouble(),0.4+0.4*rnd.NextDouble()));

            // Behavior Tree AI
            BTAIComp ai = new BTAIComp();
            var      randomWanderBehavior = new RandomWanderBehavior(1, 6);

            ai.rootNode = new PrioritySelector(randomWanderBehavior);
            ball.AddComponent(ai);

            // Modifier to adapt scale
            var m = new Modifier <Entity>(MyScaleModifier, ball);

            //delegate(Entity entity){ entity.GetComponent<ScaleComp>().Scale = 0.5 + entity.GetComponent<PositionComp>().Position.X; }
            //);
            m.AttachTo(ball);

            // another adapting scale with sine rhythm
            var s = new SineModifier <ScaleComp>(MyScaleModifier2, ball.GetComponent <ScaleComp>());

            s.Frequency = 0.5;
            s.Amplitude = 0.25;
            s.Offset    = 1;
            s.AttachTo(ball);

            // modifier to adapt rotation
            var r = new Modifier <DrawComp>(MyRotateModifier, ball.GetComponent <DrawComp>());

            r.AttachTo(ball);

            // set different time offset initially, per ball (for the modifiers)
            ball.GetComponent <ScriptComp>().SimTime = 10 * rnd.NextDouble();

            ball.Refresh();
            return(ball);
        }