Esempio n. 1
0
        private void AnimateKnockDown(GameTime gT)
        {
            this.CurrentFrameTime += (float)gT.ElapsedGameTime.TotalSeconds;
            if (this.CurrentFrameTime >= Actor.FrameRate * 1.2f)
            {
                this.CurrentFrameTime = 0f;
                this.FrameX++;

                if (this.FrameX == 1 && CheckForDeath())
                {
                    SoundManager.PlaySound("GetHit-Died");
                }

                if (this.FrameX > 7)
                {
                    if (CheckForDeath())
                    {
                        //SoundManager.PlaySound("GetHit-Died");
                        state       = EnemyRangedState.Dying;
                        stateTime   = 1f;
                        this.FrameX = 6;
                        return;
                    }
                    // Set state and texture
                    state       = EnemyRangedState.Down;
                    this.FrameX = 6;
                    stateTime   = 0f;
                    return;
                }
                SetDrawArea();
            }
        }
Esempio n. 2
0
        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
            this.state  = EnemyRangedState.TakeHitLowKick;
            this.Sprite = Texture_React;
            this.InitSpriteFrames(DRAW_WIDTH_TAKEHIT, DRAW_HEIGHT_TAKEHIT, 3, 6);
            this.SetDrawArea();
            this.SetOriginPosition("bottom");

            // Face the man who beat you
            if (cameFrom == DirectionTarget.Left)
            {
                FacingDir = DirectionTarget.Right;
            }
            else
            {
                FacingDir = DirectionTarget.Left;
            }

            SoundManager.PlaySound("GetHit02");
            SoundManager.PlaySound("GetHit-Shit");
        }
Esempio n. 3
0
        public override void GetKnockedDown(DirectionTarget cameFrom, int damage)
        {
            // Set state and texture
            this.IsAttackable = false;
            this.IsAttacking  = false;
            this.Health      -= damage;

            this.state  = EnemyRangedState.KnockedDown;
            this.Sprite = Texture_React;
            this.InitSpriteFrames(DRAW_WIDTH_KNOCKDOWN, DRAW_HEIGHT_TAKEHIT, 0, 1);
            this.SetDrawArea();
            this.SetOriginPosition("bottom");

            // Face the man who beat you
            if (cameFrom == DirectionTarget.Left)
            {
                FacingDir = DirectionTarget.Right;
            }
            else
            {
                FacingDir = DirectionTarget.Left;
            }

            SoundManager.PlaySound("GetHit03");
        }
Esempio n. 4
0
        public override void GetKnockedDown(DirectionTarget cameFrom, int damage)
        {
            // Set state and texture
            IsAttackable     = false;
            this.IsAttacking = false;
            state            = EnemyRangedState.KnockedDown;
            texture          = Game1.SprCharacterReact;
            frameX           = 0;
            frameY           = 1;
            drawWidth        = DRAW_WIDTH_KNOCKDOWN;
            drawHeight       = DRAW_HEIGHT_TAKEHIT;
            originCharacters = new Vector2((drawWidth / 2), drawHeight);
            SetDrawArea();

            // Play Sound
            //SoundManager.PlaySound("MetalSound2");
            SoundManager.PlaySound("GetHit03");

            // Face the man who beat you
            if (cameFrom == DirectionTarget.Right)
            {
                FacingDir = DirectionTarget.Left;
            }
            else
            {
                FacingDir = DirectionTarget.Right;
            }

            this.Health -= damage;
        }
Esempio n. 5
0
        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      = EnemyRangedState.TakeHitLowKick;
            texture    = Game1.SprCharacterReact;
            frameX     = 3;
            frameY     = 6;
            drawWidth  = DRAW_WIDTH_TAKEHIT;
            drawHeight = DRAW_HEIGHT_TAKEHIT;
            SetDrawArea();

            // Play Sound
            SoundManager.PlaySound("GetHit02");
            SoundManager.PlaySound("GetHit-Shit");

            // Face the man who beat you
            if (cameFrom == DirectionTarget.Left)
            {
                FacingDir = DirectionTarget.Right;
            }
            else
            {
                FacingDir = DirectionTarget.Left;
            }
        }
Esempio n. 6
0
        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 -= 2.5f;
                    FacingDir        = DirectionTarget.Right;

                    // Did this movement just take 'this' OFFSCREEN?
                    if (this.Position.X < Camera.Position.X - Game1.SCREEN_WIDTH / 2)
                    {
                        this.state = EnemyRangedState.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 += 2.5f;
                    FacingDir        = DirectionTarget.Left;

                    // Did this movement just take 'this' OFFSCREEN?
                    if (this.Position.X > Camera.Position.X + Game1.SCREEN_WIDTH / 2)
                    {
                        this.state = EnemyRangedState.MoveTo;
                    }


                    return(false);
                }
            }
            return(false);
        }
Esempio n. 7
0
        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 = EnemyRangedState.MoveAway;
                this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, 0, this.FrameY);
            }
        }
