-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77b45e7
commit 7ad3aa0
Showing
26 changed files
with
308 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using SandboxEditor; | ||
using Sandbox; | ||
using System.ComponentModel; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Platformer; | ||
|
||
[Library( "plat_musicbox", Description = "Music Box" )] | ||
[EditorSprite( "materials/editor/musicbox/musicbox.vmat" )] | ||
[Display( Name = "Music Box", GroupName = "Platformer", Description = "Platformer Soundscape" ), Category( "Sound" ), Icon( "speaker" )] | ||
[HammerEntity] | ||
partial class MusicBox : Entity | ||
{ | ||
/// <summary> | ||
/// Name of the sound to play. | ||
/// </summary> | ||
[Property( "soundName" ), FGDType( "sound" )] | ||
[Net] public string SoundName { get; set; } | ||
|
||
/// <summary> | ||
/// Name of the sound to play. | ||
/// </summary> | ||
[Property( "bgsoundName" ), FGDType( "sound" )] | ||
[Net] public string BGSoundName { get; set; } | ||
|
||
[Net] public float Volume { get; set; } | ||
|
||
public Sound PlayingSound { get; protected set; } | ||
public Sound BGPlayingSound { get; protected set; } | ||
|
||
|
||
public override void Spawn() | ||
{ | ||
base.Spawn(); | ||
|
||
Transmit = TransmitType.Always; | ||
} | ||
|
||
public override void ClientSpawn() | ||
{ | ||
// OnStartSound(); | ||
} | ||
|
||
[Event.Tick.Client] | ||
public void Tick() | ||
{ | ||
if ( PlayingSound.Index <= 0 ) | ||
{ | ||
OnStartSound(); | ||
} | ||
} | ||
|
||
[ClientRpc] | ||
protected void OnStartSound() | ||
{ | ||
PlayingSound = Sound.FromScreen( SoundName ).SetVolume( 1 ); | ||
BGPlayingSound = Sound.FromScreen( BGSoundName ).SetVolume( .1f ); | ||
} | ||
|
||
[ClientRpc] | ||
public void UpdateVolume(float vol) | ||
{ | ||
PlayingSound.SetVolume( 1 - vol ); | ||
BGPlayingSound.SetVolume( vol ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
| ||
using SandboxEditor; | ||
using Sandbox; | ||
using System.ComponentModel.DataAnnotations; | ||
using System; | ||
|
||
namespace Platformer; | ||
|
||
[Library( "plat_musicboxtweaker", Description = "Music Box Tweaker" )] | ||
[EditorSprite( "materials/editor/musicboxtweaker/musicboxtweaker.vmat" )] | ||
[Display( Name = "Music Box Tweaker", GroupName = "Platformer", Description = "Platformer Soundscape" ), Category( "Sound" ), Icon( "speaker" )] | ||
[HammerEntity] | ||
[BoundsHelper( "mins", "maxs", false, true )] | ||
partial class MusicBoxTweaker : ModelEntity | ||
{ | ||
[Net, Property, FGDType( "target_destination" )] public string TargetMusicBox { get; set; } = ""; | ||
[Net] public float Volume { get; set; } = 1; | ||
|
||
[Property( "mins", Title = "Tweaker mins" )] | ||
[Net] | ||
public Vector3 Mins { get; set; } = new Vector3( -32, -32, 0 ); | ||
|
||
[Property( "maxs", Title = "Tweaker maxs" )] | ||
[Net] | ||
public Vector3 Maxs { get; set; } = new Vector3( 32, 32, 64 ); | ||
|
||
private MusicBox MusicBox; | ||
private Vector3[] DirectionLut = new Vector3[] | ||
{ | ||
Vector3.Up, | ||
Vector3.Down, | ||
Vector3.Left, | ||
Vector3.Right, | ||
Vector3.Forward, | ||
Vector3.Backward | ||
}; | ||
|
||
public override void Spawn() | ||
{ | ||
base.Spawn(); | ||
|
||
Transmit = TransmitType.Always; | ||
} | ||
|
||
[Event.Frame] | ||
public void OnFrame() | ||
{ | ||
MusicBox ??= FindByName( TargetMusicBox ) as MusicBox; | ||
if ( !MusicBox.IsValid() ) return; | ||
|
||
var pos = CurrentView.Position; | ||
if ( Local.Pawn.IsValid() ) | ||
{ | ||
pos = Local.Pawn.Position; | ||
} | ||
|
||
var bbox = new BBox( Position + Mins, Position + Maxs ); | ||
var playerBbox = new BBox( pos - new Vector3( 8, 8, 0 ), pos + new Vector3( 8, 8, 64 ) ); | ||
|
||
if ( !bbox.Overlaps( playerBbox ) ) | ||
return; | ||
|
||
var dist = ShortestDistanceToSurface( bbox, pos ) - 8.0f; | ||
var vol = Math.Max( dist.LerpInverse( 0f, 64f ), 0.1f ); | ||
|
||
if ( BasePlayerController.Debug ) | ||
{ | ||
DebugOverlay.Box( bbox, Color.Green ); | ||
DebugOverlay.Text( vol.ToString(), bbox.Center, 0, 3000 ); | ||
} | ||
|
||
MusicBox.UpdateVolume( vol ); | ||
} | ||
|
||
private float ShortestDistanceToSurface( BBox bbox, Vector3 position ) | ||
{ | ||
var result = float.MaxValue; | ||
var point = Vector3.Zero; | ||
foreach ( var dir in DirectionLut ) | ||
{ | ||
var closetsPoint = bbox.ClosestPoint( position + dir * 10000 ); | ||
var dist = Vector3.DistanceBetween( closetsPoint, position + new Vector3( 0, 0, 48 ) ); | ||
if( dist < result ) | ||
{ | ||
point = closetsPoint; | ||
result = dist; | ||
} | ||
} | ||
|
||
if ( BasePlayerController.Debug ) | ||
{ | ||
DebugOverlay.Sphere( point, 3f, Color.Red, 0, false ); | ||
DebugOverlay.Line( point, position + new Vector3(0,0,48), 0f, false ); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
| ||
using SandboxEditor; | ||
using Sandbox; | ||
using System.ComponentModel.DataAnnotations; | ||
using System; | ||
|
||
namespace Platformer; | ||
|
||
[Library( "plat_musicboxtweakerradius", Description = "Music Box Tweaker Radius" )] | ||
[EditorSprite( "editor/ent_logic.vmat" )] | ||
[Display( Name = "Music Box Tweaker", GroupName = "Platformer", Description = "Platformer Soundscape" ), Category( "Sound" ), Icon( "speaker" )] | ||
[HammerEntity] | ||
[Sphere( "radius" )] | ||
partial class MusicBoxTweakerRadius : ModelEntity | ||
{ | ||
[Net, Property, FGDType( "target_destination" )] public string TargetMusicBox { get; set; } = ""; | ||
[Net] public float Volume { get; set; } = 1; | ||
[Net, Property] | ||
public float Radius { get; set; } = 128.0f; | ||
|
||
private MusicBox MusicBox; | ||
|
||
public override void Spawn() | ||
{ | ||
base.Spawn(); | ||
|
||
Transmit = TransmitType.Always; | ||
} | ||
|
||
[Event.Frame] | ||
public void OnFrame() | ||
{ | ||
MusicBox ??= FindByName( TargetMusicBox ) as MusicBox; | ||
if ( !MusicBox.IsValid() ) return; | ||
|
||
var pos = CurrentView.Position; | ||
if ( Local.Pawn.IsValid() ) | ||
{ | ||
pos = Local.Pawn.Position; | ||
} | ||
|
||
var dist = Position.Distance( pos ); | ||
if ( dist > Radius ) | ||
return; | ||
|
||
var vol = (Radius - dist).LerpInverse( 0, 64f ); | ||
vol = Math.Max( 0.1f, vol ); | ||
|
||
MusicBox.UpdateVolume( vol ); | ||
|
||
if ( BasePlayerController.Debug ) | ||
{ | ||
DebugOverlay.Text( vol.ToString(), Position ); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.