Compare commits
3 Commits
fixed-came
...
bbf0a765d5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbf0a765d5 | ||
|
|
bce1f8e1f7 | ||
|
|
3e9d64cb00 |
@@ -6,7 +6,7 @@ namespace LuckerGame.Components.Lucker.Cameras;
|
||||
public abstract partial class AbstractCamera : EntityComponent<Entities.Lucker>, ISingletonComponent
|
||||
{
|
||||
public virtual bool ShouldShowCursor => false;
|
||||
protected Vector3 CameraPosition { get; set; }
|
||||
public Vector3 CameraPosition { get; set; }
|
||||
protected Rotation CameraRotation { get; set; }
|
||||
protected float FieldOfView { get; set; }
|
||||
protected IEntity FirstPersonViewer { get; set; }
|
||||
|
||||
@@ -15,13 +15,13 @@ public class RussianRouletteMinigame : Minigame
|
||||
{
|
||||
public override string Name => "Russian Roulette";
|
||||
private List<Lucker> Players { get; set; }
|
||||
private Pawn 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<Pawn> DeadVictims => Players
|
||||
.Select( player => player.Pawn as Pawn )
|
||||
private List<Entities.Pawn> 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<Lucker> players )
|
||||
{
|
||||
Players = players;
|
||||
Shooter = new Pawn();
|
||||
Shooter = new Entities.Pawn();
|
||||
var shooterInventory = Shooter.Components.Create<PawnInventory>();
|
||||
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.Pawn();
|
||||
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 );
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
64
code/Minigames/TerryRaces/Racer.cs
Normal file
64
code/Minigames/TerryRaces/Racer.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using LuckerGame.Entities;
|
||||
using LuckerGame.UI;
|
||||
using Sandbox;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
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()
|
||||
{
|
||||
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( double minSpeed, double maxSpeed )
|
||||
{
|
||||
Speed = (float)(RandomExtensions.NextDouble( Random, minSpeed, maxSpeed ));
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
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;
|
||||
@@ -14,39 +15,109 @@ namespace LuckerGame.Minigames.TerryRaces;
|
||||
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<Lucker> Players { get; set; }
|
||||
private FixedCamera camera;
|
||||
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 FinishLineY = -300f;
|
||||
private float StartingX = 90f;
|
||||
private float RacerXOffset = 60f;
|
||||
private float MinimumSpeed = .90f;
|
||||
private float MaximumSpeed = 1.1f;
|
||||
|
||||
public override void Initialize( List<Lucker> players )
|
||||
{
|
||||
Players = players;
|
||||
|
||||
// Setup cameras for players
|
||||
Players.ForEach( player =>
|
||||
{
|
||||
camera = player.Components.Create<FixedCamera>();
|
||||
camera.LookAt( new Vector3( -110f, 4f, 180f ), Rotation.FromPitch( 45 ) );
|
||||
camera.FieldOfViewValue = 120f;
|
||||
Camera = player.Components.Create<FixedCamera>();
|
||||
Camera.LookAt( new Vector3(0f, 0f, 400f), Rotation.FromPitch( -270 ) );
|
||||
Camera.FieldOfViewValue = 100f;
|
||||
} );
|
||||
|
||||
Players.Select( ( player, i ) => (Player: player, Index: i) ).ToList().ForEach( pair =>
|
||||
{
|
||||
var player = pair.Player;
|
||||
var index = pair.Index;
|
||||
var pawn = new Pawn();
|
||||
pawn.Name = player.Name;
|
||||
pawn.Tags.Add( "victim" );
|
||||
pawn.Health = 1;
|
||||
player.Pawn = pawn;
|
||||
pawn.DressFromClient( player.Client );
|
||||
|
||||
} );
|
||||
SpawnRacers();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
Racers.ForEach( racer =>
|
||||
{
|
||||
if (WinningRacer == null)
|
||||
{
|
||||
GetWinningRacer();
|
||||
racer.ContinueRacing();
|
||||
}
|
||||
else
|
||||
{
|
||||
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(random);
|
||||
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(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;
|
||||
}
|
||||
}
|
||||
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/>
|
||||
<VotingLobby/>
|
||||
<Scoreboard/>
|
||||
<CameraCursor/>
|
||||
</root>
|
||||
|
||||
@code
|
||||
|
||||
Reference in New Issue
Block a user