Skip to content

Commit

Permalink
Get platformer playable
Browse files Browse the repository at this point in the history
  • Loading branch information
cr4yz committed Dec 8, 2022
1 parent ff4e373 commit 2ff3d45
Show file tree
Hide file tree
Showing 43 changed files with 273 additions and 282 deletions.
10 changes: 5 additions & 5 deletions code/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace Platformer;

public partial class Platformer : Sandbox.Game
public partial class Platformer : GameManager
{

public new static Platformer Current;
Expand Down Expand Up @@ -48,7 +48,7 @@ public Platformer()
/// </summary>
public override void OnVoicePlayed( Client cl )
{
VoiceChatList.Current?.OnVoicePlayed( cl.PlayerId, cl.VoiceLevel );
VoiceChatList.Current?.OnVoicePlayed( cl.SteamId, cl.VoiceLevel );
}

[Event.Entity.PostSpawn]
Expand Down Expand Up @@ -88,7 +88,7 @@ public override void ClientDisconnect( Client client, NetworkDisconnectionReason
{
base.ClientDisconnect( client, reason );

PlatformerChatBox.AddInformation( To.Everyone, $"{client.Name} has left the game", client.PlayerId );
PlatformerChatBox.AddInformation( To.Everyone, $"{client.Name} has left the game", client.SteamId );
}

public override void OnKilled( Client client, Entity pawn )
Expand All @@ -98,7 +98,7 @@ public override void OnKilled( Client client, Entity pawn )
var msg = Rand.FromList( killMessages );


PlatformerChatBox.AddChatEntry( To.Everyone, client.Name, msg, client.PlayerId, null, false );
PlatformerChatBox.AddChatEntry( To.Everyone, client.Name, msg, client.SteamId, null, false );
}

private List<string> killMessages = new()
Expand Down Expand Up @@ -153,7 +153,7 @@ public static async void SubmitScore( string bucket, Client client, int score )

var leaderboard = await Leaderboard.FindOrCreate( bucket, false );

return await leaderboard.Value.GetScore( client.PlayerId );
return await leaderboard.Value.GetScore( client.SteamId );

}
}
36 changes: 3 additions & 33 deletions code/Gamemodes/BaseGamemode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,11 @@ public virtual void DoClientJoined( Client cl )
{
var tx = randomSpawnPoint.Transform;
tx.Position = tx.Position + Vector3.Up * 50.0f; // raise it up
cl.Pawn.Transform = tx;
cl.Pawn.Position = tx.Position;
cl.Pawn.Rotation = tx.Rotation;
}

PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.PlayerId, null, false );
PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.SteamId, null, false );
}

public virtual PlatformerPawn CreatePlayerInstance( Client cl ) => new PlatformerPawn( cl );
Expand All @@ -119,37 +120,6 @@ public virtual void DoPlayerKilled( PlatformerPawn player ) { }
protected virtual bool CanBreakState() => false;
protected virtual void OnGameLive() { }

[Event.Frame]
protected virtual void DoPostProcess()
{
var postProcess = Map.Camera.FindOrCreateHook<Sandbox.Effects.ScreenEffects>();
//Crashing Game
//postProcess.Sharpen.Enabled = false;

//postProcess.FilmGrain.Enabled = false;
//postProcess.FilmGrain.Intensity = 0.2f;
//postProcess.FilmGrain.Response = 1;

//postProcess.Vignette.Enabled = true;
//postProcess.Vignette.Intensity = 1.0f;
//postProcess.Vignette.Roundness = 1.5f;
//postProcess.Vignette.Smoothness = 0.5f;
//postProcess.Vignette.Color = Color.Black;

//postProcess.Saturate.Enabled = true;
//postProcess.Saturate.Amount = 1;

//postProcess.Blur.Enabled = false;

//if ( GameState == GameStates.Warmup )
//{
// postProcess.FilmGrain.Intensity = 0.4f;
// postProcess.FilmGrain.Response = 0.5f;

// postProcess.Saturate.Amount = 0.5f;
//}
}

