TreeScene: draw a triangle
This commit is contained in:
parent
987c86fae9
commit
df436f8c32
@ -64,11 +64,11 @@ namespace SemiColinGames {
|
||||
|
||||
private void LoadLevel() {
|
||||
world?.Dispose();
|
||||
world = new SneakWorld(GraphicsDevice, Content.LoadString("levels/demo.json"));
|
||||
// world = new TreeWorld();
|
||||
// world = new SneakWorld(GraphicsDevice, Content.LoadString("levels/demo.json"));
|
||||
world = new TreeWorld();
|
||||
scene?.Dispose();
|
||||
scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera);
|
||||
// scene = new TreeScene(GraphicsDevice);
|
||||
// scene = new SneakScene(GraphicsDevice, ((SneakWorld) world).Camera);
|
||||
scene = new TreeScene(GraphicsDevice);
|
||||
|
||||
GC.Collect();
|
||||
GC.WaitForPendingFinalizers();
|
||||
|
@ -6,12 +6,28 @@ using System;
|
||||
namespace SemiColinGames {
|
||||
public sealed class TreeScene : IScene {
|
||||
|
||||
readonly Color backgroundColor = Color.SkyBlue;
|
||||
const int MAX_LINE_VERTICES = 4;
|
||||
|
||||
readonly GraphicsDevice graphics;
|
||||
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() {
|
||||
@ -19,11 +35,24 @@ namespace SemiColinGames {
|
||||
}
|
||||
|
||||
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 */);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user