From bbf0a765d51f0238ddeb8372705464654e236939 Mon Sep 17 00:00:00 2001 From: mccarreon Date: Wed, 9 Aug 2023 17:50:57 -0700 Subject: [PATCH] added nametags --- code/Entities/Pawn.cs | 2 +- code/Entities/Weapons/Weapon.cs | 8 +-- code/EntityComponents/Pawn/PawnAnimator.cs | 2 +- code/EntityComponents/Pawn/PawnInventory.cs | 2 +- .../Pawn/UserPawnController.cs | 2 +- .../RussianRouletteMinigame.cs | 10 ++-- .../TerryRaces/HoveringTextCreator.cs | 23 +++++++++ code/Minigames/TerryRaces/Racer.cs | 49 ++++++++++++++++--- .../TerryRaces/TerryRacesMinigame.cs | 30 +++++------- code/UI/HoveringText.razor | 30 ++++++++++++ code/UI/HoveringText.razor.scss | 7 +++ code/UI/Hud.razor | 1 - 12 files changed, 129 insertions(+), 37 deletions(-) create mode 100644 code/Minigames/TerryRaces/HoveringTextCreator.cs create mode 100644 code/UI/HoveringText.razor create mode 100644 code/UI/HoveringText.razor.scss diff --git a/code/Entities/Pawn.cs b/code/Entities/Pawn.cs index 162982d..b96efd7 100644 --- a/code/Entities/Pawn.cs +++ b/code/Entities/Pawn.cs @@ -7,7 +7,7 @@ namespace LuckerGame.Entities; /// /// Represents an entity in the world. Could be controlled by a Lucker or a minigame /// -public partial class Racer : AnimatedEntity +public partial class Pawn : AnimatedEntity { [ClientInput] public Vector3 InputDirection { get; set; } diff --git a/code/Entities/Weapons/Weapon.cs b/code/Entities/Weapons/Weapon.cs index 35606a1..95ec514 100644 --- a/code/Entities/Weapons/Weapon.cs +++ b/code/Entities/Weapons/Weapon.cs @@ -14,7 +14,7 @@ public partial class Weapon : AnimatedEntity /// /// An accessor to grab our Pawn. /// - public Racer Pawn => Owner as Racer; + public Pawn Pawn => Owner as Pawn; /// /// This'll decide which entity to fire effects from. If we're in first person, the View Model, otherwise, this. @@ -63,10 +63,10 @@ public partial class Weapon : AnimatedEntity } /// - /// Called when is called for this weapon. + /// Called when is called for this weapon. /// /// - public void OnEquip( Racer pawn ) + public void OnEquip( Pawn pawn ) { Owner = pawn; SetParent( pawn, true ); @@ -86,7 +86,7 @@ public partial class Weapon : AnimatedEntity } /// - /// Called from . + /// Called from . /// /// public override void Simulate( IClient player ) diff --git a/code/EntityComponents/Pawn/PawnAnimator.cs b/code/EntityComponents/Pawn/PawnAnimator.cs index becefd0..84d91fe 100644 --- a/code/EntityComponents/Pawn/PawnAnimator.cs +++ b/code/EntityComponents/Pawn/PawnAnimator.cs @@ -3,7 +3,7 @@ using System; namespace LuckerGame.Components.Pawn; -public class PawnAnimator : EntityComponent, ISingletonComponent +public class PawnAnimator : EntityComponent, ISingletonComponent { public void Simulate() { diff --git a/code/EntityComponents/Pawn/PawnInventory.cs b/code/EntityComponents/Pawn/PawnInventory.cs index 5556c81..f37e224 100644 --- a/code/EntityComponents/Pawn/PawnInventory.cs +++ b/code/EntityComponents/Pawn/PawnInventory.cs @@ -5,7 +5,7 @@ using Sandbox; namespace LuckerGame.Components.Pawn; -public partial class PawnInventory : EntityComponent +public partial class PawnInventory : EntityComponent { [Net] private List Weapons { get; set; } = new List(); [Net, Predicted] public Weapon ActiveWeapon { get; private set; } diff --git a/code/EntityComponents/Pawn/UserPawnController.cs b/code/EntityComponents/Pawn/UserPawnController.cs index 1d8022e..cd84a52 100644 --- a/code/EntityComponents/Pawn/UserPawnController.cs +++ b/code/EntityComponents/Pawn/UserPawnController.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; namespace LuckerGame.Components.Pawn; -public class UserPawnController : EntityComponent +public class UserPawnController : EntityComponent { public int StepSize => 24; public int GroundAngle => 45; diff --git a/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs b/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs index 47d55c3..1c728a6 100644 --- a/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs +++ b/code/Minigames/RussianRoulette/RussianRouletteMinigame.cs @@ -15,13 +15,13 @@ public class RussianRouletteMinigame : Minigame { public override string Name => "Russian Roulette"; private List Players { get; set; } - private Entities.Racer Shooter { get; set; } + private Entities.Pawn Shooter { get; set; } private const float ShooterDistance = 80f; private const float TimeBetweenShots = 7f; private int Taunted = 0; - private List DeadVictims => Players - .Select( player => player.Pawn as Entities.Racer ) + private List DeadVictims => Players + .Select( player => player.Pawn as Entities.Pawn ) .Where( pawn => !pawn.IsValid || pawn.LifeState != LifeState.Alive ) .ToList(); @@ -30,7 +30,7 @@ public class RussianRouletteMinigame : Minigame public override void Initialize( List players ) { Players = players; - Shooter = new Entities.Racer(); + Shooter = new Entities.Pawn(); var shooterInventory = Shooter.Components.Create(); shooterInventory.AddWeapon( new RussianPistol() ); @@ -45,7 +45,7 @@ public class RussianRouletteMinigame : Minigame { var player = pair.Player; var index = pair.Index; - var pawn = new Entities.Racer(); + var pawn = new Entities.Pawn(); pawn.Name = player.Name; pawn.Tags.Add( "victim" ); pawn.Health = 1; diff --git a/code/Minigames/TerryRaces/HoveringTextCreator.cs b/code/Minigames/TerryRaces/HoveringTextCreator.cs new file mode 100644 index 0000000..953c530 --- /dev/null +++ b/code/Minigames/TerryRaces/HoveringTextCreator.cs @@ -0,0 +1,23 @@ +using LuckerGame.UI; +using Sandbox; + +public class HoveringTextCreator : Entity +{ + private string Text { get; set; } + private Entity TargetEntity { get; set; } + + public HoveringTextCreator() + { + + } + public HoveringTextCreator(string text, Entity targetEntity) + { + Text = text; + TargetEntity = targetEntity; + } + public override void ClientSpawn() + { + base.ClientSpawn(); + var hoveringText = new HoveringText(Text, TargetEntity); + } +} diff --git a/code/Minigames/TerryRaces/Racer.cs b/code/Minigames/TerryRaces/Racer.cs index 5d8542d..6f71184 100644 --- a/code/Minigames/TerryRaces/Racer.cs +++ b/code/Minigames/TerryRaces/Racer.cs @@ -1,4 +1,5 @@ using LuckerGame.Entities; +using LuckerGame.UI; using Sandbox; using System; using System.IO; @@ -6,22 +7,58 @@ using System.Linq; using System.Numerics; using System.Reflection.Metadata.Ecma335; -public class Racer : LuckerGame.Entities.Racer +public class Racer : Pawn { public float Speed; + private float SpeedModifier = 1f; + private Random Random { get; set; } + private HoveringText NameTag { get; set; } + + public Racer() + { + + } + + public Racer( Random random ) + { + Random = random; + } + + public override void ClientSpawn() + { + base.ClientSpawn(); + NameTag = new( Name, this ); + } + public void ContinueRacing() { - Position = Position.WithY( Position.y - Speed ); - SetAnimParameter( "move_x", Speed*500f ); + SetAnimParameter( "move_x", Speed * 500f * SpeedModifier ); + ModifySpeed(); + Position = Position.WithY( Position.y - (Speed * SpeedModifier) ); + + } + + private void ModifySpeed() + { + var roll = Random.NextDouble(); + switch ( roll ) + { + case >= .90 and < .95: + SpeedModifier = 2f; + break; + case >= .95: + SpeedModifier = 0.5f; + break; + } } public void StopRacing() { - + SetAnimParameter( "move_x", 0 ); } - public void GenerateSpeed(Random random, double minSpeed, double maxSpeed) + public void GenerateSpeed( double minSpeed, double maxSpeed ) { - Speed = (float)(RandomExtensions.NextDouble( random, minSpeed, maxSpeed )); + Speed = (float)(RandomExtensions.NextDouble( Random, minSpeed, maxSpeed )); } } diff --git a/code/Minigames/TerryRaces/TerryRacesMinigame.cs b/code/Minigames/TerryRaces/TerryRacesMinigame.cs index 4840602..5530704 100644 --- a/code/Minigames/TerryRaces/TerryRacesMinigame.cs +++ b/code/Minigames/TerryRaces/TerryRacesMinigame.cs @@ -16,6 +16,7 @@ public class TerryRaces : Minigame { public override string Name => "Terry Races"; private Random random = new Random(); + private HoveringTextCreator NameTag { get; set; } private Racer WinningRacer = null; private FixedCamera Camera; private List Players { get; set; } @@ -51,23 +52,18 @@ public class TerryRaces : Minigame public override void Tick() { - if ( Racers != null ) + Racers.ForEach( racer => { - Racers.ForEach( racer => + if (WinningRacer == null) { - if ( WinningRacer == null ) - { - // Log.Info( $"{racer.Name} is racing" ); - GetWinningRacer(); - racer.ContinueRacing(); - } - else - { - // Log.Info( $"{racer.Name} is stopping." ); - racer.StopRacing(); - } - } ); - } + GetWinningRacer(); + racer.ContinueRacing(); + } + else + { + racer.StopRacing(); + } + } ); } public override void Cleanup() @@ -79,7 +75,7 @@ public class TerryRaces : Minigame for ( int i = 0; i < RacerNames.Count; i++ ) { var clothing = new ClothingContainer(); - var racer = new Racer(); + var racer = new Racer(random); var x = StartingX - RacerXOffset * i; clothing.Toggle( GetRandomBottomClothing() ); @@ -89,7 +85,7 @@ public class TerryRaces : Minigame racer.Name = RacerNames[i]; racer.Position = new Vector3( x, StartingY, 0 ); racer.Rotation = Rotation.FromYaw( -90 ); - racer.GenerateSpeed( random, MinimumSpeed, MaximumSpeed ); + racer.GenerateSpeed(MinimumSpeed, MaximumSpeed ); Racers.Add( racer ); } diff --git a/code/UI/HoveringText.razor b/code/UI/HoveringText.razor new file mode 100644 index 0000000..1f48e49 --- /dev/null +++ b/code/UI/HoveringText.razor @@ -0,0 +1,30 @@ +@using Sandbox; +@using Sandbox.UI; + +@namespace LuckerGame.UI +@attribute [StyleSheet] +@inherits WorldPanel + + + + + +@code { + private Entity TargetEntity; + private string Text; + + public HoveringText(string text, Entity targetEntity) + { + Text = text; + TargetEntity = targetEntity; + } + + [GameEvent.Client.Frame] + private void OnFrame() + { + if (!TargetEntity.IsValid()) return; + Log.Info($"{Text} to {TargetEntity.Position}"); + Position = TargetEntity.Position + Vector3.Up * 65f; + Rotation = Rotation.LookAt(-Screen.GetDirection(new Vector2(Screen.Width * 0.5f, Screen.Height * 0.5f))); + } +} \ No newline at end of file diff --git a/code/UI/HoveringText.razor.scss b/code/UI/HoveringText.razor.scss new file mode 100644 index 0000000..11f34ec --- /dev/null +++ b/code/UI/HoveringText.razor.scss @@ -0,0 +1,7 @@ +hoveringtext { + white-space: nowrap; + .text { + font-size: 150px; + color: white; + } +} \ No newline at end of file diff --git a/code/UI/Hud.razor b/code/UI/Hud.razor index deb2cb5..91f613d 100644 --- a/code/UI/Hud.razor +++ b/code/UI/Hud.razor @@ -12,7 +12,6 @@ - @code