public override void GetHitKick(DirectionTarget cameFrom, int damage) { this.IsAttacking = false; this.Health -= damage; if (CheckForDeath()) { SoundManager.PlaySound("GetHit-Died"); GetKnockedDown(cameFrom, 0); return; } // Set state and tetxture state = DeejayCloseState.TakeHitLowKick; texture = Game1.SprDeejayWalkIdle; frameX = 0; frameY = 3; drawWidth = DRAW_WIDTH_TAKEHITLOW; drawHeight = DRAW_HEIGHT_TAKEHITLOW; SetDrawArea(); // Play Sound SoundManager.PlaySound("GetHit02"); // Face the man who beat you if (cameFrom == DirectionTarget.Left) { FacingDir = DirectionTarget.Right; } else { FacingDir = DirectionTarget.Left; } }
public override void GetKnockedDown(DirectionTarget cameFrom, int damage) { // Set state and texture IsAttackable = false; this.IsAttacking = false; state = DeejayCloseState.KnockedDown; texture = Game1.SprDeejayWalkIdle; frameX = 0; frameY = 4; drawWidth = DRAW_WIDTH_KNOCKDOWN; drawHeight = DRAW_HEIGHT_TAKEHIT; originCharacters = new Vector2((drawWidth / 2), drawHeight); SetDrawArea(); // Play Sound SoundManager.PlaySound("GetHit03"); // Face the man who beat you if (cameFrom == DirectionTarget.Right) { FacingDir = DirectionTarget.Left; } else { FacingDir = DirectionTarget.Right; } this.Health -= damage; }
private void DecideWhatToDo() { if (Game1.Random.NextDouble() < 0.5d) { // Decide to retreat GetRetreatTarget(); // Set time to be in Retreat STate stateTime = (float)(Game1.Random.NextDouble() + 1.8); } else { // ATTACK if (NoOtherEnemiesAttacking()) { this.IsAttacking = true; this.state = DeejayCloseState.MoveTo; frameX = 0; drawWidth = DRAW_WIDTH_WALK; } //else // ???????????????????????? - They wont wait until other enemy is done fighting with player //{ // GetRetreatTarget(); //} } }
public override void GetKnockedDown(DirectionTarget cameFrom, int damage) { // Set state and texture this.IsAttackable = false; this.IsAttacking = false; this.Health -= damage; this.state = DeejayCloseState.KnockedDown; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_KNOCKDOWN, DRAW_HEIGHT_TAKEHIT, 0, 4); this.SetOriginPosition("bottom"); this.SetDrawArea(); // Face the man who beat you if (cameFrom == DirectionTarget.Right) { FacingDir = DirectionTarget.Left; } else { FacingDir = DirectionTarget.Right; } SoundManager.PlaySound("GetHit03"); }
public override void GetHitKick(DirectionTarget cameFrom, int damage) { this.IsAttacking = false; this.Health -= damage; if (this.CheckForDeath()) { SoundManager.PlaySound("GetHit-Died"); GetKnockedDown(cameFrom, 0); return; } // Set state and tetxture this.state = DeejayCloseState.TakeHitLowKick; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_TAKEHITLOW, DRAW_HEIGHT_TAKEHITLOW, 0, 3); // this.SetOriginPosition("bottom"); this.SetDrawArea(); // Face the man who beat you if (cameFrom == DirectionTarget.Left) { FacingDir = DirectionTarget.Right; } else { FacingDir = DirectionTarget.Left; } SoundManager.PlaySound("GetHit02"); }
public void SetToLayingDown(DirectionTarget facingDir) { this.FacingDir = facingDir; this.state = DeejayCloseState.LayingDown; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_WAIT, DRAW_HEIGHT_WAIT, 0, 7); this.SetOriginPosition("bottom"); this.SetDrawArea(); }
public void SetToWait(DirectionTarget facingDir) { this.FacingDir = facingDir; this.state = DeejayCloseState.Wait; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_IDLE, DRAW_HEIGHT_NORMAL, 0, 0); this.SetOriginPosition("bottom"); this.SetDrawArea(); }
public void SetToLayingDown(DirectionTarget facingDir) { texture = Game1.SprDeejayWalkIdle; drawWidth = DRAW_WIDTH_WAIT; drawHeight = DRAW_HEIGHT_WAIT; frameX = 0; frameY = 7; SetDrawArea(); state = DeejayCloseState.LayingDown; this.originCharacters = new Vector2((drawWidth / 2), drawHeight); this.FacingDir = facingDir; }
public void SetToWait(DirectionTarget facingDir) { texture = Game1.SprDeejayWalkIdle; drawWidth = DRAW_WIDTH_IDLE; drawHeight = DRAW_HEIGHT_NORMAL; frameX = 0; frameY = 0; SetDrawArea(); state = DeejayCloseState.Wait; this.originCharacters = new Vector2((drawWidth / 2), drawHeight); this.FacingDir = facingDir; }
private void AnimateKnockDown(GameTime gT) { float calcDistance = 0; this.CurrentFrameTime += (float)gT.ElapsedGameTime.TotalSeconds; if (this.CurrentFrameTime >= Actor.FrameRate * 0.5f) { if (this.FacingDir == DirectionTarget.Left) { calcDistance = ((this.Position.X + 150) - this.Position.X) * 20f * Camera.Elasticity; } else { calcDistance = ((this.Position.X - 150) - this.Position.X) * 20f * Camera.Elasticity; } this.Position.X = this.Position.X + calcDistance; this.CurrentFrameTime = 0f; this.FrameX++; if (this.FrameX == 1 && CheckForDeath() && this.FrameY == 4) { SoundManager.PlaySound("GetHit-Died"); } if (this.FrameX > 3 && this.FrameY == 5) { if (CheckForDeath()) { state = DeejayCloseState.Dying; stateTime = 1f; this.FrameX = 2; return; } // Set state and texture state = DeejayCloseState.Down; this.FrameX = 2; stateTime = 0f; return; } if (this.FrameX > 6 && this.FrameY == 4) { this.FrameX = 0; this.FrameY++; } this.SetDrawArea(); } }
public void GetUpAnimation() { this.IsAttacking = false; this.IsAttackable = true; this.state = DeejayCloseState.GettingUp; this.CurrentFrameTime = 0; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_GETTINGUP, DRAW_HEIGHT_TAKEHIT, 0, 6); this.SetDrawArea(); this.SetOriginPosition("bottom"); this.UpdateHitArea(); }
public void GetUpAnimation() { this.IsAttacking = false; texture = Game1.SprDeejayWalkIdle; IsAttackable = true; state = DeejayCloseState.GettingUp; currentFrameTime = 0f; frameX = 0; frameY = 6; drawWidth = DRAW_WIDTH_GETTINGUP; drawHeight = DRAW_HEIGHT_TAKEHIT; SetDrawArea(); originCharacters = new Vector2(drawWidth / 2, drawHeight); }
private void GetRetreatTarget() { state = DeejayCloseState.Retreat; // Retreat to which side of the player if (Game1.Random.NextDouble() < 0.5d) { // Go LEFT of the player retreatTarget.X = Game1.Random.Next((int)(InLevel.Player1.Position.X - 200), (int)(InLevel.Player1.Position.X - 100)); // Is this position off screen if (retreatTarget.X < Camera.Position.X - Game1.SCREEN_WIDTH / 2) { // go to the Right Side of Player retreatTarget.X = Game1.Random.Next((int)(InLevel.Player1.Position.X + 100), (int)(InLevel.Player1.Position.X + 200)); } } else { // go to the Right Side of Player retreatTarget.X = Game1.Random.Next((int)(InLevel.Player1.Position.X + 100), (int)(InLevel.Player1.Position.X + 200)); // Is this position off screen if (retreatTarget.X < Camera.Position.X - Game1.SCREEN_WIDTH / 2) { // Go LEFT of the player retreatTarget.X = Game1.Random.Next((int)(InLevel.Player1.Position.X - 200), (int)(InLevel.Player1.Position.X - 100)); } } // Get Y Retreat Target //int range = InLevel.PlayBounds.Bottom - InLevel.PlayBounds.Top; //float percent = (float)Game1.Random.NextDouble(); //retreatTarget.Y = percent * range + InLevel.PlayBounds.Top; retreatTarget.Y = Game1.Random.Next(InLevel.PlayBounds.Top, InLevel.PlayBounds.Bottom); }
public override void Update(GameTime gT) { switch (state) { #region Retreat State case DeejayCloseState.Retreat: stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (stateTime <= 0) { // Run out of time DecideWhatToDo(); } else { // Retreat to retreatTarget // Move to X Target if (Position.X < retreatTarget.X) // target is to the RIGHT { this.Position.X += ACTOR_X_SPEED + ACTOR_X_RETREAT_SPEED; if (Position.X > retreatTarget.X) // Gone too far { Position.X = retreatTarget.X; } } else // Target to the LEFT { this.Position.X -= ACTOR_X_SPEED + ACTOR_X_RETREAT_SPEED; if (Position.X < retreatTarget.X) // Gone too far { Position.X = retreatTarget.X; } } // Move to Y Location if (Position.Y < retreatTarget.Y) // target is Below US { this.Position.Y += ACTOR_Y_SPEED + ACTOR_Y_RETREAT_SPEED; if (Position.Y > retreatTarget.Y) // Gone too far { Position.Y = retreatTarget.Y; } } else // Target is above us { this.Position.Y -= ACTOR_Y_SPEED + ACTOR_Y_RETREAT_SPEED; if (Position.Y < retreatTarget.Y) // Gone too far { Position.Y = retreatTarget.Y; } } // Make sure this enemy is always facing Player if (Position.X < InLevel.Player1.Position.X) // to the right of use { this.FacingDir = DirectionTarget.Right; } else // to the left { this.FacingDir = DirectionTarget.Left; } // Which animation to use if (this.Position == retreatTarget) { // At location IDLE frameY = 0; drawWidth = DRAW_WIDTH_IDLE; //drawHeight = DRAW_HEIGHT_NORMAL; ; originCharacters = new Vector2(drawWidth / 2, drawHeight); AnimateIdle(gT); } else { // Not at location drawWidth = DRAW_WIDTH_WALK; //drawHeight = DRAW_HEIGHT_NORMAL; originCharacters = new Vector2(drawWidth / 2, drawHeight); AnimateWalking(gT); } } break; #endregion #region MoveTo case DeejayCloseState.MoveTo: // Are we lined up with player bool linedUpX = LinedUpXWithPlayer(); bool linedUpY = LinedUpYWithPlayer(); if (linedUpX && linedUpY) { // Set Pre-Attack State frameX = 0; frameY = 0; state = DeejayCloseState.PreAttack; drawWidth = DRAW_WIDTH_IDLE; originCharacters = new Vector2(drawWidth / 2, drawHeight); SetDrawArea(); // How long do we stay in the pre-attack state stateTime = 0.5f * (float)Game1.Random.NextDouble(); break; } AnimateWalking(gT); break; #endregion #region Pre Attack case DeejayCloseState.PreAttack: // Am I still lined up with the player if (LinedUpXWithPlayer() && LinedUpYWithPlayer()) { // Have we been in this state long enough? stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (stateTime < 0) { // Is Player Attackable if (!InLevel.Player1.IsAttackable) { GetRetreatTarget(); break; } // if (NoOtherEnemiesAttacking()) //{ // Its time to attack texture = Game1.SprDeejayAttacks; frameX = 0; frameY = D_ATTACK01_COMBO1_FRAME_Y; drawWidth = D_WIDTH_COMBO1_ATTACK01; drawHeight = D_HEIGHT_COMBO1_ATTACK01; //originCharacters = new Vector2(drawWidth / 2, drawHeight); if (FacingDir == DirectionTarget.Left) { originCharacters = new Vector2((drawWidth / 2), drawHeight); } //originCharacters = new Vector2((drawWidth / 2) + 18, drawHeight + 2); else // Right { originCharacters = new Vector2((drawWidth / 2), drawHeight); } //originCharacters = new Vector2((drawWidth / 2) - 18, drawHeight + 2); SetDrawArea(); state = DeejayCloseState.Attack; SoundManager.PlaySound("ThrowPunch"); attackNumber = 1; //this.IsAttacking = true; //} } } else { // Not lined up with the player state = DeejayCloseState.MoveTo; frameX = 0; drawWidth = DRAW_WIDTH_WALK; originCharacters = new Vector2(drawWidth / 2, drawHeight); return; } AnimateIdle(gT); break; #endregion #region Attacks case DeejayCloseState.Attack: // Do Nothing switch (attackNumber) { case 1: // Animate AnimateAttack1(gT); break; case 2: // Animate AnimateAttack2(gT); break; case 3: // Animate AnimateAttack3(gT); break; } break; #endregion #region Take Hit and Die Cycle case DeejayCloseState.TakeHit: originCharacters = new Vector2((drawWidth / 2), drawHeight); //originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight); AnimateTakeHit(gT); break; case DeejayCloseState.TakeHitLowKick: originCharacters = new Vector2((drawWidth / 2), drawHeight); //originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight); AnimateTakeHitKick(gT); break; case DeejayCloseState.KnockedDown: //drawWidth = DRAW_WIDTH_KNOCKDOWN; originCharacters = new Vector2((drawWidth / 2), drawHeight); //originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight); AnimateKnockDown(gT); break; case DeejayCloseState.Down: stateTime += (float)gT.ElapsedGameTime.TotalSeconds; if (stateTime >= Actor.DOWN_TIME) { // Set up Gettign Up Animation state = DeejayCloseState.GettingUp; currentFrameTime = 0f; frameX = 0; frameY = 6; drawWidth = DRAW_WIDTH_GETTINGUP; drawHeight = DRAW_HEIGHT_NORMAL; originCharacters = new Vector2(drawWidth / 2, drawHeight); SetDrawArea(); } break; case DeejayCloseState.GettingUp: AnimateGettingUp(gT); break; case DeejayCloseState.Dying: // Flash the Body a few times stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (stateTime <= 0) { stateTime = ENEMY_DEATH_FLASH_TIME; IsVisible = !IsVisible; DeathFlashes++; if (DeathFlashes >= 8) { // Will I drop a item if (Game1.Random.NextDouble() >= 0.5f) // 0.9 = 10% chance of dropping item { this.InLevel.GameItems.Add( new PickUpStone(this.InLevel, this.Position)); } // Actor is Dead RemoveActorFromLevel(); } } break; #endregion #region Waiting case DeejayCloseState.Wait: AnimateWaiting(gT); break; #endregion #region Laying Down case DeejayCloseState.LayingDown: AnimateLayingDownWaiting(gT); break; #endregion } }
public override void Update(GameTime gT) { switch (this.state) { #region Retreat State case DeejayCloseState.Retreat: this.stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (this.stateTime <= 0) { // Ran out of time, make a decision on what to do next this.DecideWhatToDo(); } else { // Retreat to retreatTarget // Move to X Target if (this.Position.X < this.retreatTarget.X) // target is to the RIGHT { this.Position.X += ACTOR_X_SPEED + ACTOR_X_RETREAT_SPEED; if (this.Position.X > this.retreatTarget.X) // Gone too far { this.Position.X = this.retreatTarget.X; } } else // Target to the LEFT { this.Position.X -= ACTOR_X_SPEED + ACTOR_X_RETREAT_SPEED; if (this.Position.X < this.retreatTarget.X) // Gone too far { this.Position.X = this.retreatTarget.X; } } // Move to Y Location if (this.Position.Y < this.retreatTarget.Y) // target is Below US { this.Position.Y += ACTOR_Y_SPEED + ACTOR_Y_RETREAT_SPEED; if (this.Position.Y > this.retreatTarget.Y) // Gone too far { this.Position.Y = this.retreatTarget.Y; } } else // Target is above us { this.Position.Y -= ACTOR_Y_SPEED + ACTOR_Y_RETREAT_SPEED; if (this.Position.Y < this.retreatTarget.Y) // Gone too far { this.Position.Y = this.retreatTarget.Y; } } // Make sure this enemy is always facing Player if (this.Position.X < this.InLevel.Player1.Position.X) // to the right of use { this.FacingDir = DirectionTarget.Right; } else // to the left { this.FacingDir = DirectionTarget.Left; } // Which animation to use if (this.Position == this.retreatTarget) { this.InitSpriteFrames(DRAW_WIDTH_IDLE, this.DrawHeight, this.FrameX, 0); this.SetOriginPosition("bottom"); AnimateIdle(gT); } else { this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, this.FrameX, this.FrameY); this.SetOriginPosition("bottom"); AnimateWalking(gT); } } break; #endregion #region MoveTo case DeejayCloseState.MoveTo: // Are we lined up with player bool linedUpX = LinedUpXWithPlayer(); bool linedUpY = LinedUpYWithPlayer(); if (linedUpX && linedUpY) { // Set Pre-Attack State this.state = DeejayCloseState.PreAttack; this.InitSpriteFrames(DRAW_WIDTH_IDLE, this.DrawHeight, 0, 0); this.SetOriginPosition("bottom"); this.SetDrawArea(); // How long do we stay in the pre-attack state this.stateTime = 0.5f * (float)Game1.Random.NextDouble(); break; } AnimateWalking(gT); break; #endregion #region Pre Attack case DeejayCloseState.PreAttack: // Am I still lined up with the player if (LinedUpXWithPlayer() && LinedUpYWithPlayer()) { // Have we been in this state long enough? this.stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (this.stateTime < 0) { // Is Player Attackable if (!InLevel.Player1.IsAttackable) { this.GetRetreatTarget(); break; } // if (NoOtherEnemiesAttacking()) // { // Its time to attack this.state = DeejayCloseState.Attack; this.Sprite = Texture_Attack; this.InitSpriteFrames(D_WIDTH_COMBO1_ATTACK01, D_HEIGHT_COMBO1_ATTACK01, 0, D_ATTACK01_COMBO1_FRAME_Y); if (FacingDir == DirectionTarget.Left) { this.SetOriginPosition("bottom"); } else { this.SetOriginPosition("bottom"); } this.SetDrawArea(); this.attackNumber = 1; SoundManager.PlaySound("ThrowPunch"); // this.IsAttacking = true; // } } } else { // Not lined up with the player state = DeejayCloseState.MoveTo; this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, 0, this.FrameY); this.SetOriginPosition("bottom"); return; } AnimateIdle(gT); break; #endregion #region Attacks case DeejayCloseState.Attack: // Do Nothing switch (attackNumber) { case 1: // Animate AnimateAttack1(gT); break; case 2: // Animate AnimateAttack2(gT); break; case 3: // Animate AnimateAttack3(gT); break; } break; #endregion #region Take Hit and Die Cycle case DeejayCloseState.TakeHit: this.SetOriginPosition("bottom"); AnimateTakeHit(gT); break; case DeejayCloseState.TakeHitLowKick: this.SetOriginPosition("bottom"); AnimateTakeHitKick(gT); break; case DeejayCloseState.KnockedDown: this.SetOriginPosition("bottom"); AnimateKnockDown(gT); break; case DeejayCloseState.Down: stateTime += (float)gT.ElapsedGameTime.TotalSeconds; if (stateTime >= Actor.DOWN_TIME) { // Set up Gettign Up Animation this.state = DeejayCloseState.GettingUp; this.CurrentFrameTime = 0; this.InitSpriteFrames(DRAW_WIDTH_GETTINGUP, DRAW_HEIGHT_NORMAL, 0, 6); this.SetOriginPosition("bottom"); this.SetDrawArea(); } break; case DeejayCloseState.GettingUp: AnimateGettingUp(gT); break; case DeejayCloseState.Dying: // Flash the Body a few times this.stateTime -= (float)gT.ElapsedGameTime.TotalSeconds; if (this.stateTime <= 0) { this.stateTime = ENEMY_DEATH_FLASH_TIME; this.IsVisible = !this.IsVisible; this.DeathFlashes++; if (this.DeathFlashes >= 8) { // Will I drop a item if (Game1.Random.NextDouble() >= 0.5f) // 0.9 = 10% chance of dropping item { this.InLevel.GameItems.Add(new PickUpStone(this.InLevel, this.Position)); } // Actor is Dead this.RemoveActorFromLevel(); } } break; #endregion #region Waiting case DeejayCloseState.Wait: AnimateWaiting(gT); break; #endregion #region Laying Down case DeejayCloseState.LayingDown: AnimateLayingDownWaiting(gT); break; #endregion } }