added nametags
This commit is contained in:
@@ -7,7 +7,7 @@ namespace LuckerGame.Entities;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents an entity in the world. Could be controlled by a Lucker or a minigame
|
/// Represents an entity in the world. Could be controlled by a Lucker or a minigame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class Racer : AnimatedEntity
|
public partial class Pawn : AnimatedEntity
|
||||||
{
|
{
|
||||||
[ClientInput]
|
[ClientInput]
|
||||||
public Vector3 InputDirection { get; set; }
|
public Vector3 InputDirection { get; set; }
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public partial class Weapon : AnimatedEntity
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// An accessor to grab our Pawn.
|
/// An accessor to grab our Pawn.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Racer Pawn => Owner as Racer;
|
public Pawn Pawn => Owner as Pawn;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// This'll decide which entity to fire effects from. If we're in first person, the View Model, otherwise, this.
|
/// 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
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when <see cref="Racer.SetActiveWeapon(Weapon)"/> is called for this weapon.
|
/// Called when <see cref="Pawn.SetActiveWeapon(Weapon)"/> is called for this weapon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pawn"></param>
|
/// <param name="pawn"></param>
|
||||||
public void OnEquip( Racer pawn )
|
public void OnEquip( Pawn pawn )
|
||||||
{
|
{
|
||||||
Owner = pawn;
|
Owner = pawn;
|
||||||
SetParent( pawn, true );
|
SetParent( pawn, true );
|
||||||
@@ -86,7 +86,7 @@ public partial class Weapon : AnimatedEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called from <see cref="Racer.Simulate(IClient)"/>.
|
/// Called from <see cref="Pawn.Simulate(IClient)"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="player"></param>
|
/// <param name="player"></param>
|
||||||
public override void Simulate( IClient player )
|
public override void Simulate( IClient player )
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System;
|
|||||||
|
|
||||||
namespace LuckerGame.Components.Pawn;
|
namespace LuckerGame.Components.Pawn;
|
||||||
|
|
||||||
public class PawnAnimator : EntityComponent<Entities.Racer>, ISingletonComponent
|
public class PawnAnimator : EntityComponent<Entities.Pawn>, ISingletonComponent
|
||||||
{
|
{
|
||||||
public void Simulate()
|
public void Simulate()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ using Sandbox;
|
|||||||
|
|
||||||
namespace LuckerGame.Components.Pawn;
|
namespace LuckerGame.Components.Pawn;
|
||||||
|
|
||||||
public partial class PawnInventory : EntityComponent<Entities.Racer>
|
public partial class PawnInventory : EntityComponent<Entities.Pawn>
|
||||||
{
|
{
|
||||||
[Net] private List<Weapon> Weapons { get; set; } = new List<Weapon>();
|
[Net] private List<Weapon> Weapons { get; set; } = new List<Weapon>();
|
||||||
[Net, Predicted] public Weapon ActiveWeapon { get; private set; }
|
[Net, Predicted] public Weapon ActiveWeapon { get; private set; }
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace LuckerGame.Components.Pawn;
|
namespace LuckerGame.Components.Pawn;
|
||||||
|
|
||||||
public class UserPawnController : EntityComponent<Entities.Racer>
|
public class UserPawnController : EntityComponent<Entities.Pawn>
|
||||||
{
|
{
|
||||||
public int StepSize => 24;
|
public int StepSize => 24;
|
||||||
public int GroundAngle => 45;
|
public int GroundAngle => 45;
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ public class RussianRouletteMinigame : Minigame
|
|||||||
{
|
{
|
||||||
public override string Name => "Russian Roulette";
|
public override string Name => "Russian Roulette";
|
||||||
private List<Lucker> Players { get; set; }
|
private List<Lucker> Players { get; set; }
|
||||||
private Entities.Racer Shooter { get; set; }
|
private Entities.Pawn Shooter { get; set; }
|
||||||
private const float ShooterDistance = 80f;
|
private const float ShooterDistance = 80f;
|
||||||
private const float TimeBetweenShots = 7f;
|
private const float TimeBetweenShots = 7f;
|
||||||
private int Taunted = 0;
|
private int Taunted = 0;
|
||||||
|
|
||||||
private List<Entities.Racer> DeadVictims => Players
|
private List<Entities.Pawn> DeadVictims => Players
|
||||||
.Select( player => player.Pawn as Entities.Racer )
|
.Select( player => player.Pawn as Entities.Pawn )
|
||||||
.Where( pawn => !pawn.IsValid || pawn.LifeState != LifeState.Alive )
|
.Where( pawn => !pawn.IsValid || pawn.LifeState != LifeState.Alive )
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ public class RussianRouletteMinigame : Minigame
|
|||||||
public override void Initialize( List<Lucker> players )
|
public override void Initialize( List<Lucker> players )
|
||||||
{
|
{
|
||||||
Players = players;
|
Players = players;
|
||||||
Shooter = new Entities.Racer();
|
Shooter = new Entities.Pawn();
|
||||||
var shooterInventory = Shooter.Components.Create<PawnInventory>();
|
var shooterInventory = Shooter.Components.Create<PawnInventory>();
|
||||||
shooterInventory.AddWeapon( new RussianPistol() );
|
shooterInventory.AddWeapon( new RussianPistol() );
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class RussianRouletteMinigame : Minigame
|
|||||||
{
|
{
|
||||||
var player = pair.Player;
|
var player = pair.Player;
|
||||||
var index = pair.Index;
|
var index = pair.Index;
|
||||||
var pawn = new Entities.Racer();
|
var pawn = new Entities.Pawn();
|
||||||
pawn.Name = player.Name;
|
pawn.Name = player.Name;
|
||||||
pawn.Tags.Add( "victim" );
|
pawn.Tags.Add( "victim" );
|
||||||
pawn.Health = 1;
|
pawn.Health = 1;
|
||||||
|
|||||||
23
code/Minigames/TerryRaces/HoveringTextCreator.cs
Normal file
23
code/Minigames/TerryRaces/HoveringTextCreator.cs
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using LuckerGame.Entities;
|
using LuckerGame.Entities;
|
||||||
|
using LuckerGame.UI;
|
||||||
using Sandbox;
|
using Sandbox;
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -6,22 +7,58 @@ using System.Linq;
|
|||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Reflection.Metadata.Ecma335;
|
using System.Reflection.Metadata.Ecma335;
|
||||||
|
|
||||||
public class Racer : LuckerGame.Entities.Racer
|
public class Racer : Pawn
|
||||||
{
|
{
|
||||||
public float Speed;
|
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()
|
public void ContinueRacing()
|
||||||
{
|
{
|
||||||
Position = Position.WithY( Position.y - Speed );
|
SetAnimParameter( "move_x", Speed * 500f * SpeedModifier );
|
||||||
SetAnimParameter( "move_x", Speed*500f );
|
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()
|
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 ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public class TerryRaces : Minigame
|
|||||||
{
|
{
|
||||||
public override string Name => "Terry Races";
|
public override string Name => "Terry Races";
|
||||||
private Random random = new Random();
|
private Random random = new Random();
|
||||||
|
private HoveringTextCreator NameTag { get; set; }
|
||||||
private Racer WinningRacer = null;
|
private Racer WinningRacer = null;
|
||||||
private FixedCamera Camera;
|
private FixedCamera Camera;
|
||||||
private List<Lucker> Players { get; set; }
|
private List<Lucker> Players { get; set; }
|
||||||
@@ -50,25 +51,20 @@ public class TerryRaces : Minigame
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick()
|
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();
|
GetWinningRacer();
|
||||||
racer.ContinueRacing();
|
racer.ContinueRacing();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Log.Info( $"{racer.Name} is stopping." );
|
|
||||||
racer.StopRacing();
|
racer.StopRacing();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public override void Cleanup()
|
public override void Cleanup()
|
||||||
{
|
{
|
||||||
@@ -79,7 +75,7 @@ public class TerryRaces : Minigame
|
|||||||
for ( int i = 0; i < RacerNames.Count; i++ )
|
for ( int i = 0; i < RacerNames.Count; i++ )
|
||||||
{
|
{
|
||||||
var clothing = new ClothingContainer();
|
var clothing = new ClothingContainer();
|
||||||
var racer = new Racer();
|
var racer = new Racer(random);
|
||||||
var x = StartingX - RacerXOffset * i;
|
var x = StartingX - RacerXOffset * i;
|
||||||
|
|
||||||
clothing.Toggle( GetRandomBottomClothing() );
|
clothing.Toggle( GetRandomBottomClothing() );
|
||||||
@@ -89,7 +85,7 @@ public class TerryRaces : Minigame
|
|||||||
racer.Name = RacerNames[i];
|
racer.Name = RacerNames[i];
|
||||||
racer.Position = new Vector3( x, StartingY, 0 );
|
racer.Position = new Vector3( x, StartingY, 0 );
|
||||||
racer.Rotation = Rotation.FromYaw( -90 );
|
racer.Rotation = Rotation.FromYaw( -90 );
|
||||||
racer.GenerateSpeed( random, MinimumSpeed, MaximumSpeed );
|
racer.GenerateSpeed(MinimumSpeed, MaximumSpeed );
|
||||||
|
|
||||||
Racers.Add( racer );
|
Racers.Add( racer );
|
||||||
}
|
}
|
||||||
|
|||||||
30
code/UI/HoveringText.razor
Normal file
30
code/UI/HoveringText.razor
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
@using Sandbox;
|
||||||
|
@using Sandbox.UI;
|
||||||
|
|
||||||
|
@namespace LuckerGame.UI
|
||||||
|
@attribute [StyleSheet]
|
||||||
|
@inherits WorldPanel
|
||||||
|
|
||||||
|
<root class="card">
|
||||||
|
<label class="text">@Text</label>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
@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)));
|
||||||
|
}
|
||||||
|
}
|
||||||
7
code/UI/HoveringText.razor.scss
Normal file
7
code/UI/HoveringText.razor.scss
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
hoveringtext {
|
||||||
|
white-space: nowrap;
|
||||||
|
.text {
|
||||||
|
font-size: 150px;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,6 @@
|
|||||||
<VoiceList/>
|
<VoiceList/>
|
||||||
<VotingLobby/>
|
<VotingLobby/>
|
||||||
<Scoreboard/>
|
<Scoreboard/>
|
||||||
<CameraCursor/>
|
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
@code
|
@code
|
||||||
|
|||||||
Reference in New Issue
Block a user