Пример #1
0
        public void ScrollCamera(Viewport viewport, LevelPlayer player, TileEngine tileEngine)
        {
#if ZUNE
const float ViewMargin = 0.45f;
#else
            const float ViewMargin = 0.35f;
#endif

            // Calculate the edges of the screen.
            float marginHeight = viewport.Height + 20.0f;
            float marginWidth = viewport.Width * ViewMargin;
            float marginLeft = CameraPositionXAxis + marginWidth;
            float marginRight = CameraPositionXAxis + viewport.Width - marginWidth;

            // Calculate how far to scroll when the player is near the edges of the screen.
            float cameraMovement = 0.0f;
            if (player.Position.X < marginLeft)
                cameraMovement = player.Position.X - marginLeft;
            else if (player.Position.X > marginRight)
                cameraMovement = player.Position.X - marginRight;

            const float TopMargin = 0.3f;
            const float BottomMargin = 0.1f;
            float marginTop = cameraPositionYAxis + viewport.Height * TopMargin;
            float marginBottom = cameraPositionYAxis + viewport.Height - viewport.Height * BottomMargin;

            float cameraMovementY = 0.0f;
            if (player.Position.Y < marginTop) //above the top margin   
                cameraMovementY = player.Position.Y - marginTop;
            else if (player.Position.Y > marginBottom) //below the bottom margin   
                cameraMovementY = player.Position.Y - marginBottom;   




            // Update the camera position, but prevent scrolling off the ends of the level.
            float maxCameraPositionXOffset = LevelTile.Width * tileEngine.Width - viewport.Width;
            CameraPositionXAxis = MathHelper.Clamp(CameraPositionXAxis + cameraMovement, 0.0f, maxCameraPositionXOffset);

            float maxCameraPositionYOffset = LevelTile.Height * tileEngine.Height - viewport.Height;  
            cameraPositionYAxis = MathHelper.Clamp(cameraPositionYAxis + cameraMovementY, 0.0f, maxCameraPositionYOffset);  
        }
