/// <summary> /// Constructor for a unit /// </summary> /// <param name="owner">Owner</param> /// <param name="health">Current Health</param> public Unit(Player.Player owner, short health) : base(owner, health) { this.entityType = EntityType.Unit; this.stats = new UnitStats(); attackStance = AttackStance.Guard; }
/// <summary> /// Set the Unit's AttackStance. /// </summary> /// <param name="stance"></param> public void setAttackStance(AttackStance stance) { this.attackStance = stance; if (stance == AttackStance.Guard) { this.guardCell = myCell; } else if (stance == AttackStance.Agressive) { this.guardCell = null; } }
protected override void Initialize() { roar_clip = Resources.Load("Sounds/BOSS_roar") as AudioClip; footstep_clip = Resources.Load("Sounds/footsteps1") as AudioClip; fissure = Resources.Load("Skills/FireFissure") as GameObject; player = GameObject.FindGameObjectWithTag("Player"); playerHealth = player.GetComponent <Player>(); maxHealth = health; currentState = FSMState.Chase; currentAttackStance = AttackStance.NORMAL; animator = GetComponent <Animator>(); source = GetComponent <AudioSource>(); rigidBody = GetComponent <Rigidbody>(); avoidance = GetComponent <Avoidance>(); }
protected override void FSMUpdate() { base.FSMUpdate(); DebuggingInput(); bossGUI.SetActive(Vector3.Distance(player.transform.position, transform.position) <= cameraShakeRange); if (health <= 0) { currentAttackStance = AttackStance.BROKEN; attackRange *= 4; attackAngle = 10; health = 600; isChasing = false; IsSwinging = false; currentState = FSMState.Overpowered; } }
public override void Update(GameTime gameTime, TeeEngine engine) { // Get the Hero player for interaction purposes. Hero player = (Hero)engine.GetEntity("Player"); Vector2 prevPos = Pos; // Check if this Bat has died. if (HP <= 0) { this.Opacity -= 0.02f; this.Drawables.ResetState(CurrentDrawableState, gameTime); if (this.Opacity < 0) { engine.RemoveEntity(this); } } else { // ATTACKING LOGIC. if (_attackStance == AttackStance.Attacking) { this.Pos.X -= (float)(Math.Cos(_attackAngle) * _attackSpeed); this.Pos.Y -= (float)(Math.Sin(_attackAngle) * _attackSpeed); this._attackHeight.Y += 30.0f / ATTACK_COUNTER_LIMIT; this.Drawables.SetGroupProperty("Body", "Offset", _attackHeight); if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime)) { player.HP -= 3; } if (_attackCounter++ == ATTACK_COUNTER_LIMIT) { _attackStance = AttackStance.NotAttacking; } } // ATTACK PREPERATION LOGIC. else if (_attackStance == AttackStance.Preparing) { _attackHeight.Y -= 2; if (_attackHeight.Y < -40) { _attackHeight.Y = -40; _attackAngle = Math.Atan2( this.Pos.Y - player.Pos.Y, this.Pos.X - player.Pos.X ); _attackStance = AttackStance.Attacking; _attackCounter = 0; } Drawables.SetGroupProperty("Body", "Offset", _attackHeight); } // NON-ATTACKING LOGIC. PATROL AND APPROACH. else if (_attackStance == AttackStance.NotAttacking) { double distance = Vector2.Distance(player.Pos, this.Pos); if (distance < AGRO_DISTANCE) { // Move towards the player for an attack move. double angle = Math.Atan2( player.Pos.Y - this.Pos.Y, player.Pos.X - this.Pos.X ); // Approach Function. double moveValue; if (distance < ATTACK_DISTANCE) { _attackStance = AttackStance.Preparing; moveValue = 0; } else { moveValue = _moveSpeed; } Pos.X += (float)(Math.Cos(angle) * moveValue); Pos.Y += (float)(Math.Sin(angle) * moveValue); } else { // Perform a standard patrol action. Pos.X += (float)(Math.Cos(gameTime.TotalGameTime.TotalSeconds - _randomModifier * 90) * 2); } } // Determine the animation based on the change in position. if (Math.Abs(prevPos.X - Pos.X) > Math.Abs(prevPos.Y - Pos.Y)) { if (prevPos.X < Pos.X) { this.CurrentDrawableState = "Right"; } if (prevPos.X > Pos.X) { this.CurrentDrawableState = "Left"; } } else { if (prevPos.Y < Pos.Y) { this.CurrentDrawableState = "Down"; } if (prevPos.Y > Pos.Y) { this.CurrentDrawableState = "Up"; } } } }
public override void Update(GameTime gameTime, TeeEngine engine) { // Get the Hero player for interaction purposes. Hero player = (Hero)engine.GetEntity("Player"); Vector2 prevPos = Pos; // Check if this Bat has died. if (HP <= 0) { this.Opacity -= 0.02f; this.Drawables.ResetState(CurrentDrawableState, gameTime); if (this.Opacity < 0) engine.RemoveEntity(this); } else { // ATTACKING LOGIC. if (_attackStance == AttackStance.Attacking) { this.Pos.X -= (float) (Math.Cos(_attackAngle) * _attackSpeed); this.Pos.Y -= (float) (Math.Sin(_attackAngle) * _attackSpeed); this._attackHeight.Y += 30.0f / ATTACK_COUNTER_LIMIT; this.Drawables.SetGroupProperty("Body", "Offset", _attackHeight); if (Entity.IntersectsWith(this, "Shadow", player, "Shadow", gameTime)) player.HP -= 3; if (_attackCounter++ == ATTACK_COUNTER_LIMIT) _attackStance = AttackStance.NotAttacking; } // ATTACK PREPERATION LOGIC. else if (_attackStance == AttackStance.Preparing) { _attackHeight.Y -= 2; if (_attackHeight.Y < -40) { _attackHeight.Y = -40; _attackAngle = Math.Atan2( this.Pos.Y - player.Pos.Y, this.Pos.X - player.Pos.X ); _attackStance = AttackStance.Attacking; _attackCounter = 0; } Drawables.SetGroupProperty("Body", "Offset", _attackHeight); } // NON-ATTACKING LOGIC. PATROL AND APPROACH. else if (_attackStance == AttackStance.NotAttacking) { double distance = Vector2.Distance(player.Pos, this.Pos); if (distance < AGRO_DISTANCE) { // Move towards the player for an attack move. double angle = Math.Atan2( player.Pos.Y - this.Pos.Y, player.Pos.X - this.Pos.X ); // Approach Function. double moveValue; if (distance < ATTACK_DISTANCE) { _attackStance = AttackStance.Preparing; moveValue = 0; } else moveValue = _moveSpeed; Pos.X += (float)(Math.Cos(angle) * moveValue); Pos.Y += (float)(Math.Sin(angle) * moveValue); } else { // Perform a standard patrol action. Pos.X += (float)(Math.Cos(gameTime.TotalGameTime.TotalSeconds - _randomModifier * 90) * 2); } } // Determine the animation based on the change in position. if (Math.Abs(prevPos.X - Pos.X) > Math.Abs(prevPos.Y - Pos.Y)) { if (prevPos.X < Pos.X) this.CurrentDrawableState = "Right"; if (prevPos.X > Pos.X) this.CurrentDrawableState = "Left"; } else { if (prevPos.Y < Pos.Y) this.CurrentDrawableState = "Down"; if (prevPos.Y > Pos.Y) this.CurrentDrawableState = "Up"; } } }
public Unit(Player.Player owner, UnitStats stats) : base(owner, stats.maxHealth) { this.stats = stats; this.entityType = EntityType.Unit; attackStance = AttackStance.Guard; }