From dbf0218371ce006b674b0ede8e6a4d97932ff2c6 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Tue, 1 Aug 2023 01:31:25 +0100 Subject: Add footprints --- code/entity/Footprint.cs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 code/entity/Footprint.cs (limited to 'code/entity') diff --git a/code/entity/Footprint.cs b/code/entity/Footprint.cs new file mode 100644 index 0000000..8941e95 --- /dev/null +++ b/code/entity/Footprint.cs @@ -0,0 +1,55 @@ +using System; + +namespace MurderGame; + +using Sandbox; +// It's just a square with a material slapped onto it. +public class Footprint : RenderEntity +{ + public Material SpriteMaterial { get; set; } + + public float SpriteScale { get; set; } = 18f; + + public bool Enabled { get; set; } = true; + + public Color Color { get; set; } + + private TimeSince TimeSinceCreated = 0; + + [GameEvent.Tick.Client] + public void OnTick() + { + if ( !(TimeSinceCreated > Math.Clamp(MurderGame.MaxFootprintTime, 0, 30)) ) + { + return; + } + + Enabled = false; + Delete(); + } + + public override void DoRender(SceneObject obj) + { + if (!Enabled) return; + + // Allow lights to affect the sprite + Graphics.SetupLighting(obj); + // Create the vertex buffer for the sprite + var vb = new VertexBuffer(); + vb.Init(true); + + // Vertex buffers are in local space, so we need the camera position in local space too + var normal = new Vector3( 0, 0.01f, 100 ); + var w = normal.Cross(Vector3.Down).Normal; + var h = normal.Cross(w).Normal; + float halfSpriteSize = SpriteScale / 2; + + // Add a single quad to our vertex buffer + vb.AddQuad(new Ray(default, normal), halfSpriteSize*w, h*halfSpriteSize); + + Graphics.Attributes.Set( "color", Color); + + // Draw the sprite + vb.Draw( SpriteMaterial ); + } +} -- cgit v1.2.3-70-g09d2