Esempio n. 8
0
        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 = EnemyRangedState.MoveAway;
                frameX     = 0;
                drawWidth  = DRAW_WIDTH_WALK;
            }
        }
Esempio n. 9
0
        private void GetRetreatTarget()
        {
            state = EnemyRangedState.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);
        }
Esempio n. 10
0
        public override void Update(GameTime gT)
        {
            switch (state)
            {
                #region Retreat State
            case EnemyRangedState.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 += 2f;
                        if (Position.X > retreatTarget.X)     // Gone too far
                        {
                            Position.X = retreatTarget.X;
                        }
                    }
                    else     // Target to the LEFT
                    {
                        this.Position.X -= 2f;
                        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 += 1.5f;
                        if (Position.Y > retreatTarget.Y)     // Gone too far
                        {
                            Position.Y = retreatTarget.Y;
                        }
                    }
                    else     // Target is above us
                    {
                        this.Position.Y -= 1.5f;
                        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, 1);
                        this.SetOriginPosition("bottom");
                        AnimateWalking(gT);
                    }
                }
                break;

                #endregion

                #region MoveTo - move to the Player, for attacking
            case EnemyRangedState.MoveTo:
                // Are we lined up with player
                bool linedUpX = LinedUpXWithPlayerClose();
                bool linedUpY = LinedUpYWithPlayer();

                if (linedUpX && linedUpY)
                {
                    // Set Pre-Attack State
                    this.FrameX = 0;
                    this.FrameY = 0;
                    this.state  = EnemyRangedState.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 Move Away - MoveAway the Player, for

            case EnemyRangedState.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.state  = EnemyRangedState.ThrowStone;
                        this.Sprite = Texture_React;
                        this.InitSpriteFrames(DRAW_WIDTH_ROCKTHROW, DRAW_HEIGHT_TAKEHIT, 0, 7);
                        this.SetOriginPosition("bottom");
                        this.SetDrawArea();

                        SoundManager.PlaySound("ThrowPunch");
                        break;
                    }
                    else
                    {
                        GetRetreatTarget();
                    }
                }

                AnimateWalking(gT);
                break;

                #endregion

                #region ThrowKnife

            case EnemyRangedState.ThrowStone:
                AnimateThrowRock(gT);
                break;

                #endregion

                #region Pre Attack
            case EnemyRangedState.PreAttack:
                // Am I still lined up with the player
                if (LinedUpXWithPlayerClose() && 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;
                        }

                        // Its time to attack
                        this.Sprite = Texture_Attack;
                        this.InitSpriteFrames(D_WIDTH_COMBO1_ATTACK03, D_HEIGHT_COMBO1_ATTACK03, 0, 3);

                        if (FacingDir == DirectionTarget.Left)
                        {
                            this.SetOriginPosition("bottom", 18, 2);
                        }
                        else
                        {
                            this.SetOriginPosition("bottom", -18, 2);
                        }

                        this.SetDrawArea();
                        this.state = EnemyRangedState.Attack;

                        SoundManager.PlaySound("ThrowPunch");
                    }
                }
                else
                {
                    // Not lined up with the player
                    this.state = EnemyRangedState.MoveTo;
                    this.InitSpriteFrames(DRAW_WIDTH_WALK, this.DrawHeight, 0, this.FrameY);
                    this.SetOriginPosition("bottom");
                    return;
                }
                AnimateIdle(gT);
                break;
                #endregion

                #region Attacks

            case EnemyRangedState.Attack:

                AnimateKnockDownAttack(gT);
                break;

                #endregion

                #region Take Hit and Die Cycle
            case EnemyRangedState.TakeHit:
                this.SetOriginPosition("bottom", -5, this.DrawHeight);
                AnimateTakeHit(gT);
                break;

            case EnemyRangedState.TakeHitLowKick:
                this.SetOriginPosition("bottom", -5, this.DrawHeight);
                AnimateTakeHitKick(gT);
                break;

            case EnemyRangedState.KnockedDown:
                AnimateKnockDown(gT);
                break;

            case EnemyRangedState.Down:
                stateTime += (float)gT.ElapsedGameTime.TotalSeconds;
                if (stateTime >= Actor.DOWN_TIME)
                {
                    // Set up Gettign Up Animation
                    this.state            = EnemyRangedState.GettingUp;
                    this.CurrentFrameTime = 0f;
                    this.InitSpriteFrames(DRAW_WIDTH_GETTINGUP, DRAW_HEIGHT_TAKEHIT, 0, 5);
                    this.SetOriginPosition("bottom");
                    this.SetDrawArea();
                }
                break;

            case EnemyRangedState.GettingUp:
                AnimateGettingUp(gT);
                break;

            case EnemyRangedState.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.6f)     // 0.6 = 40% chance of dropping item
                        {
                            this.InLevel.GameItems.Add(
                                new PickUpStone(this.InLevel, this.Position));
                        }

                        // Actor is Dead
                        RemoveActorFromLevel();
                    }
                }
                break;
                #endregion
            }
        }