public WeaponPlayerA(Game game) : base(game) { this.weaponStrategy = new WeaponStrategyA1(); this.weaponStrategyA1 = new WeaponStrategyA1(); this.weaponStrategyA2 = new WeaponStrategyA2(); }
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); }
public override void FireWeapon() { switch (this.UpgradeLevel) { case 1: this.weaponStrategy = this.weaponStrategyA1; if (this.weaponStrategy.Execute( () => this.TriggerWeaponFiredEvent(this, null), this.elapsedShotInterval, this.Shots, this.Position, this.Rotation, this.SpriteShot.Width, this.SpriteShot.Height, this.SpriteShotDataCached)) { this.elapsedShotInterval = 0; } break; case 2: this.weaponStrategy = this.weaponStrategyA2; if (this.weaponStrategy.Execute( () => this.TriggerWeaponFiredEvent(this, null), this.elapsedShotInterval, this.Shots, this.Position, this.Rotation, this.SpriteShot.Width, this.SpriteShot.Height, this.SpriteShotDataCached)) { this.elapsedShotInterval = 0; } break; } }
public Hero(IWeaponStrategy weaponStrategy) { _weaponStrategy = weaponStrategy; }
public void ChangeWeapon(IWeaponStrategy newWeaponStrategy) { _weaponStrategy = newWeaponStrategy; }
public Character(string name) { Name = name; _weapon = new NoWeaponStrategy(); }
public void ChangeWeapon(IWeaponStrategy weapon) { _weapon = weapon; }
protected override void InitializeStateMachine() { var alive = new State<Action<double>>( EnemyState.Alive, delegate { if (this.waypoints.Count != 0) { this.targetPosition = this.waypoints.First(); } }, null, null); var dying = new State<Action<double>>( EnemyState.Dying, null, delegate { 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(dying, () => this.Health <= 0 && this.isOffscreen == false); alive.AddTransition(dead, () => this.Health >= 0 && this.isOffscreen); dying.AddTransition(dead, () => this.spriteManager.IsAnimationDone(this.stateMachine.CurrentState.Name)); this.stateMachine = new StateMachine<Action<double>>(alive); }
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); }