Пример #2
0
        /// <summary>
        /// Animates each enemy and allow them to kill the player.
        /// </summary>
        public void PlayerAndEnemy(LevelPlayer player, Character enemy, GameTime gameTime)
        {
            if (player.oneFrame.Intersects(enemy.BoundingRectangle))
            {
                //Enemy will stop walking, if their bounding box intersect with player and they are not doing some speical animation
                if (enemy.SpecialAnimationDone || enemy == Statics.Level.Boss)
                {
                    if (enemy.MoveState != Enums.MoveState.Fall && enemy.MoveState != Enums.MoveState.FireFall && enemy.MoveState != Enums.MoveState.FireReaction)
                        enemy.movement = 0;
                }

                // Resolve the collision along the X axis between player and enemy, player is not allow to go through the enemy.  
                Vector2 depth = RectangleExtensions.GetIntersectionDepth(player.BoundingRectangle, enemy.BoundingRectangle);
                player.Position = new Vector2(player.Position.X + depth.X, player.Position.Y);

                if (player.MoveState == Enums.MoveState.SpecialCombo)
                {
                        if (enemy == Statics.Level.Boss)
                            enemy.MoveState = Enums.MoveState.Fall;
                        else
                            enemy.MoveState = Enums.MoveState.FireFall;

                        enemy.SpecialAnimationDone = false;
                        if (!player.AttackOnce)
                        {
                             enemy.Health -= player.AttackStrength;
                             player.Health -= 3;
                             player.AttackOnce = true;
                        }
                        player.movement = 0;
                }

                if (PerPixel.Collision(player.oneFrame, player.ColorData, enemy.oneFrame, enemy.ColorData))
                {
                    //Placing this test outside of the Intersects test ensures the player will be capable of damage from every enemy punch
                    //This resolves the problem of only once damage per time the player entered the bounding Rectangle of the enemy.  

                    if (!player.AttackOnce && 
                        enemy.MoveState != Enums.MoveState.FinalCombo2 &&
                        (player.ComboCount > 0 ||
                         player.Health <= 0.2 * player.fullHealth))
                    {
                        switch (player.MoveState)
                        {
                            case Enums.MoveState.Punch:
                                enemy.MoveState = Enums.MoveState.Reaction;
                                enemy.Health -= player.AttackStrength;
                                enemy.hurtCount++;
                                player.CountActions += 6;
                                player.punchHurtCount++;
                                break;
                            case Enums.MoveState.PunchUp:
                                enemy.MoveState = Enums.MoveState.Fall;
                                enemy.Health -= player.AttackStrength;
                                enemy.hurtCount += 2;
                                player.CountActions += 6;
                                break;
                            case Enums.MoveState.Kick:
                                enemy.MoveState = Enums.MoveState.Reaction;
                                enemy.Health -= player.AttackStrength;
                                enemy.hurtCount ++;
                                player.kickHurtCount++;
                                player.CountActions += 10;
                                break;
                            case Enums.MoveState.ComboKick:
                                enemy.MoveState = Enums.MoveState.Fall;
                                enemy.Health -= 2 * player.AttackStrength;
                                enemy.hurtCount += 2;
                                player.CountActions += 20;
                                break;
                            case Enums.MoveState.FirePunch1:
                                enemy.MoveState = Enums.MoveState.FireReaction;
                                enemy.Health -= 2 * player.AttackStrength;
                                player.CountActions += 15;
                                break;
                            case Enums.MoveState.FirePunch2:
                                enemy.MoveState = Enums.MoveState.FireReaction;
                                enemy.Health -= 2 * player.AttackStrength;
                                player.CountActions += 15;
                                break;
                            case Enums.MoveState.FirePunch3:
                                enemy.MoveState = Enums.MoveState.FireFall;
                                enemy.Health -= 2 * player.AttackStrength;
                                player.CountActions += 15;
                                break;
                            case Enums.MoveState.FinalCombo2:
                                enemy.MoveState = Enums.MoveState.FireFall;
                                enemy.Health -= 4 * player.AttackStrength;
                                player.ComboCount--;
                                break;
                        }

                        enemy.hurtSound.Play();
                        player.AttackOnce = true;
                        enemy.SpecialAnimationDone = false;
                        HitTime = gameTime.TotalRealTime;
                    }

                    if (!enemy.AttackOnce && player.SpecialAnimationDone)
                    {
                        if (enemy == Statics.Level.Boss)
                        {
                            switch (enemy.MoveState)
                            {
                                case Enums.MoveState.Punch:
                                    player.MoveState = Enums.MoveState.Fall;
                                    player.Health -= enemy.AttackStrength;
                                    enemy.hitCount++;
                                    break;
                                case Enums.MoveState.FinalCombo2:
                                    player.MoveState = Enums.MoveState.Fall;
                                    player.Health -= 2 * enemy.AttackStrength;
                                    break;
                            }
                        }
                        else
                        {
                            switch (enemy.MoveState)
                            {
                                case Enums.MoveState.FinalCombo1:
                                    player.MoveState = Enums.MoveState.Reaction;
                                    player.Health -= enemy.AttackStrength;
                                    enemy.hitCount++;
                                    break;
                                case Enums.MoveState.FinalCombo2:
                                    player.MoveState = Enums.MoveState.Fall;
                                    player.Health -= 2 * enemy.AttackStrength;
                                    break;
                            }
                        }

                        player.SpecialAnimationDone = false;
                        enemy.hurtSound.Play();
                        enemy.AttackOnce = true;
                    }
                }
            }
            //If no intersection between player rectangle and enemy rectangle frame
            //Add enemy movement towards player here...
            else
            {
                if (enemy.SpecialAnimationDone)
                {
                    if(enemy == Statics.Level.Boss)
                        enemy.movement = 200;
                    else
                        enemy.movement = 65f;
                    enemy.MoveState = Enums.MoveState.Walk;
                }
            }
        }     
