Beispiel #1
0
        public Servant()
            : base("pixie")
        {
            IsCollisionFree    = false;
            Pushing.Force      = 0f; // servants cant push others.
            DrawInfo.DrawColor = Color.Yellow;

            ComplexBehavior = new SubsumptionBehavior();
            Add(ComplexBehavior);

            // avoid knights - done by a 'reversed' chase
            AvoidingKnights            = new ChaseBehavior(typeof(Knight), true);
            AvoidingKnights.MoveSpeed  = RandomMath.RandomBetween(0.43f, 0.65f);
            AvoidingKnights.ChaseRange = RandomMath.RandomBetween(10f, 17f);
            AvoidingKnights.ReverseBehavior();
            ComplexBehavior.Add(AvoidingKnights);

            // avoid hero - done by a 'reversed' chase
            AvoidingHero            = new ChaseBehavior(Level.Current.hero);
            AvoidingHero.MoveSpeed  = RandomMath.RandomBetween(0.43f, 0.65f);
            AvoidingHero.ChaseRange = RandomMath.RandomBetween(10f, 17f);
            AvoidingHero.ReverseBehavior();
            ComplexBehavior.Add(AvoidingHero);

            Wandering           = new RandomWanderBehavior(9.7f, 14.3f);
            Wandering.MoveSpeed = 0.3f;
            ComplexBehavior.Add(Wandering);
        }
Beispiel #2
0
        public Servant()
            : base("pixie")
        {
            IsCollisionFree    = false;
            Pushing.Force      = 0f; // servants cant push others.
            DrawInfo.DrawColor = Color.Yellow;

            // avoid other things
            Avoiding = new ChaseBehavior(typeof(Companion));
            Avoiding.MoveDeltaTime = RandomMath.RandomBetween(0.43f, 0.65f);
            Avoiding.ChaseRange    = 11f; // RandomMath.RandomBetween(12f, 40f);
            Add(Avoiding);

            // avoid other things
            Avoiding = new ChaseBehavior(typeof(Pixie));
            Avoiding.MoveDeltaTime = RandomMath.RandomBetween(0.43f, 0.65f);
            Avoiding.ChaseRange    = 11f; // RandomMath.RandomBetween(12f, 40f);
            //Avoiding.Avoidance = true;
            Add(Avoiding);

            Wandering = new RandomWanderBehavior(9.7f, 14.3f);
            Wandering.MoveDeltaTime = 0.3f;
            Add(Wandering);

            Reverse = new ReverseControlBehavior();
            Add(Reverse);
        }
Beispiel #3
0
        public RedGuard(Thing chaseTarget)
            : base("pixie")
        {
            IsCollisionFree    = false;
            DrawInfo.DrawColor = new Color(255, 10, 4);
            Health             = 13f;

            ComplexBehavior = new SubsumptionBehavior();
            Add(ComplexBehavior);

            Combat = new CombatBehavior(typeof(Knight));
            ComplexBehavior.Add(Combat);

            // chase knights that are very close
            ChasingComp            = new ChaseBehavior(typeof(Knight), true);
            ChasingComp.MoveSpeed  = RandomMath.RandomBetween(0.43f, 0.65f);
            ChasingComp.ChaseRange = 2f; // RandomMath.RandomBetween(12f, 40f);
            ComplexBehavior.Add(ChasingComp);

            // chase hero
            Chasing            = new ChaseBehavior(chaseTarget);
            Chasing.MoveSpeed  = RandomMath.RandomBetween(0.47f, 0.75f);
            Chasing.ChaseRange = 14f; // RandomMath.RandomBetween(12f, 40f);
            ComplexBehavior.Add(Chasing);

            Turning           = new AlwaysTurnRightBehavior(); // patrolling
            Turning.MoveSpeed = Chasing.MoveSpeed;             //RandomMath.RandomBetween(0.57f, 1.05f);
            Turning.MoveSpeed = 0.7f;
            ComplexBehavior.Add(Turning);

            Wandering           = new RandomWanderBehavior(2.7f, 11.3f);
            Wandering.MoveSpeed = 0.7f;
            ComplexBehavior.Add(Wandering);
        }
