Exemple #1
0
        protected void BoundPosition()
        {
            Vector2 result = new Vector2(Position.X, Position.Y);

            float rightEdge = Position.X + PlayerChar.Width;

            // Check horizontal Scene.Bound
            if (rightEdge > Scene.Bound.Width)
            {
                result.X -= rightEdge - Scene.Bound.Width;
                Velocity  = new Vector2(0f, Velocity.Y);
            }
            else if (Position.X < 0)
            {
                result.X += 0 - Position.X;
                Velocity  = new Vector2(0f, Velocity.Y);
            }

            float topEdge = Position.Y - PlayerChar.Height;

            // Check vertical Scene.Bound
            if (Position.Y > Scene.Bound.Height)
            {
                PlayerChar.DeathPowerTransition();
            }
            else if (topEdge < 0)
            {
                result.Y += 0 - topEdge;
                Velocity  = new Vector2(Velocity.X, 0f);
            }

            Position = result;
        }