Пример #3
0
        /// <summary>
        /// Gets the latest input and uses it to update the input history buffer.
        /// </summary>
        public void UpdatePlayer(GameTime gameTime, LevelPlayer player)
        {
            // Get latest input state.
            GamePadState lastGamePadState = GamePadState;
            KeyboardState lastKeyboardState = KeyboardState;
            GamePadState = GamePad.GetState(PlayerIndex);
#if WINDOWS
            if (PlayerIndex == PlayerIndex.One)
            {
                KeyboardState = Keyboard.GetState(PlayerIndex);
            }
#endif

            if (player.SpecialAnimationDone)
            {
                // If any digital horizontal movement input is found, override the analog movement.
                if (GamePadState.IsButtonDown(Buttons.DPadLeft) || KeyboardState.IsKeyDown(Keys.A) || KeyboardState.IsKeyDown(Keys.Left))
                {
                    player.direction = Enums.FaceDirection.Left;
                    player.movement = 0.8f;
                }
                if (GamePadState.IsButtonDown(Buttons.DPadRight) || KeyboardState.IsKeyDown(Keys.D) || KeyboardState.IsKeyDown(Keys.Right))
                {
                    player.direction = Enums.FaceDirection.Right;
                    player.movement = 0.8f;
                }

                if (Math.Abs(player.movement) > 0)
                    player.MoveState = Enums.MoveState.Run;

                // Check if the player wants to jump.
                player.isJumping = GamePadState.IsButtonDown(Buttons.DPadUp) || KeyboardState.IsKeyDown(Keys.W) || KeyboardState.IsKeyDown(Keys.Space) || KeyboardState.IsKeyDown(Keys.Up);
            }

            // Expire old input.
            TimeSpan time = gameTime.TotalRealTime;
            TimeSpan timeSinceLast = time - LastInputTime;
            if (timeSinceLast > BufferTimeOut)
            {
                Buffer.Clear();
            }

            // Get all of the non-direction buttons pressed.
            Buttons buttons = 0;
            foreach (var buttonAndKey in NonDirectionButtons)
            {
                Buttons button = buttonAndKey.Key;
                Keys key = buttonAndKey.Value;

                // Check the game pad and keyboard for presses.
                if ((lastGamePadState.IsButtonUp(button) &&
                     GamePadState.IsButtonDown(button)) ||
                    (lastKeyboardState.IsKeyUp(key) &&
                     KeyboardState.IsKeyDown(key)))
                {
                    // Use a bitwise-or to accumulate button presses.
                    buttons |= button;
                }
            }

            // It is very hard to press two buttons on exactly the same frame.
            // If they are close enough, consider them pressed at the same time.
            bool mergeInput = (Buffer.Count > 0 && timeSinceLast < MergeInputTime);

            // If there is a new direction,
            var direction = Direction.FromInput(GamePadState, KeyboardState);
            if (Direction.FromInput(lastGamePadState, lastKeyboardState) != direction)
            {
                // combine the direction with the buttons.
                buttons |= direction;

                // Don't merge two different directions. This avoids having impossible
                // directions such as Left+Up+Right. This also has the side effect that
                // the direction needs to be pressed at the same time or slightly before
                // the buttons for merging to work.
                mergeInput = false;
            }

            // If there was any new input on this update, add it to the buffer.
            if (buttons != 0)
            {
                if (mergeInput)
                {
                    // Use a bitwise-or to merge with the previous input.
                    // LastInputTime isn't updated to prevent extending the merge window.
                    Buffer[Buffer.Count - 1] = Buffer[Buffer.Count - 1] | buttons;
                }
                else
                {
                    // Append this input to the buffer, expiring old input if necessary.
                    if (Buffer.Count == Buffer.Capacity)
                    {
                        Buffer.RemoveAt(0);
                    }
                    Buffer.Add(buttons);

                    // Record this the time of this input to begin the merge window.
                    LastInputTime = time;
                }
            }
        }
Пример #4
0
 public void OnCollected(LevelPlayer collectedBy)
 {
     collectedSound.Play();
 }
Пример #5
0
        /// <summary>
        /// Called when a HealthPotion is collected.
        /// </summary>
        /// <param name="healthPotion">The healthPotion that was collected.</param>
        /// <param name="collectedBy">The player who collected this healthPotion.</param>
        private void OnHealthPotionCollected(HealthPotion healthPotion, LevelPlayer collectedBy)
        {
            collectedBy.Health += (2 * collectedBy.fullHealth/ 3);
            if (collectedBy.Health >= collectedBy.fullHealth)
                collectedBy.Health = collectedBy.fullHealth;

            healthPotion.OnCollected(collectedBy);
        }
Пример #6
0
        /// <summary>
        /// Animates each HealthPotion and checks to allows the player to collect them.
        /// </summary>
        public void UpdateHealthPotions(GameTime gameTime, LevelPlayer player)
        {
            UpdateKnives(gameTime);
            for (int i = 0; i < healthPotions.Count; ++i)
            {
                HealthPotion healthPotion = healthPotions[i];

                healthPotion.Update(gameTime);

                if (healthPotion.BoundingCircle.Intersects(player.BoundingRectangle))
                {
                    healthPotions.RemoveAt(i--);
                    OnHealthPotionCollected(healthPotion, player);
                }
            }
        }