Example #1
0
        public EnemyScripted(Game game, List<Vector2> waypoints, bool isBoss)
            : base(game)
        {
            this.waypoints = waypoints;
            this.isBoss = isBoss;
            this.Health = 100;

            this.Position = waypoints.First();
            waypoints.RemoveAt(0);
            this.targetPosition = waypoints.First();

            this.behaviourStrategy = new BehaviourStrategySeek();
            this.shootingStrategy = new WeaponStrategyEnemyA();

            this.Game.Components.Add(this);

            this.weapon = new WeaponEnemyA(this.Game); // Todo: Factory
            this.Game.Components.Add(this.weapon);
        }
Example #2
0
 public Actor(IBehaviourStrategy behaviour)
 {
     Behaviour = behaviour;
 }
Example #3
0
        protected override void InitializeStateMachine()
        {
            var alive = new State<Action<double>>(
                EnemyState.Alive,
                null,
                null,
                null);

            var patrol = new State<Action<double>>(
                EnemyState.Patrol,
                delegate { this.targetPosition = this.waypoints.First(); },
                delegate
                    {
                        this.behaviourStrategy = this.behaviourStrategySeek;
                        this.shootingStrategy = null;

                        this.IsHealthAdded = false;
                        this.IsHealthSubtracted = false;
                    },
                null);

            var attack = new State<Action<double>>(
                EnemyState.Attack,
                delegate { this.targetPosition = this.PlayerPosition; },
                delegate
                    {
                        this.behaviourStrategy = this.behaviourStrategySeek;
                        this.shootingStrategy = new WeaponStrategyEnemyA();

                        this.IsHealthAdded = false;
                        this.IsHealthSubtracted = false;
                    },
                null);

            var retreat = new State<Action<double>>(
                EnemyState.Retreat,
                delegate { this.targetPosition = this.PlayerPosition; },
                delegate
                    {
                        this.behaviourStrategy = this.behaviourStrategyFlee;
                        this.shootingStrategy = null;

                        this.IsHealthAdded = false;
                        this.IsHealthSubtracted = false;
                    },
                null);

            var dying = new State<Action<double>>(
                EnemyState.Dying,
                null,
                delegate
                    {
                        this.behaviourStrategy = null;
                        this.shootingStrategy = null;

                        this.IsHealthAdded = false;
                        this.IsHealthSubtracted = false;
                    },
                null);

            var dead = new State<Action<double>>(
                EnemyState.Dead,
                null,
                () => this.Game.Components.Remove(this),
                null);

            alive.AddTransition(patrol, () => true);

            patrol.AddTransition(attack, () => new Vector2(this.PlayerPosition.X - this.Position.X, this.PlayerPosition.Y - this.Position.Y).Length() < 200);
            patrol.AddTransition(retreat, () => this.IsHealthSubtracted);
            patrol.AddTransition(dying, () => this.Health <= 0);

            attack.AddTransition(retreat, () => this.IsHealthSubtracted);
            attack.AddTransition(patrol, () => new Vector2(this.PlayerPosition.X - this.Position.X, this.PlayerPosition.Y - this.Position.Y).Length() > 200);
            attack.AddTransition(dying, () => this.Health <= 0);

            //retreat.AddTransition(attack, () => ...); <- Should that be even possible?
            retreat.AddTransition(patrol, () => new Vector2(this.PlayerPosition.X - this.Position.X, this.PlayerPosition.Y - this.Position.Y).Length() > 200);
            retreat.AddTransition(dying, () => this.Health <= 0);

            dying.AddTransition(dead, () => this.spriteManager.IsAnimationDone(this.stateMachine.CurrentState.Name));

            this.stateMachine = new StateMachine<Action<double>>(alive);
        }