Beispiel #4
0
        public Companion()
            : base("pixie")
        {
            IsCollisionFree = false;

            SetColors(4f, new Color(38, 30, 240), new Color(150, 150, 255));

            Pushing.Force = RandomMath.RandomBetween(1f, 1.5f);

            SubsumptionBehavior sub = new SubsumptionBehavior();

            Add(sub);

            Combat = new CombatBehavior(typeof(RedGuard));
            sub.Add(Combat);

            ChasingHero                = new ChaseBehavior(Level.Current.pixie);
            ChasingHero.ChaseRange     = 370f;
            ChasingHero.SatisfiedRange = 6f;
            ChasingHero.MoveDeltaTime  = RandomMath.RandomBetween(1.2f, 1.5f);
            sub.Add(ChasingHero);

            ChasingRedGuard               = new ChaseBehavior(typeof(RedGuard));
            ChasingRedGuard.ChaseRange    = 20f;
            ChasingRedGuard.MoveDeltaTime = RandomMath.RandomBetween(1.1f, 1.5f);
            sub.Add(ChasingRedGuard);

            Attacking = new AttackBehavior(Level.Current.pixie);
            Attacking.AttackDuration = RandomMath.RandomBetween(1.5f, 2.8f);
            sub.Add(Attacking);

            Wandering = new RandomWanderBehavior(2.7f, 11.3f);
            Wandering.MoveDeltaTime = RandomMath.RandomBetween(0.09f, 0.25f);
            sub.Add(Wandering);
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public Knight()
            : base("pixie")
        {
            IsCollisionFree = false;

            SetColors(4f, new Color(28, 20, 230), new Color(76, 76, 255));
            Health = 13f;

            Pushing.Force = RandomMath.RandomBetween(1f, 1.5f);

            ComplexBehavior        = new SubsumptionBehavior();
            ComplexBehavior.Active = false; // initially, knight stays near square table.
            Add(ComplexBehavior);

            Combat = new CombatBehavior(typeof(RedGuard));
            ComplexBehavior.Add(Combat);

            ChasingHero                = new ChaseBehavior(Level.Current.hero);
            ChasingHero.ChaseRange     = 20f;
            ChasingHero.SatisfiedRange = 8f;
            ChasingHero.MoveSpeed      = RandomMath.RandomBetween(1.54f, 1.87f);
            ComplexBehavior.Add(ChasingHero);

            var tb = new PathFindToTargetBehavior()
            {
                ChaseTarget    = Level.Current.hero,
                ChaseRange     = 970f,
                SatisfiedRange = ChasingHero.ChaseRange - 2f
            };

            ComplexBehavior.Add(tb);

            ChasingRedGuard            = new ChaseBehavior(typeof(RedGuard), true);
            ChasingRedGuard.ChaseRange = 20f;
            ChasingRedGuard.MoveSpeed  = RandomMath.RandomBetween(1.1f, 1.5f);
            ComplexBehavior.Add(ChasingRedGuard);

            Attacking = new AttackBehavior(Level.Current.hero);
            Attacking.AttackDuration = RandomMath.RandomBetween(1.9f, 2.95f);
            ComplexBehavior.Add(Attacking);

            Wandering           = new RandomWanderBehavior(15.7f, 23.3f);
            Wandering.MoveSpeed = RandomMath.RandomBetween(0.001f, 0.02f);
            ComplexBehavior.Add(Wandering);
        }
        public BadPixel(Thing chaseTarget)
            : base("shape2x2")
        {
            IsCollisionFree    = false;
            DrawInfo.DrawColor = new Color(255, 10, 4);

            SubsumptionBehavior sub = new SubsumptionBehavior();

            Add(sub);

            Chasing            = new ChaseBehavior(chaseTarget);
            Chasing.MoveSpeed  = RandomMath.RandomBetween(0.47f, 0.75f);
            Chasing.ChaseRange = 6f; // RandomMath.RandomBetween(12f, 40f);
            sub.Add(Chasing);

            Turning           = new AlwaysTurnRightBehavior();
            Turning.MoveSpeed = Chasing.MoveSpeed; //RandomMath.RandomBetween(0.57f, 1.05f);
            Turning.MoveSpeed = 0.7f;
            sub.Add(Turning);

            Wandering           = new RandomWanderBehavior(2.7f, 11.3f);
            Wandering.MoveSpeed = 0.7f;
            sub.Add(Wandering);
        }