aboutsummaryrefslogtreecommitdiffstats
path: root/code/pawn
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/pawn
parentca0d44610b6216f82fcf8f5830d445963654db64 (diff)
Add footprints
Diffstat (limited to 'code/pawn')
-rw-r--r--code/pawn/Player.Character.cs11
-rw-r--r--code/pawn/Player.cs2
-rw-r--r--code/pawn/component/FootprintTrackerComponent.cs51
3 files changed, 62 insertions, 2 deletions
diff --git a/code/pawn/Player.Character.cs b/code/pawn/Player.Character.cs
index a8fc19c..579107a 100644
--- a/code/pawn/Player.Character.cs
+++ b/code/pawn/Player.Character.cs
@@ -5,10 +5,17 @@ namespace MurderGame;
public partial class Player
{
[Net] public Team Team { get; set; }
-
+
[Net] public string CharacterName { get; set; }
- [Net] public string HexColor { get; set; }
+ [Net] public Color Color { get; set; } = Color.White;
+
+ public string HexColor {
+ get
+ {
+ return Color.Hex;
+ }
+ }
public string GetTeamName()
{
diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs
index 7073bb1..7254023 100644
--- a/code/pawn/Player.cs
+++ b/code/pawn/Player.cs
@@ -47,6 +47,7 @@ public partial class Player : AnimatedEntity
[BindComponent] public AnimatorComponent Animator { get; }
[BindComponent] public InventoryComponent Inventory { get; }
[BindComponent] public FallDamageComponent FallDamage { get; }
+ [BindComponent] public FootprintTrackerComponent FootprintTracker { get; }
[Net]
public Ragdoll PlayerRagdoll { get; set; }
@@ -179,6 +180,7 @@ public partial class Player : AnimatedEntity
Animator?.Simulate();
Inventory?.Simulate( cl );
FallDamage?.Simulate( cl );
+ FootprintTracker?.Simulate( cl );
if (Game.IsServer && Camera is not SpectatorCameraComponent && LifeState == LifeState.Dead && TimeSinceDeath > 3.5)
{
diff --git a/code/pawn/component/FootprintTrackerComponent.cs b/code/pawn/component/FootprintTrackerComponent.cs
new file mode 100644
index 0000000..7a396d1
--- /dev/null
+++ b/code/pawn/component/FootprintTrackerComponent.cs
@@ -0,0 +1,51 @@
+using System.Linq;
+using Sandbox;
+
+namespace MurderGame;
+
+public class FootprintTrackerComponent : EntityComponent<Player>, ISingletonComponent
+{
+ private TimeSince TimeSinceFootstep = 0;
+ private bool FootstepLeft = true;
+
+ public void Simulate( IClient cl )
+ {
+ if (!Game.IsClient || TimeSinceFootstep < 0.25) return;
+ TimeSinceFootstep = 0;
+ FootstepLeft = !FootstepLeft;
+
+ var bystanders = Game.Clients.Where(c => (c.Pawn as Player)?.Team is Team.Bystander or Team.Detective);
+
+ foreach (var bystander in bystanders)
+ {
+ if (bystander.Pawn is not Player player) continue;
+ if (player.Velocity.Length < 1) continue;
+ var start = player.Position + Vector3.Up;
+ var end = start + Vector3.Down * 20;
+
+ var tr = Trace.Ray( start, end )
+ .Size( 2)
+ .WithAnyTags( "solid" )
+ .Ignore( Entity )
+ .Run();
+
+ if ( !tr.Hit )
+ {
+ continue;
+ }
+
+ var material = FootstepLeft
+ ? "materials/left_shoe_footprint.vmat"
+ : "materials/right_shoe_footprint.vmat";
+ var _ = new Footprint
+ {
+ SpriteMaterial = Material.Load(material),
+ SpriteScale = 24f,
+ Position = player.Position + (Vector3.Up * 1f),
+ Rotation = Rotation.LookAt(player.Velocity, tr.Normal).RotateAroundAxis( tr.Normal, 270 ),
+ Color = player.Color
+ };
+ }
+ }
+
+}