diff --git a/code/Constants.cs b/code/Constants.cs deleted file mode 100644 index d382e59..0000000 --- a/code/Constants.cs +++ /dev/null @@ -1,5 +0,0 @@ -public static class Constants -{ - public readonly static Vector3 - TOPDOWN_CAMERA_POSITION = new Vector3(0f, 0f, 280f); -} diff --git a/code/Entities/Pawn.cs b/code/Entities/Pawn.cs index b96efd7..162982d 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 Pawn : AnimatedEntity +public partial class Racer : AnimatedEntity { [ClientInput] public Vector3 InputDirection { get; set; } diff --git a/code/Entities/Weapons/Weapon.cs b/code/Entities/Weapons/Weapon.cs index 95ec514..35606a1 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 Pawn Pawn => Owner as Pawn; + public Racer Pawn => Owner as Racer; /// /// 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( Pawn pawn ) + public void OnEquip( Racer 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 84d91fe..becefd0 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 f37e224..5556c81 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 cd84a52..1d8022e 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 55ab89f..47d55c3 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 Pawn Shooter { get; set; } + private Entities.Racer 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 Pawn ) + private List DeadVictims => Players + .Select( player => player.Pawn as Entities.Racer ) .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 Pawn(); + Shooter = new Entities.Racer(); 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 Pawn(); + var pawn = new Entities.Racer(); pawn.Name = player.Name; pawn.Tags.Add( "victim" ); pawn.Health = 1; @@ -83,7 +83,7 @@ public class RussianRouletteMinigame : Minigame } else if ( TimeSinceShot > TimeBetweenShots * .8f && Taunted == 1) { - var victim = Players.Select( player => player.Pawn as Pawn ) + var victim = Players.Select( player => player.Pawn as Racer ) .OrderBy( _ => Guid.NewGuid() ) .FirstOrDefault(); Shooter.LookAt( victim.Position ); diff --git a/code/Minigames/TerryRaces/Racer.cs b/code/Minigames/TerryRaces/Racer.cs index faef72f..5d8542d 100644 --- a/code/Minigames/TerryRaces/Racer.cs +++ b/code/Minigames/TerryRaces/Racer.cs @@ -1,9 +1,27 @@ using LuckerGame.Entities; using Sandbox; +using System; +using System.IO; +using System.Linq; +using System.Numerics; +using System.Reflection.Metadata.Ecma335; -namespace Sandbox.Minigames.TerryRaces; - -public class Racer : Pawn +public class Racer : LuckerGame.Entities.Racer { + public float Speed; + public void ContinueRacing() + { + Position = Position.WithY( Position.y - Speed ); + SetAnimParameter( "move_x", Speed*500f ); + } + public void StopRacing() + { + + } + + public void GenerateSpeed(Random random, double minSpeed, double maxSpeed) + { + Speed = (float)(RandomExtensions.NextDouble( random, minSpeed, maxSpeed )); + } } diff --git a/code/Minigames/TerryRaces/TerryRacesMinigame.cs b/code/Minigames/TerryRaces/TerryRacesMinigame.cs index 81e4c2d..4840602 100644 --- a/code/Minigames/TerryRaces/TerryRacesMinigame.cs +++ b/code/Minigames/TerryRaces/TerryRacesMinigame.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Numerics; +using System.Reflection.Metadata.Ecma335; using LuckerGame.Components.Lucker.Cameras; using LuckerGame.Components.Pawn; using LuckerGame.Entities; using Sandbox; -using Sandbox.Minigames.TerryRaces; using Sandbox.UI; namespace LuckerGame.Minigames.TerryRaces; @@ -15,46 +15,113 @@ namespace LuckerGame.Minigames.TerryRaces; public class TerryRaces : Minigame { public override string Name => "Terry Races"; - private List Players { get; set; } + private Random random = new Random(); + private Racer WinningRacer = null; private FixedCamera Camera; - private List Racers { get; set; } + private List Players { get; set; } + private List Racers { get; set; } = new List(); + private List RacerNames = new List + { + "Terrance", + "Terrie", + "TearBear", + "Theresa" + }; private float StartingY = 290f; + private float FinishLineY = -300f; private float StartingX = 90f; private float RacerXOffset = 60f; - private int NumberOfRacers = 4; + private float MinimumSpeed = .90f; + private float MaximumSpeed = 1.1f; public override void Initialize( List players ) { Players = players; - + // Setup cameras for players Players.ForEach( player => { Camera = player.Components.Create(); - Camera.LookAt( Constants.TOPDOWN_CAMERA_POSITION, Rotation.FromPitch( -270 ) ); + Camera.LookAt( new Vector3(0f, 0f, 400f), Rotation.FromPitch( -270 ) ); Camera.FieldOfViewValue = 100f; } ); - // SpawnRacers(); - } - - private void SpawnRacers() - { - for ( int i = 0; i < NumberOfRacers; i++ ) - { - var racer = new Racer(); - var x = StartingX - RacerXOffset * i; - racer.Position = new Vector3( x, StartingY, 0 ); - racer.Rotation = Rotation.FromPitch( -90 ); - Racers.Add( racer ); - } + SpawnRacers(); } public override void Tick() { + if ( Racers != null ) + { + Racers.ForEach( racer => + { + if ( WinningRacer == null ) + { + // Log.Info( $"{racer.Name} is racing" ); + GetWinningRacer(); + racer.ContinueRacing(); + } + else + { + // Log.Info( $"{racer.Name} is stopping." ); + racer.StopRacing(); + } + } ); + } } public override void Cleanup() { } + + private void SpawnRacers() + { + for ( int i = 0; i < RacerNames.Count; i++ ) + { + var clothing = new ClothingContainer(); + var racer = new Racer(); + var x = StartingX - RacerXOffset * i; + + clothing.Toggle( GetRandomBottomClothing() ); + clothing.Toggle( GetRandomHatClothing() ); + clothing.DressEntity( racer ); + + racer.Name = RacerNames[i]; + racer.Position = new Vector3( x, StartingY, 0 ); + racer.Rotation = Rotation.FromYaw( -90 ); + racer.GenerateSpeed( random, MinimumSpeed, MaximumSpeed ); + + Racers.Add( racer ); + } + } + + private Clothing GetRandomBottomClothing() + { + return ResourceLibrary + .GetAll() + .Where( c => c.Category == Clothing.ClothingCategory.Bottoms ) + .OrderBy( _ => Guid.NewGuid() ) + .FirstOrDefault(); + } + + private Clothing GetRandomHatClothing() + { + return ResourceLibrary + .GetAll() + .Where( c => c.Category == Clothing.ClothingCategory.Hat ) + .OrderBy( _ => Guid.NewGuid() ) + .FirstOrDefault(); + } + + private void GetWinningRacer() + { + foreach ( Racer racer in Racers ) + { + if ( racer.Position.y <= FinishLineY ) + { + WinningRacer = racer; + Log.Info( $"Winning racer: {racer.Name}" ); + } + } + } } diff --git a/code/RandomExtensions.cs b/code/RandomExtensions.cs new file mode 100644 index 0000000..0bfe3e1 --- /dev/null +++ b/code/RandomExtensions.cs @@ -0,0 +1,11 @@ +using System; +public static class RandomExtensions +{ + public static double NextDouble( + this Random random, + double minValue, + double maxValue ) + { + return random.NextDouble() * (maxValue - minValue) + minValue; + } +}