got racers animated and racing
This commit is contained in:
@@ -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.Racer 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.Racer> 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<Lucker> players )
|
||||
{
|
||||
Players = players;
|
||||
Shooter = new Pawn();
|
||||
Shooter = new Entities.Racer();
|
||||
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.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 );
|
||||
|
||||
@@ -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 ));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Lucker> Players { get; set; }
|
||||
private Random random = new Random();
|
||||
private Racer WinningRacer = null;
|
||||
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 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<Lucker> players )
|
||||
{
|
||||
Players = players;
|
||||
|
||||
|
||||
// Setup cameras for players
|
||||
Players.ForEach( player =>
|
||||
{
|
||||
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;
|
||||
} );
|
||||
|
||||
// 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<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}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user