Example #1
0
        public void LoadContent()
        {
            position = new Vector3d(200, 200, 200);
            facing = 180;
            pitch = 0;

            camera = new RectangularPrismObject(new Vector3((float)position.X, (float)position.Y, (float)position.Z), new Vector3(10, 10, 10));
            body = new ControlledPhysicsEntity(new Vector3(25, 50, 25), new Vector3(2.5f, 50, 2.5f));
        }
        public virtual bool Intersects(RectangularPrismObject rectangle)
        {
            if (Left <= rectangle.Right &&
                Right >= rectangle.Left &&
                Top <= rectangle.Bottom &&
                Bottom >= rectangle.Top &&
                Front >= rectangle.Back &&
                Back <= rectangle.Front)
            {
                return true;
            }

            return false;
        }
        public void Update(double gameTime, RectangularPrismObject[] staticEnvironment, double rotationArgs)
        {
            rotation = rotationArgs;
            position.Y += velocityY;

            if (onGround)
            {
                jumped = false;
                velocityY = 0;
            }
            else
                velocityY -= (float)(9.8 * gameTime);

            onGround = false;

            foreach (RectangularPrismObject rectangleObject in staticEnvironment)
            {
                if (Intersects(rectangleObject))
                {
                    onGround = true;

                    if (jumped == false)
                    {
                        position = new Vector3d(position.X, rectangleObject.Bottom, position.Z);
                    }
                }
            }
        }
        public void CheckCollision(RectangularPrismObject[] rectangle)
        {
            bool x = false, y = false, z = false;

            for (int a = 0; a < rectangle.Length; a++)
            {
                if (Left <= rectangle[a].Right &&
                    Right >= rectangle[a].Left)
                    x = true;
                if (Top <= rectangle[a].Bottom &&
                    Bottom >= rectangle[a].Top)
                    y = true;
                if (Front >= rectangle[a].Back &&
                    Back <= rectangle[a].Front)
                    z = true;
            }

            Console.WriteLine(x + ":" + y + ":" + z);
            Console.WriteLine(Top + ":" + Bottom + ":" + rectangle[0].Top + ":" + rectangle[0].Bottom);
        }