All pastes #776472 Raw Edit

Untitled

public text v1 · immutable
·published 2007-11-16 02:25 UTC
rendered paste body
float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
                
            int dispSizeOver2 = displaySize / 2;

            int startX = (int)PlayerLocation.X - dispSizeOver2;
            int startY = (int)PlayerLocation.Y - dispSizeOver2;
            int maxX = (int)PlayerLocation.X + dispSizeOver2;
            int maxY = (int)PlayerLocation.Y + dispSizeOver2;
            
            if (displaySize % 2 != 0)
            {
                maxX++;
                maxY++;
            }

            for (int x = startX; x < maxX; x++)
            {
                for (int y = startY; y < maxY; y++)
                {
                    Vector3 drawOffset = new Vector3();
                    Tile tile = tileMatrix.GetLandTile(x, y);

                    int xIndex = x - startX;
                    int yIndex = y - startY;

                    drawOffset.X = xIndex * 44;
                    drawOffset.Y = yIndex * 44;

                    int vertexIndex = (yIndex * 6) + ((xIndex * displaySize) * 6);
                    int textureIndex = (yIndex) + (xIndex * displaySize);

                    textureBuffer[textureIndex] = Artwork.GetTextmap(GraphicsDevice, tile.ID);

                    if (PlayerLocation.X == x && PlayerLocation.Y == y)
                    {
                        textureBuffer[textureIndex] = Artwork.GetTextmap(GraphicsDevice, 0);
                    }

                    vertices[vertexIndex].Position = drawOffset + new Vector3(0, 0, 0);
                    vertices[vertexIndex].TextureCoordinate = new Vector2(0, 0);
                    vertices[vertexIndex + 1].Position = drawOffset + new Vector3(44, 0, 0);
                    vertices[vertexIndex + 1].TextureCoordinate = new Vector2(1, 0);
                    vertices[vertexIndex + 2].Position = drawOffset + new Vector3(44, 44, 0);
                    vertices[vertexIndex + 2].TextureCoordinate = new Vector2(1, 1);
                    vertices[vertexIndex + 3].Position = drawOffset + new Vector3(0, 44, 0);
                    vertices[vertexIndex + 3].TextureCoordinate = new Vector2(0, 1);
                    vertices[vertexIndex + 4] = vertices[vertexIndex];
                    vertices[vertexIndex + 5] = vertices[vertexIndex + 2];

                }
            }

            vertexBuffer.SetData<VertexPositionTexture>(vertices);

------------------------------------------------------------------------------------------------


            Viewport viewport = GraphicsDevice.Viewport;

            int vertPos = 0;

            GraphicsDevice.VertexDeclaration = vertexDeclaration;
            GraphicsDevice.Vertices[0].SetSource(vertexBuffer, 0, VertexPositionTexture.SizeInBytes);
            GraphicsDevice.Viewport = Engine.GameViewport;
            GraphicsDevice.RenderState.DepthBufferEnable = false;

            BasicEffect.Projection =
                Matrix.CreateRotationZ(MathHelper.ToRadians(45)) *
                Matrix.CreateTranslation(new Vector3(512, 352 - ((displaySize / 2) * 62.25f), 0)) * 
                Matrix.CreateOrthographicOffCenter(0, Engine.Width, Engine.Height, 0, 0, 1);
           
            BasicEffect.TextureEnabled = true;

            BasicEffect.Begin();
            BasicEffect.CurrentTechnique.Passes[0].Begin();

            for (int i = 0; i < displaySize * displaySize; i++, vertPos += 6)
            {
                BasicEffect.Texture = textureBuffer[i];
                BasicEffect.CommitChanges();

                GraphicsDevice.DrawPrimitives(primitiveType, vertPos, 4);
            }

            BasicEffect.CurrentTechnique.Passes[0].End();
            BasicEffect.End();

            GraphicsDevice.RenderState.DepthBufferEnable = true;
            GraphicsDevice.Viewport = viewport;