Example #1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Handles ;
        // - collisions with platforms
        // - applying gravity to the player
        // - resetting the player position if needed.
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void UpdatePlayerGravityAndPlatforms(GameTime gameTime, LevelLibrary.LevelRenderer levelRenderer)
        {
            bool clashing;

            gravity.Apply(ref position, gameTime, isOnGround);

            // Update the level positions and enemies
            levelRenderer.Update(gameTime, ref position, this.Width, this.Height, this);

            // Check for clashes
            clashing = levelRenderer.HandleClash(ref position, Width, Height, ref isOnGround);

            // If we clash with the square below and we're falling STOP
            if (clashing)
            {
                if (gravity.direction == LevelLibrary.Directions.down)
                {
                    gravity.direction = LevelLibrary.Directions.none;
                }
                else if (gravity.direction == LevelLibrary.Directions.up)
                {
                    gravity.SetVelocity(1, LevelLibrary.Directions.down);
                }
            }

            // If we have landed back on earth, we can jump again.
            if (isOnGround || hoverAbility == true)
            {
                jumping = false;
            }
        }
Example #2
0
        private void ModeLeftRight(LevelLibrary.LevelRenderer levelRenderer)
        {
            //LevelLibrary.LevelRenderer.Sides clashingWith;
            bool clash = false;
            bool isOnGround = false;

            position += direction;

            clash = levelRenderer.HandleClash(ref position,
                                        enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround);

            // Clash on left ?
            // Clash on right ?
            if ((clash) || (position.X <= 0) || (position.X >= screenLimits.X))
            {
                //position = oldPosition;
                // Reverse the direction by multiplying by -1
                // e.g. 1 * -1 = -1
                // and -1 * -1 =  1
                // Nice huh?
                direction.X = direction.X * -1.0f;
                if (enemyAnimation.direction == Directions.right)
                {
                    enemyAnimation.direction = Directions.left;
                }
                else
                {
                    enemyAnimation.direction = Directions.right;
                }
            }
        }
Example #3
0
        private void ModeUpDown(LevelLibrary.LevelRenderer levelRenderer)
        {
            bool clash = false;
            bool isOnGround = false;

            position += direction;

            clash = levelRenderer.HandleClash(ref position,
                                        enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround);

            // Clash on left ?
            // Clash on right ?
            if ((clash) ||  (position.Y <= 0) || (position.Y >= screenLimits.Y))
            {
                //position = oldPosition;
                // Reverse the direction by multiplying by -1
                // e.g. 1 * -1 = -1
                // and -1 * -1 =  1
                // Nice huh?
                direction.Y = direction.Y * -1.0f;
                if (enemyAnimation.direction == Directions.up)
                {
                    enemyAnimation.direction = Directions.down;
                }
                else
                {
                    enemyAnimation.direction = Directions.up;
                }
            }
        }
Example #4
0
        private void ModeChase(LevelLibrary.LevelRenderer levelRenderer)
        {
            bool clash = false;
            bool isOnGround = false;

            if (playerPosition.X < position.X)
            {
                direction.X = -1f;
            }
            else
            {
                direction.X = 1f;
            }

            position += direction;

            clash = levelRenderer.HandleClash(ref position,
                                        enemyAnimation.FrameWidth, enemyAnimation.FrameHeight, ref isOnGround);

            // Clash on left ?
            // Clash on right ?
            if ((clash) || (position.X <= 0) || (position.X >= screenLimits.X))
            {
                direction.Y = 0f;
            }
        }