public override void GetKnockedDown(DirectionTarget cameFrom, int damage) { // Set state and texture this.IsAttackable = false; this.IsAttacking = false; this.Health -= damage; this.state = RolentoEnemyRangedState.KnockedDown; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_KNOCKDOWN, DRAW_HEIGHT_TAKEHIT, 3, 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("RolentoGetHit02"); }
private void AnimateKnockDown(GameTime gT) { currentFrameTime += (float)gT.ElapsedGameTime.TotalSeconds; if (currentFrameTime >= Actor.FrameRate * 1.2f) { currentFrameTime = 0f; frameX++; if (frameX == 4 && CheckForDeath() && frameY == 4) { SoundManager.PlaySound("RolentoDye"); } if (frameX > 5 && frameY == 5) { if (CheckForDeath()) { //SoundManager.PlaySound("GetHit-Died"); state = RolentoEnemyRangedState.Dying; stateTime = 1f; frameX = 4; return; } // Set state and texture state = RolentoEnemyRangedState.Down; frameX = 4; stateTime = 0f; return; } if (frameX > 6 && frameY == 4) { frameX = 0; frameY++; } SetDrawArea(); } }
public override void GetHitKick(DirectionTarget cameFrom, int damage) { this.IsAttacking = false; this.Health -= damage; if (this.CheckForDeath()) { SoundManager.PlaySound("RolentoDye"); GetKnockedDown(cameFrom, 0); return; } // Set state and tetxture this.state = RolentoEnemyRangedState.TakeHitLowKick; this.Sprite = Texture_Walk_Idle; this.InitSpriteFrames(DRAW_WIDTH_TAKEHITLOW, DRAW_HEIGHT_TAKEHITLOW, 0, 4); this.SetDrawArea(); // Face the man who beat you if (cameFrom == DirectionTarget.Left) { FacingDir = DirectionTarget.Right; } else { FacingDir = DirectionTarget.Left; } SoundManager.PlaySound("RolentoGetHit"); }
public override void GetKnockedDown(DirectionTarget cameFrom, int damage) { // Set state and texture IsAttackable = false; this.IsAttacking = false; state = RolentoEnemyRangedState.KnockedDown; texture = Game1.SprRolentoWalkIdle; frameX = 3; frameY = 4; drawWidth = DRAW_WIDTH_KNOCKDOWN; drawHeight = DRAW_HEIGHT_TAKEHIT; originCharacters = new Vector2((drawWidth / 2), drawHeight); SetDrawArea(); // Play Sound SoundManager.PlaySound("RolentoGetHit02"); // Face the man who beat you if (cameFrom == DirectionTarget.Right) { FacingDir = DirectionTarget.Left; } else { FacingDir = DirectionTarget.Right; } this.Health -= damage; }
public override void GetHitKick(DirectionTarget cameFrom, int damage) { this.IsAttacking = false; this.Health -= damage; if (CheckForDeath()) { SoundManager.PlaySound("RolentoDye"); GetKnockedDown(cameFrom, 0); return; } // Set state and tetxture state = RolentoEnemyRangedState.TakeHitLowKick; texture = Game1.SprRolentoWalkIdle; frameX = 0; frameY = 4; drawWidth = DRAW_WIDTH_TAKEHITLOW; drawHeight = DRAW_HEIGHT_TAKEHITLOW; SetDrawArea(); // Play Sound SoundManager.PlaySound("RolentoGetHit"); // Face the man who beat you if (cameFrom == DirectionTarget.Left) { FacingDir = DirectionTarget.Right; } else { FacingDir = DirectionTarget.Left; } }
private bool LinedUpXWithPlayerRanged() { // is the player to the left or right if (this.Position.X < InLevel.Player1.Position.X) // Player is to the left { // If far enouggh away if (this.Position.X < InLevel.Player1.Position.X - THROW_STONE_SAFE_DISTANCE) { return(true); } else { // Move left a bit, get more distance this.Position.X -= ACTOR_X_SPEED; FacingDir = DirectionTarget.Right; // Did this movement just take 'this' OFFSCREEN? if (this.Position.X < Camera.Position.X - Game1.SCREEN_WIDTH / 2) { this.state = RolentoEnemyRangedState.MoveTo; } return(false); } } // is the player to the left or right else if (this.Position.X >= InLevel.Player1.Position.X) // Player is to the right { // If far enouggh away if (this.Position.X > InLevel.Player1.Position.X + THROW_STONE_SAFE_DISTANCE) { return(true); } else { // Move Right a bit, get more distance this.Position.X += ACTOR_X_SPEED; FacingDir = DirectionTarget.Left; // Did this movement just take 'this' OFFSCREEN? if (this.Position.X > Camera.Position.X + Game1.SCREEN_WIDTH / 2) { this.state = RolentoEnemyRangedState.MoveTo; } return(false); } } return(false); }
private void DecideWhatToDo() { if (Game1.Random.NextDouble() < 0.5d) { // Decide to retreat GetRetreatTarget(); // Set time to be in Retreat State this.stateTime = (float)(Game1.Random.NextDouble() + 1.8); } else { this.state = RolentoEnemyRangedState.MoveAway; this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, 0, this.FrameY); } }
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 { this.state = RolentoEnemyRangedState.MoveAway; frameX = 0; drawWidth = DRAW_WIDTH_WALK; } }
private void GetRetreatTarget() { state = RolentoEnemyRangedState.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 (this.state) { #region Retreat State case RolentoEnemyRangedState.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 this.InitSpriteFrames(DRAW_WIDTH_IDLE, this.DrawHeight, this.FrameX, 0); this.SetOriginPosition("bottom"); AnimateIdle(gT); } else { // Not at location this.InitSpriteFrames(DRAW_WIDTH_WALK, DRAW_HEIGHT_NORMAL, this.FrameX, 2); this.SetOriginPosition("bottom"); AnimateWalking(gT); } } break; #endregion #region MoveTo - move to the Player, for attacking case RolentoEnemyRangedState.MoveTo: // Are we lined up with player bool linedUpX = LinedUpXWithPlayerClose(); bool linedUpY = LinedUpYWithPlayer(); if (linedUpX && linedUpY) { // Set Pre-Attack State this.InitSpriteFrames(DRAW_WIDTH_IDLE, this.DrawHeight, 0, 0); this.SetOriginPosition("bottom"); this.SetDrawArea(); this.state = RolentoEnemyRangedState.PreAttack; // How long do we stay in the pre-attack state this.stateTime = 0.5f * (float)Game1.Random.NextDouble(); break; } AnimateWalking(gT); break; #endregion #region Move Away - MoveAway the Player, for case RolentoEnemyRangedState.MoveAway: // Are we lined up with player bool linedUpXRanged = LinedUpXWithPlayerRanged(); bool linedUpYRanged = LinedUpYWithPlayer(); if (linedUpXRanged && linedUpYRanged) { if (InLevel.Player1.IsAttackable) // Check if we can throw stone { // Throw Knife Animation this.Sprite = Texture_Attack; this.InitSpriteFrames(DRAW_WIDTH_THROW, DRAW_HEIGHT_THROW, 0, 5); this.SetOriginPosition("bottom"); this.SetDrawArea(); this.state = RolentoEnemyRangedState.ThrowStone; break; } else { GetRetreatTarget(); } } AnimateWalking(gT); break; #endregion #region ThrowKnife case RolentoEnemyRangedState.ThrowStone: AnimateThrowRock(gT); break; #endregion #region Pre Attack case RolentoEnemyRangedState.PreAttack: // Am I still lined up with the player if (LinedUpXWithPlayerClose() && 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) { GetRetreatTarget(); break; } // Its time to attack this.state = RolentoEnemyRangedState.Attack; this.Sprite = Texture_Attack; this.InitSpriteFrames(D_WIDTH_COMBO1_ATTACK01, D_HEIGHT_COMBO1_ATTACK01, 0, 0); this.SetOriginPosition("bottom"); this.SetDrawArea(); SoundManager.PlaySound("RolentoThrow"); SoundManager.PlaySound("RolentoLaugh2"); } } else { // Not lined up with the player this.state = RolentoEnemyRangedState.MoveTo; this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, 0, this.FrameY); this.SetOriginPosition("bottom"); return; } AnimateIdle(gT); break; #endregion #region Attacks case RolentoEnemyRangedState.Attack: AnimateKnockDownAttack(gT); break; #endregion #region Take Hit and Die Cycle case RolentoEnemyRangedState.TakeHit: this.SetOriginPosition("bottom"); AnimateTakeHit(gT); break; case RolentoEnemyRangedState.TakeHitLowKick: this.SetOriginPosition("bottom"); AnimateTakeHitKick(gT); break; case RolentoEnemyRangedState.KnockedDown: this.SetOriginPosition("bottom"); AnimateKnockDown(gT); break; case RolentoEnemyRangedState.Down: this.stateTime += (float)gT.ElapsedGameTime.TotalSeconds; if (this.stateTime >= Actor.DOWN_TIME) { // Set up Gettign Up Animation this.state = RolentoEnemyRangedState.GettingUp; this.Sprite = Texture_Walk_Idle; this.CurrentFrameTime = 0; this.InitSpriteFrames(DRAW_WIDTH_GETTINGUP, DRAW_HEIGHT_GETTINGUP, 0, 6); this.SetOriginPosition("bottom"); this.SetDrawArea(); } break; case RolentoEnemyRangedState.GettingUp: AnimateGettingUp(gT); break; case RolentoEnemyRangedState.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.1f) // 0.8 = 80% chance of dropping item { this.InLevel.GameItems.Add(new PickUpStone(this.InLevel, this.Position)); } // Actor is Dead RemoveActorFromLevel(); } } break; #endregion } }