using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; using System; namespace SemiColinGames { public sealed class TreeScene : IScene { const int MAX_LINE_VERTICES = 4; private readonly Color backgroundColor = Color.SkyBlue; private readonly GraphicsDevice graphics; private readonly BasicEffect basicEffect; private VertexPositionColor[] lineVertices; private VertexBuffer vertexBuffer; public TreeScene(GraphicsDevice graphics) { this.graphics = graphics; basicEffect = new BasicEffect(graphics) { World = Matrix.CreateTranslation(0, 0, 0), View = Matrix.CreateLookAt(Vector3.Backward, Vector3.Zero, Vector3.Up), VertexColorEnabled = true }; basicEffect.Projection = Matrix.CreateOrthographicOffCenter(0, 1920, 1080, 0, -1, 1); lineVertices = new VertexPositionColor[MAX_LINE_VERTICES]; vertexBuffer = new VertexBuffer( graphics, typeof(VertexPositionColor), MAX_LINE_VERTICES, BufferUsage.WriteOnly); } ~TreeScene() { Dispose(); } public void Dispose() { vertexBuffer.Dispose(); GC.SuppressFinalize(this); } public void Draw(bool isRunningSlowly, IWorld iworld, bool paused) { graphics.Clear(backgroundColor); lineVertices[0] = new VertexPositionColor(new Vector3(100, 100, 0), Color.Black); lineVertices[1] = new VertexPositionColor(new Vector3(300, 200, 0), Color.Black); lineVertices[2] = new VertexPositionColor(new Vector3(200, 200, 0), Color.Black); lineVertices[3] = new VertexPositionColor(new Vector3(100, 100, 0), Color.Black); graphics.SetVertexBuffer(vertexBuffer); vertexBuffer.SetData(lineVertices); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Apply(); graphics.DrawPrimitives(PrimitiveType.LineStrip, 0, 3 /* num lines */); } } } }