aboutsummaryrefslogtreecommitdiffstats
path: root/code/entity/Footprint.cs
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.com>2023-08-01 01:31:25 +0100
committerLeonardo Bishop <me@leonardobishop.com>2023-08-01 01:31:25 +0100
commitdbf0218371ce006b674b0ede8e6a4d97932ff2c6 (patch)
treea865e7ff8e9f65579435b951a0c2ceffd8237c61 /code/entity/Footprint.cs
parentca0d44610b6216f82fcf8f5830d445963654db64 (diff)
Add footprints
Diffstat (limited to 'code/entity/Footprint.cs')
-rw-r--r--code/entity/Footprint.cs55
1 files changed, 55 insertions, 0 deletions
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 );
+ }
+}