got racers animated and racing
This commit is contained in:
@@ -1,5 +0,0 @@
|
|||||||
public static class Constants
|
|
||||||
{
|
|
||||||
public readonly static Vector3
|
|
||||||
TOPDOWN_CAMERA_POSITION = new Vector3(0f, 0f, 280f);
|
|
||||||
}
|
|
||||||
@@ -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 Pawn : AnimatedEntity
|
public partial class Racer : 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 Pawn Pawn => Owner as Pawn;
|
public Racer Pawn => Owner as Racer;
|
||||||
|
|
||||||
/// <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="Pawn.SetActiveWeapon(Weapon)"/> is called for this weapon.
|
/// Called when <see cref="Racer.SetActiveWeapon(Weapon)"/> is called for this weapon.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="pawn"></param>
|
/// <param name="pawn"></param>
|
||||||
public void OnEquip( Pawn pawn )
|
public void OnEquip( Racer 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="Pawn.Simulate(IClient)"/>.
|
/// Called from <see cref="Racer.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.Pawn>, ISingletonComponent
|
public class PawnAnimator : EntityComponent<Entities.Racer>, 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.Pawn>
|
public partial class PawnInventory : EntityComponent<Entities.Racer>
|
||||||
{
|
{
|
||||||
[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.Pawn>
|
public class UserPawnController : EntityComponent<Entities.Racer>
|
||||||
{
|
{
|
||||||
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 Pawn Shooter { get; set; }
|
private Entities.Racer 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<Pawn> DeadVictims => Players
|
private List<Entities.Racer> DeadVictims => Players
|
||||||
.Select( player => player.Pawn as Pawn )
|
.Select( player => player.Pawn as Entities.Racer )
|
||||||
.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 Pawn();
|
Shooter = new Entities.Racer();
|
||||||
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 Pawn();
|
var pawn = new Entities.Racer();
|
||||||
pawn.Name = player.Name;
|
pawn.Name = player.Name;
|
||||||
pawn.Tags.Add( "victim" );
|
pawn.Tags.Add( "victim" );
|
||||||
pawn.Health = 1;
|
pawn.Health = 1;
|
||||||
@@ -83,7 +83,7 @@ public class RussianRouletteMinigame : Minigame
|
|||||||
}
|
}
|
||||||
else if ( TimeSinceShot > TimeBetweenShots * .8f && Taunted == 1)
|
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() )
|
.OrderBy( _ => Guid.NewGuid() )
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
Shooter.LookAt( victim.Position );
|
Shooter.LookAt( victim.Position );
|
||||||
|
|||||||
@@ -1,9 +1,27 @@
|
|||||||
using LuckerGame.Entities;
|
using LuckerGame.Entities;
|
||||||
using Sandbox;
|
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 : LuckerGame.Entities.Racer
|
||||||
|
|
||||||
public class Racer : Pawn
|
|
||||||
{
|
{
|
||||||
|
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 ));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,11 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
|
using System.Reflection.Metadata.Ecma335;
|
||||||
using LuckerGame.Components.Lucker.Cameras;
|
using LuckerGame.Components.Lucker.Cameras;
|
||||||
using LuckerGame.Components.Pawn;
|
using LuckerGame.Components.Pawn;
|
||||||
using LuckerGame.Entities;
|
using LuckerGame.Entities;
|
||||||
using Sandbox;
|
using Sandbox;
|
||||||
using Sandbox.Minigames.TerryRaces;
|
|
||||||
using Sandbox.UI;
|
using Sandbox.UI;
|
||||||
|
|
||||||
namespace LuckerGame.Minigames.TerryRaces;
|
namespace LuckerGame.Minigames.TerryRaces;
|
||||||
@@ -15,13 +15,24 @@ namespace LuckerGame.Minigames.TerryRaces;
|
|||||||
public class TerryRaces : Minigame
|
public class TerryRaces : Minigame
|
||||||
{
|
{
|
||||||
public override string Name => "Terry Races";
|
public override string Name => "Terry Races";
|
||||||
private List<Lucker> Players { get; set; }
|
private Random random = new Random();
|
||||||
|
private Racer WinningRacer = null;
|
||||||
private FixedCamera Camera;
|
private FixedCamera Camera;
|
||||||
private List<Racer> Racers { get; set; }
|
private List<Lucker> Players { get; set; }
|
||||||
|
private List<Racer> Racers { get; set; } = new List<Racer>();
|
||||||
|
private List<string> RacerNames = new List<string>
|
||||||
|
{
|
||||||
|
"Terrance",
|
||||||
|
"Terrie",
|
||||||
|
"TearBear",
|
||||||
|
"Theresa"
|
||||||
|
};
|
||||||
private float StartingY = 290f;
|
private float StartingY = 290f;
|
||||||
|
private float FinishLineY = -300f;
|
||||||
private float StartingX = 90f;
|
private float StartingX = 90f;
|
||||||
private float RacerXOffset = 60f;
|
private float RacerXOffset = 60f;
|
||||||
private int NumberOfRacers = 4;
|
private float MinimumSpeed = .90f;
|
||||||
|
private float MaximumSpeed = 1.1f;
|
||||||
|
|
||||||
public override void Initialize( List<Lucker> players )
|
public override void Initialize( List<Lucker> players )
|
||||||
{
|
{
|
||||||
@@ -31,30 +42,86 @@ public class TerryRaces : Minigame
|
|||||||
Players.ForEach( player =>
|
Players.ForEach( player =>
|
||||||
{
|
{
|
||||||
Camera = player.Components.Create<FixedCamera>();
|
Camera = player.Components.Create<FixedCamera>();
|
||||||
Camera.LookAt( Constants.TOPDOWN_CAMERA_POSITION, Rotation.FromPitch( -270 ) );
|
Camera.LookAt( new Vector3(0f, 0f, 400f), Rotation.FromPitch( -270 ) );
|
||||||
Camera.FieldOfViewValue = 100f;
|
Camera.FieldOfViewValue = 100f;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// SpawnRacers();
|
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 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick()
|
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()
|
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<Clothing>()
|
||||||
|
.Where( c => c.Category == Clothing.ClothingCategory.Bottoms )
|
||||||
|
.OrderBy( _ => Guid.NewGuid() )
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Clothing GetRandomHatClothing()
|
||||||
|
{
|
||||||
|
return ResourceLibrary
|
||||||
|
.GetAll<Clothing>()
|
||||||
|
.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}" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
code/RandomExtensions.cs
Normal file
11
code/RandomExtensions.cs
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user