aboutsummaryrefslogtreecommitdiffstats
path: root/code/entity/Footprint.cs
blob: 8941e95adc71af581c6481f78cad2824f4a196d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 );
	}
}