protected virtual void FreshStart()
{
foreach ( var cl in Client.All )
Expand Down
8 changes: 5 additions & 3 deletions code/Gamemodes/BrawlPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public override void Simulate( Client cl )
{
base.Simulate( cl );

Animator.SetAnimParameter( "holdtype", 5 );
Animator.SetAnimParameter( "aim_body_weight", 1.0f );
// ANIMATOR:
//Animator.SetAnimParameter( "holdtype", 5 );
//Animator.SetAnimParameter( "aim_body_weight", 1.0f );

if ( Health > 0 && Input.Pressed( InputButton.PrimaryAttack ) )
{
Expand All @@ -37,7 +38,8 @@ private void TryPunch()
if ( TimeSincePunch < .5f ) return;

TimeSincePunch = 0f;
Animator.SetAnimParameter( "b_attack", true );
// ANIMATOR:
//Animator.SetAnimParameter( "b_attack", true );

if ( !IsServer ) return;

Expand Down
4 changes: 2 additions & 2 deletions code/Gamemodes/CompetitivePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public override void Simulate( Client cl )
KeysPlayerHas.Clear();
NumberLife = 3;
NumberOfKeys = 0;
Game.Current.DoPlayerSuicide( cl );
TakeDamage( new() { Damage = 9999 } );
}
else
{
Game.Current.DoPlayerSuicide( cl );
TakeDamage( new() { Damage = 9999 } );
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions code/Gamemodes/Coop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public override void DoPlayerKilled( PlatformerPawn player )

var deathpawn = new PlatformerDeadPawn( player.Client );
player.Client.Pawn = deathpawn;
player.Client.Pawn.Transform = player.Transform;
player.Client.Pawn.Position = player.Transform.Position;
player.Client.Pawn.Rotation = player.Transform.Rotation;
}

public override void DoClientJoined( Client cl )
Expand All @@ -60,7 +61,7 @@ public override void DoClientJoined( Client cl )
var randomplayer = allplayers.OrderBy( x => Rand.Int( 99999 ) ).FirstOrDefault();
deathpawn.Position = randomplayer.Position + Vector3.Up * 32;

PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.PlayerId, null, false );
PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.SteamId, null, false );
}

if ( GameState != GameStates.Live )
Expand All @@ -81,7 +82,7 @@ public override void DoClientJoined( Client cl )

pawn.NumberLife = 1;

PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.PlayerId, null, false );
PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.SteamId, null, false );
}
}

Expand Down
2 changes: 1 addition & 1 deletion code/Gamemodes/TagPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void TagNearbyPlayers()
}
}

[Event.Frame]
[Event.Client.Frame]
private void EnsureTagParticle()
{
var create = Tagged && TagArrowParticle == null;
Expand Down
25 changes: 25 additions & 0 deletions code/Player/Camera/BaseAnimator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

using Sandbox;
using Platformer;

public class BaseAnimator
{

protected AnimatedEntity Pawn;

public BaseAnimator( Sandbox.AnimatedEntity p )
{
Pawn = p;
}

public virtual void Simulate()
{

}

public virtual void OnEvent( string eventName )
{

}

}
10 changes: 10 additions & 0 deletions code/Player/Camera/BaseCamera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

public class BaseCamera
{

public virtual void Update()
{

}

}
4 changes: 2 additions & 2 deletions code/UI/Base/Chatbox/PlatformerChatBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static void DebugMsg()
{
var cl = ConsoleSystem.Caller;

PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.PlayerId, null, false );
PlatformerChatBox.AddChatEntry( To.Everyone, cl.Name, "has joined the game", cl.SteamId, null, false );
}

[ConCmd.Admin( "plat_debug_chat_other" )]
Expand All @@ -180,7 +180,7 @@ public static void Say( string message )
return;

Log.Info( $"{ConsoleSystem.Caller}: {message}" );
AddChatEntry( To.Everyone, ConsoleSystem.Caller.Name, message, ConsoleSystem.Caller.PlayerId );
AddChatEntry( To.Everyone, ConsoleSystem.Caller.Name, message, ConsoleSystem.Caller.SteamId );
}

}
Expand Down
2 changes: 1 addition & 1 deletion code/UI/Base/Chatbox/PlatformerChatEntry.razor
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

public string PlayerClasses()
{
if ( Local.PlayerId != PlayerId ) return "not-me";
if ( Local.SteamId != PlayerId ) return "not-me";
return "";
}

Expand Down
2 changes: 1 addition & 1 deletion code/UI/Base/MapVote/MapVoteEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected override void OnDestroy()
Current = null;
}

[Event.Frame]
[Event.Client.Frame]
public void OnFrame()
{
if ( Panel != null )
Expand Down
10 changes: 5 additions & 5 deletions code/UI/Base/World/PlatformerNameTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class NameTagComponent : EntityComponent<PlatformerPawn>

protected override void OnActivate()
{
NameTag = new NameTag( Entity.Client?.Name ?? Entity.Name, Entity.Client?.PlayerId );
NameTag = new NameTag( Entity.Client?.Name ?? Entity.Name, Entity.Client?.SteamId );
}

protected override void OnDeactivate()
Expand All @@ -26,20 +26,20 @@ protected override void OnDeactivate()
/// <summary>
/// Called for every tag, while it's active
/// </summary>
[Event.Frame]
[Event.Client.Frame]
public void FrameUpdate()
{
var tx = Entity.GetAttachment( "hat" ) ?? Entity.Transform;
tx.Position += Vector3.Up * 5.0f;
tx.Rotation = Rotation.LookAt( -CurrentView.Rotation.Forward );
tx.Rotation = Rotation.LookAt( -Camera.Rotation.Forward );

NameTag.Transform = tx;
}

/// <summary>
/// Called once per frame to manage component creation/deletion
/// </summary>
[Event.Frame]
[Event.Client.Frame]
public static void SystemUpdate()
{
foreach ( var player in Sandbox.Entity.All.OfType<PlatformerPawn>() )
Expand All @@ -51,7 +51,7 @@ public static void SystemUpdate()
continue;
}

var shouldRemove = player.Position.Distance( CurrentView.Position ) > 500;
var shouldRemove = player.Position.Distance( Camera.Position ) > 500;
shouldRemove = shouldRemove || player.LifeState != LifeState.Alive;
shouldRemove = shouldRemove || player.IsDormant;

Expand Down
2 changes: 1 addition & 1 deletion code/hammer/Gameplay/Checkpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private bool CanPlayerCheckpoint( PlatformerPawn pl )
}

