コード例 #1
0
        public override void GetKnockedDown(DirectionTarget cameFrom, int damage)
        {
            // Set state and texture
            IsAttackable     = false;
            this.IsAttacking = false;
            state            = EnemyCloseState.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;
        }
コード例 #2
0
 private void AnimateKnockDown(GameTime gT)
 {
     currentFrameTime += (float)gT.ElapsedGameTime.TotalSeconds;
     if (currentFrameTime >= Actor.FrameRate * 1.2f)
     {
         currentFrameTime = 0f;
         frameX++;
         if (frameX == 1 && CheckForDeath())
         {
             SoundManager.PlaySound("GetHit-Died");
         }
         if (frameX > 7)
         {
             if (CheckForDeath())
             {
                 //SoundManager.PlaySound("GetHit-Died");
                 state     = EnemyCloseState.Dying;
                 stateTime = 1f;
                 frameX    = 6;
                 return;
             }
             // Set state and texture
             state     = EnemyCloseState.Down;
             frameX    = 6;
             stateTime = 0f;
             return;
         }
         SetDrawArea();
     }
 }
コード例 #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  = EnemyCloseState.KnockedDown;
            this.Sprite = Texture_React;
            this.InitSpriteFrames(DRAW_WIDTH_KNOCKDOWN, DRAW_HEIGHT_TAKEHIT, 0, 1);
            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");
        }
コード例 #4
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      = EnemyCloseState.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;
            }
        }
コード例 #5
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
            {
                // ATTACK
                if (NoOtherEnemiesAttacking())
                {
                    this.IsAttacking = true;
                    this.state       = EnemyCloseState.MoveTo;
                    frameX           = 0;
                    drawWidth        = DRAW_WIDTH_WALK;
                }
                //else // ???????????????????????? - They wont wait until other enemy is done fighting with player
                //{
                //   GetRetreatTarget();
                //}
            }
        }
コード例 #6
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  = EnemyCloseState.TakeHitLowKick;
            this.Sprite = Texture_React;
            this.InitSpriteFrames(DRAW_WIDTH_TAKEHIT, DRAW_HEIGHT_TAKEHIT, 3, 6);
            this.SetDrawArea();

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

            SoundManager.PlaySound("GetHit02");
            SoundManager.PlaySound("GetHit-Shit");
        }
コード例 #7
0
 public void SetToWait(DirectionTarget facingDir)
 {
     this.state  = EnemyCloseState.Wait;
     this.Sprite = Texture_Walk_Idle;
     this.InitSpriteFrames(DRAW_WIDTH_WAIT, DRAW_HEIGHT_WAIT, 0, 3);
     this.SetDrawArea();
     this.SetOriginPosition("bottom");
     this.FacingDir = facingDir;
 }
コード例 #8
0
 public void SetToWait(DirectionTarget facingDir)
 {
     texture    = Game1.SprCharacterWalkIdle;
     drawWidth  = DRAW_WIDTH_WAIT;
     drawHeight = DRAW_HEIGHT_WAIT;
     frameX     = 0;
     frameY     = 3;
     SetDrawArea();
     state = EnemyCloseState.Wait;
     this.originCharacters = new Vector2((drawWidth / 2), drawHeight);
     this.FacingDir        = facingDir;
 }
コード例 #9
0
        private void GetRetreatTarget()
        {
            state = EnemyCloseState.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);
        }
コード例 #10
0
        public override void Update(GameTime gT)
        {
            switch (state)
            {
                #region Retreat State
            case EnemyCloseState.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
                        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 EnemyCloseState.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            = EnemyCloseState.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 EnemyCloseState.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.SprCharacterAttacks;
                        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) + 18, drawHeight + 2);
                        }
                        else     // Right
                        {
                            originCharacters = new Vector2((drawWidth / 2) - 18, drawHeight + 2);
                        }

                        SetDrawArea();
                        state = EnemyCloseState.Attack;
                        SoundManager.PlaySound("ThrowPunch");

                        attackNumber = 1;
                        //this.IsAttacking = true;
                        //}
                    }
                }
                else
                {
                    // Not lined up with the player
                    state            = EnemyCloseState.MoveTo;
                    frameX           = 0;
                    drawWidth        = DRAW_WIDTH_WALK;
                    originCharacters = new Vector2(drawWidth / 2, drawHeight);
                    return;
                }
                AnimateIdle(gT);
                break;
                #endregion

                #region Attacks

            case EnemyCloseState.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 EnemyCloseState.TakeHit:
                originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight);
                AnimateTakeHit(gT);
                break;

            case EnemyCloseState.TakeHitLowKick:
                originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight);
                AnimateTakeHitKick(gT);
                break;

            case EnemyCloseState.KnockedDown:
                //drawWidth = DRAW_WIDTH_KNOCKDOWN;
                //originCharacters = new Vector2((drawWidth / 2) - 5, drawHeight);
                AnimateKnockDown(gT);
                break;

            case EnemyCloseState.Down:
                stateTime += (float)gT.ElapsedGameTime.TotalSeconds;
                if (stateTime >= Actor.DOWN_TIME)
                {
                    // Set up Gettign Up Animation
                    state            = EnemyCloseState.GettingUp;
                    currentFrameTime = 0f;
                    frameX           = 0;
                    frameY           = 5;
                    drawWidth        = DRAW_WIDTH_GETTINGUP;
                    drawHeight       = DRAW_HEIGHT_TAKEHIT;
                    originCharacters = new Vector2(drawWidth / 2, drawHeight);
                    SetDrawArea();
                }
                break;

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

            case EnemyCloseState.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.9f)     // 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 EnemyCloseState.Wait:

                AnimateWaiting(gT);

                break;

                #endregion
            }
        }
コード例 #11
0
        public override void Update(GameTime gT)
        {
            switch (state)
            {
                #region Retreat State
            case EnemyCloseState.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, this.DrawHeight, this.FrameX, this.FrameY);
                        this.SetOriginPosition("bottom");
                        AnimateWalking(gT);
                    }
                }
                break;

                #endregion

                #region Pre Attack
            case EnemyCloseState.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
                        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", 18, 2);
                        }
                        else
                        {
                            this.SetOriginPosition("bottom", -18, 2);
                        }
                        this.SetDrawArea();
                        this.state        = EnemyCloseState.Attack;
                        this.attackNumber = 1;

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

                #region Attacks

            case EnemyCloseState.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 EnemyCloseState.TakeHit:
                this.SetOriginPosition("bottom", -5, this.DrawHeight);
                AnimateTakeHit(gT);
                break;

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

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

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

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

            case EnemyCloseState.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.9f)     // 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 EnemyCloseState.Wait:

                AnimateWaiting(gT);

                break;

                #endregion
            }
        }