Ejemplo n.º 1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);



            //GraphicsDevice.BlendState = BlendState.Opaque;

            //DepthStencilState d = new DepthStencilState();
            //d.DepthBufferEnable = true;
            //GraphicsDevice.DepthStencilState = d;

            Matrix worldMatrix = Matrix.Identity;

            effect.World      = worldMatrix;
            effect.View       = camera.viewMatrix;
            effect.Projection = camera.projectionMatrix;

            //effect.EnableDefaultLighting();
            effect.LightingEnabled = true;
            effect.EmissiveColor   = new Vector3(0.25f, 0.25f, 0.25f);
            effect.SpecularColor   = new Vector3(0.25f, 0.25f, 0.25f);
            effect.SpecularPower   = 0.1f;

            effect.AmbientLightColor               = new Vector3(0.25f, 0.25f, 0.25f);
            effect.DirectionalLight0.Enabled       = true;
            effect.DirectionalLight0.Direction     = new Vector3(1, -1, -1);
            effect.DirectionalLight0.DiffuseColor  = new Vector3(0.75f, 0.75f, 0.75f);
            effect.DirectionalLight0.SpecularColor = new Vector3(0.1f, 0.1f, 0.1f);

            effect.World          = Matrix.Identity;
            effect.TextureEnabled = true;



            RasterizerState state = new RasterizerState();

            state.CullMode                 = CullMode.CullCounterClockwiseFace;
            state.MultiSampleAntiAlias     = true;
            state.DepthBias                = 0.01f;
            GraphicsDevice.RasterizerState = state;



            //Skybox
            effect.LightingEnabled = false;
            effect.Texture         = ContentDing.skyTexture1;
            int skyboxSize = 1000000;
            CubeModelInvertedForSkybox skybox = new CubeModelInvertedForSkybox(this, skyboxSize, skyboxSize, skyboxSize, TexturePosInfoGenerator.FullImage);
            Matrix skyboxMatrix = Matrix.CreateTranslation(camera.cameraPosition) * Matrix.CreateTranslation(new Vector3(-skyboxSize / 2, -skyboxSize / 2, -skyboxSize / 2));

            skybox.Draw(skyboxMatrix, effect);


            //effect.Texture = ContentDing.wallTexture;


            //SamplerState newSamplerState = new SamplerState()
            //{
            //    AddressU = TextureAddressMode.Wrap,
            //    AddressV = TextureAddressMode.Wrap,
            //    Filter = TextureFilter.Point
            //};
            //GraphicsDevice.SamplerStates[0] = newSamplerState;

            //foreach (WallModel wallModel in wallModels)
            //{
            //    GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            //    wallModel.Draw(Matrix.Identity, effect);
            //}


            effect.LightingEnabled = false;

            //Ground
            int    mazeScale          = 10;
            Matrix scaleMatrix        = Matrix.CreateScale(mazeScale);
            Matrix growingScaleMatrix = scaleMatrix * Matrix.CreateScale(1, (float)Math.Max(Math.Min(numbertje / 1.0f, 1), 0), 1);

            effect.World = scaleMatrix;

            //effect.Texture = ContentDing.grasTexture;

            SamplerState newSamplerState2 = new SamplerState()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                Filter   = TextureFilter.Point
            };

            GraphicsDevice.SamplerStates[0] = newSamplerState2;



            //int curmazeheight = 100;

            //WallModel wallmodel = new WallModel(this, curmazeheight * 10, curmazeheight * 10, TexturePosInfoGenerator.FullImageWithSize(15), Matrix.Identity);
            //wallmodel.Draw(Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateTranslation(0, 0, curmazeheight * 10), effect);

            effect.Texture = ContentDing.win98FloorTexture;



            CubeModel ground = new CubeModel(this, curMazeWidth - 2, 0.1f, curMazeHeight - 2, TexturePosInfoGenerator.FullImage, 2f / 3f);

            ground.Draw(Matrix.CreateTranslation(0, -0.1f, 0) * scaleMatrix, effect);


            if (drawRoof)
            {
                effect.Texture = ContentDing.win98RoofTexture;

                CubeModel roof = new CubeModel(this, curMazeWidth - 2, 0.1f, curMazeHeight - 2, TexturePosInfoGenerator.FullImage, 2f / 3f);
                roof.Draw(Matrix.CreateTranslation(0, 4f / 3f, 0) * scaleMatrix, effect);
            }

            effect.LightingEnabled = lighting;

            //Start
            effect.Texture = ContentDing.startTexture;
            CubeModel start = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);

            start.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * growingScaleMatrix, effect);


            //Finish
            effect.Texture = ContentDing.endTexture;
            CubeModel finish = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);

            finish.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(curMazeWidth - 4, 0, curMazeHeight - 4) * growingScaleMatrix, effect);


            //Me
            if (!followCamera)
            {
                var vvv = GetPosAtThisNumer(numbertje);

                var vvvv2 = new Vector3(vvv.X * 10f, 0, vvv.Y * 10f);

                //var translationmatrix = Matrix.CreateTranslation(vvvv2);

                //effect.Texture = ContentDing.redTexture;
                //targetCamera.Draw(translationmatrix, effect);


                var pospos     = GetPosAtThisNumer(numbertje - (1f / (float)speedFactor));
                var posposnext = GetPosAtThisNumer(Math.Max(numbertje + (1f / (float)speedFactor), 1.1f));

                var newRot = (float)Math.Atan2(posposnext.Y - pospos.Y, posposnext.X - pospos.X) * -1f + (MathHelper.Pi / 2.0f);


                Matrix totMatrix = MatrixExtensions.CreateRotationY(new Vector3(4, 0, 2), newRot);
                totMatrix *= Matrix.CreateTranslation(-4, 12, -2); //Put him in the middle of a tile
                totMatrix *= Matrix.CreateScale(1f / 3f);
                totMatrix *= Matrix.CreateTranslation(vvvv2);


                var posposHeadTurn     = GetPosAtThisNumer(numbertje);
                var posposnextHeadTurn = GetPosAtThisNumer(Math.Max(numbertje + (2f / (float)speedFactor), 1.1f));
                var newHeadTurn        = (float)Math.Atan2(posposnextHeadTurn.Y - posposHeadTurn.Y, posposnextHeadTurn.X - posposHeadTurn.X) * -1f + (MathHelper.Pi / 2.0f);


                effect.Texture = ContentDing.minecraftTexture;


                playerModel.Draw(totMatrix, effect, numbertje / 2.0f * speedFactor, newHeadTurn - newRot);
            }


            //Maze
            effect.World = growingScaleMatrix;

            if (vertexBuffer != null && indexBuffer != null)
            {
                GraphicsDevice.Indices = indexBuffer;
                GraphicsDevice.SetVertexBuffer(vertexBuffer);

                effect.Texture = ContentDing.win98WallTexture;

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3);
                }
            }

            effect.World = scaleMatrix * Matrix.CreateTranslation(0, 0.5f, 0); //Put it slightly above ground level

            //Path
            if (drawPath && vertexBufferPath != null && vertexBufferPath != null)
            {
                GraphicsDevice.Indices = indexBufferPath;
                GraphicsDevice.SetVertexBuffer(vertexBufferPath);

                effect.Texture = ContentDing.win98LegoTexture;

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBufferPath.VertexCount, 0, indexBufferPath.IndexCount / 3);
                }
            }



            //Draw line of sight
            if (chaseCameraShowDebugBlocks && curChaseCameraPoint != null)
            {
                effect.Texture = ContentDing.redTexture;
                CubeModel possibleCubeje = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
                possibleCubeje.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(curChaseCameraPoint.CameraPoint.X - 1, 0, curChaseCameraPoint.CameraPoint.Y - 1) * growingScaleMatrix, effect);

                if (curChaseCameraPoint.LosPoints != null)
                {
                    foreach (var losPoint in curChaseCameraPoint.LosPoints)
                    {
                        effect.Texture = ContentDing.startTexture;
                        CubeModel losPointCube = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
                        losPointCube.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(losPoint.X - 1, 0, losPoint.Y - 1) * growingScaleMatrix, effect);
                    }
                }
            }

            //var possible = determiner.GetAdjacentPoints(GetPosAtThisNumerMazePoint(numbertje));

            //foreach (var poss in possible)
            //{
            //    effect.Texture = ContentDing.startTexture;
            //    CubeModel possibleCubeje = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
            //    possibleCubeje.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(poss.X - 1, 0, poss.Y - 1) * growingScaleMatrix, effect);
            //}

            //foreach (var pathnode in currentPath)
            //{
            //    effect.Texture = ContentDing.redTexture;
            //    CubeModel possibleCubeje = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
            //    possibleCubeje.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(pathnode.X - 1, 0, pathnode.Y - 1) * growingScaleMatrix, effect);

            //}



            //CubeModel redCube = new CubeModel(this, 5, 5, 5, TexturePosInfoGenerator.FullImage);
            //effect.Texture = textureRed;

            //foreach (var node in currentPath)
            //{
            //    Matrix m = Matrix.CreateTranslation(2.5f + 10f * node.X, 2.5f, 2.5f + 10f * node.Y);
            //    redCube.Draw(m, effect);
            //}


            spriteBatch.Begin();

            String stringToDraw = "Size: " + curMazeWidth + ", Walls: " + wallsCount + ", Path length: " + pathCount + ", Speed: " + speedFactor + ", Current: " + (int)Math.Max((numbertje - 1f) * speedFactor, 0) + ", Algorithm: " + lastAlgorithm;

            var meassured = ContentDing.spriteFont.MeasureString(stringToDraw);

            spriteBatch.Draw(ContentDing.semiTransparantTexture, new Rectangle(5, 5, (int)meassured.X + 10, (int)meassured.Y + 10), Color.White);
            spriteBatch.DrawString(ContentDing.spriteFont, stringToDraw, new Vector2(10, 10), Color.White);

            spriteBatch.End();


            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            base.Draw(gameTime);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            //GraphicsDevice.BlendState = BlendState.Opaque;

            //DepthStencilState d = new DepthStencilState();
            //d.DepthBufferEnable = true;
            //GraphicsDevice.DepthStencilState = d;

            Matrix worldMatrix = Matrix.Identity;
            effect.World = worldMatrix;
            effect.View = camera.viewMatrix;
            effect.Projection = camera.projectionMatrix;

            //effect.EnableDefaultLighting();
            effect.LightingEnabled = true;
            effect.EmissiveColor = new Vector3(0.25f, 0.25f, 0.25f);
            effect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f);
            effect.SpecularPower = 0.1f;

            effect.AmbientLightColor = new Vector3(0.25f, 0.25f, 0.25f);
            effect.DirectionalLight0.Enabled = true;
            effect.DirectionalLight0.Direction = new Vector3(1, -1, -1);
            effect.DirectionalLight0.DiffuseColor = new Vector3(0.75f, 0.75f, 0.75f);
            effect.DirectionalLight0.SpecularColor = new Vector3(0.1f, 0.1f, 0.1f);

            effect.World = Matrix.Identity;
            effect.TextureEnabled = true;

            RasterizerState state = new RasterizerState();
            state.CullMode = CullMode.CullCounterClockwiseFace;
            state.MultiSampleAntiAlias = true;
            state.DepthBias = 0.01f;
            GraphicsDevice.RasterizerState = state;

            //Skybox
            effect.LightingEnabled = false;
            effect.Texture = ContentDing.skyTexture1;
            int skyboxSize = 1000000;
            CubeModelInvertedForSkybox skybox = new CubeModelInvertedForSkybox(this, skyboxSize, skyboxSize, skyboxSize, TexturePosInfoGenerator.FullImage);
            Matrix skyboxMatrix = Matrix.CreateTranslation(camera.cameraPosition) * Matrix.CreateTranslation(new Vector3(-skyboxSize / 2, -skyboxSize / 2, -skyboxSize / 2));
            skybox.Draw(skyboxMatrix, effect);

            //effect.Texture = ContentDing.wallTexture;

            //SamplerState newSamplerState = new SamplerState()
            //{
            //    AddressU = TextureAddressMode.Wrap,
            //    AddressV = TextureAddressMode.Wrap,
            //    Filter = TextureFilter.Point
            //};
            //GraphicsDevice.SamplerStates[0] = newSamplerState;

            //foreach (WallModel wallModel in wallModels)
            //{
            //    GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            //    wallModel.Draw(Matrix.Identity, effect);
            //}

            effect.LightingEnabled = false;

            //Ground
            int mazeScale = 10;
            Matrix scaleMatrix = Matrix.CreateScale(mazeScale);
            Matrix growingScaleMatrix = scaleMatrix * Matrix.CreateScale(1, (float)Math.Max(Math.Min(numbertje / 1.0f, 1), 0), 1);

            effect.World = scaleMatrix;

            //effect.Texture = ContentDing.grasTexture;

            SamplerState newSamplerState2 = new SamplerState()
            {
                AddressU = TextureAddressMode.Wrap,
                AddressV = TextureAddressMode.Wrap,
                Filter = TextureFilter.Point
            };
            GraphicsDevice.SamplerStates[0] = newSamplerState2;

            //int curmazeheight = 100;

            //WallModel wallmodel = new WallModel(this, curmazeheight * 10, curmazeheight * 10, TexturePosInfoGenerator.FullImageWithSize(15), Matrix.Identity);
            //wallmodel.Draw(Matrix.CreateRotationX(-MathHelper.PiOver2) * Matrix.CreateTranslation(0, 0, curmazeheight * 10), effect);

            effect.Texture = ContentDing.win98FloorTexture;

            effect.LightingEnabled = false;

            CubeModel ground = new CubeModel(this, curMazeWidth - 2, 0.1f, curMazeHeight - 2, TexturePosInfoGenerator.FullImage, 2f / 3f);
            ground.Draw(Matrix.CreateTranslation(0, -0.1f, 0) * scaleMatrix, effect);

            if (drawRoof)
            {
                effect.Texture = ContentDing.win98RoofTexture;

                CubeModel roof = new CubeModel(this, curMazeWidth - 2, 0.1f, curMazeHeight - 2, TexturePosInfoGenerator.FullImage, 2f / 3f);
                roof.Draw(Matrix.CreateTranslation(0, 4f / 3f, 0) * scaleMatrix, effect);
            }

            effect.LightingEnabled = lighting;

            //Start
            effect.Texture = ContentDing.startTexture;
            CubeModel start = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
            start.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * growingScaleMatrix, effect);

            //Finish
            effect.Texture = ContentDing.endTexture;
            CubeModel finish = new CubeModel(this, 0.75f, 0.75f, 0.75f, TexturePosInfoGenerator.FullImage, 0.75f);
            finish.Draw(Matrix.CreateTranslation(0.625f, 0.375f, 0.625f) * Matrix.CreateTranslation(curMazeWidth - 4, 0, curMazeHeight - 4) * growingScaleMatrix, effect);

            //Me
            if (freeMove)
            {
                effect.Texture = ContentDing.redTexture;
                var vvv = GetPosAtThisNumer(numbertje);
                var vvvv2 = new Vector3(vvv.X * 10f - 2.5f, 5f, vvv.Y * 10f - 2.5f);
                CubeModel targetCamera = new CubeModel(this, 5f, 5f, 5f, TexturePosInfoGenerator.FullImage, 0.75f);
                targetCamera.Draw(Matrix.CreateTranslation(vvvv2), effect);
            }

            //Maze
            effect.World = growingScaleMatrix;

            if (vertexBuffer != null && indexBuffer != null)
            {
                GraphicsDevice.Indices = indexBuffer;
                GraphicsDevice.SetVertexBuffer(vertexBuffer);

                effect.Texture = ContentDing.win98WallTexture;

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBuffer.VertexCount, 0, indexBuffer.IndexCount / 3);
                }

            }

            effect.World = growingScaleMatrix * Matrix.CreateTranslation(0, 0.1f, 0);

            //Path
            if (vertexBufferPath != null && vertexBufferPath != null)
            {
                GraphicsDevice.Indices = indexBufferPath;
                GraphicsDevice.SetVertexBuffer(vertexBufferPath);

                effect.Texture = ContentDing.win98LegoTexture;

                foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexBufferPath.VertexCount, 0, indexBufferPath.IndexCount / 3);
                }

            }

            //CubeModel redCube = new CubeModel(this, 5, 5, 5, TexturePosInfoGenerator.FullImage);
            //effect.Texture = textureRed;

            //foreach (var node in currentPath)
            //{
            //    Matrix m = Matrix.CreateTranslation(2.5f + 10f * node.X, 2.5f, 2.5f + 10f * node.Y);
            //    redCube.Draw(m, effect);
            //}

            //spriteBatch.Begin();

            //String stringToDraw = "Size: " + curMazeWidth + ", Walls: " + wallsCount + ", Path length: " + pathCount + ", Speed: " + speedFactor + ", Current: " + (int)Math.Max((numbertje - 1f) * speedFactor, 0);

            //var meassured = ContentDing.spriteFont.MeasureString(stringToDraw);

            //spriteBatch.Draw(ContentDing.semiTransparantTexture, new Rectangle(5, 5, (int)meassured.X + 10, (int)meassured.Y + 10), Color.White);
            //spriteBatch.DrawString(ContentDing.spriteFont, stringToDraw, new Vector2(10, 10), Color.White);

            //spriteBatch.End();

            //GraphicsDevice.BlendState = BlendState.Opaque;
            //GraphicsDevice.DepthStencilState = DepthStencilState.Default;

            base.Draw(gameTime);
        }