private bool active;
[Event.Frame]
[Event.Client.Frame]
private void OnFrame()
{
if ( Local.Pawn is not CompetitivePlayer pl ) return;
Expand Down
2 changes: 1 addition & 1 deletion code/hammer/Gameplay/KillTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public override void Touch( Entity other )
if ( !other.IsServer ) return;
if ( other is not PlatformerPawn pl ) return;

Game.Current.DoPlayerSuicide( pl.Client );
pl.TakeDamage( new() { Damage = 9999 } );
}

}
10 changes: 5 additions & 5 deletions code/hammer/Gameplay/QuestBoy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public partial class QuestBoy : AnimatedEntity

public override void Spawn()
{
Animator = new PlatformerLookAnimator();
Animator = new PlatformerLookAnimator( this );
SetModel("models/citizen/citizen.vmdl");

EnableTouch = true;
Expand Down Expand Up @@ -80,7 +80,7 @@ public override void EndTouch( Entity other )
if ( other is not PlatformerPawn pl ) return;
LookTarget = null;
pl.LookTarget = null;
pl.CameraMode = new PlatformerOrbitCamera();
pl.Camera = new PlatformerOrbitCamera();
}

public bool OnUse( Entity user )
Expand All @@ -103,9 +103,9 @@ public void LookAtPlayer( Entity pl )

WishVelocity = Velocity;

SetAnimLookAt( "aim_eyes", pl.Position + Vector3.Up * 2f );
SetAnimLookAt( "aim_head", pl.Position + Vector3.Up * 2f );
SetAnimLookAt( "aim_body", pl.Position + Vector3.Up * 2f );
SetAnimLookAt( "aim_eyes", pl.Position, pl.Position + Vector3.Up * 2f );
SetAnimLookAt( "aim_head", pl.Position, pl.Position + Vector3.Up * 2f );
SetAnimLookAt( "aim_body", pl.Position, pl.Position + Vector3.Up * 2f );

var defaultPosition = Rotation.LookAt( pl.Position - Position ).Angles();

Expand Down
2 changes: 1 addition & 1 deletion code/hammer/Pickups/BaseCollectible.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override void Spawn()
EnableSolidCollisions = false;
}

[Event.Frame]
[Event.Client.Frame]
public void OnFrame()
{
OnFrameEvent();
Expand Down
8 changes: 4 additions & 4 deletions code/hammer/Sound/MusicBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public override void ClientSpawn()
[Event.Tick.Client]
public void Tick()
{
if ( PlayingSound.Index <= 0 )
{
OnStartSound();
}
//if ( PlayingSound.Index <= 0 )
//{
// OnStartSound();
//}
}

[ClientRpc]
Expand Down
4 changes: 2 additions & 2 deletions code/hammer/Sound/MusicBoxTweaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public override void Spawn()

}

[Event.Frame]
[Event.Client.Frame]
public void OnFrame()
{
MusicBox ??= FindByName( TargetMusicBox ) as MusicBox;
if ( !MusicBox.IsValid() ) return;

var pos = CurrentView.Position;
var pos = Camera.Position;
if ( Local.Pawn.IsValid() )
{
pos = Local.Pawn.Position;
Expand Down
4 changes: 2 additions & 2 deletions code/hammer/Sound/MusicBoxTweakerRadius.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ public override void Spawn()
Transmit = TransmitType.Always;
}

[Event.Frame]
[Event.Client.Frame]
public void OnFrame()
{
MusicBox ??= FindByName( TargetMusicBox ) as MusicBox;
if ( !MusicBox.IsValid() ) return;

var pos = CurrentView.Position + new Vector3( 0, 0, 48 );
var pos = Camera.Position + new Vector3( 0, 0, 48 );
if ( Local.Pawn.IsValid() )
{
pos = Local.Pawn.Position + new Vector3( 0, 0, 48 );
Expand Down
Loading

0 comments on commit 2ff3d45

Please sign in to comment.