Skip to content

Commit da7e04a

Browse files
committed
Broadcast the screenshake and sound effects for sudden death
1 parent 38f7dee commit da7e04a

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

code/Terrain/Terrain.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,12 @@ private bool IsDistanceValid( List<GameObject> objects, Vector3 pos, float minDi
134134

135135
public async Task LowerTerrain( float amount )
136136
{
137+
LowerTerrainEffects();
138+
137139
var targetPosition = SdfWorld.WorldPosition - Vector3.Up * amount;
138140

139-
Sound.Play( "suddendeath_rumble" );
140-
141141
while ( Vector3.DistanceBetween( SdfWorld.WorldPosition, targetPosition ) > Time.Delta * 5f )
142142
{
143-
if ( Scene.Camera.IsValid() )
144-
Scene.Camera.WorldPosition += Vector3.Random * 6f;
145-
146143
var currentPosition = SdfWorld.WorldPosition;
147144
SdfWorld.WorldPosition = Vector3.Lerp( SdfWorld.WorldPosition, targetPosition, Time.Delta * 3f );
148145

@@ -155,6 +152,32 @@ public async Task LowerTerrain( float amount )
155152
}
156153
}
157154

155+
[Rpc.Broadcast( NetFlags.HostOnly )]
156+
private void LowerTerrainEffects()
157+
{
158+
Log.Info( "Playing sudden death terrain lowering effects." );
159+
160+
Sound.Play( "suddendeath_rumble" );
161+
162+
_ = ScreenShake();
163+
}
164+
165+
private async Task ScreenShake()
166+
{
167+
await GameTask.MainThread();
168+
169+
if ( !Scene.Camera.IsValid() )
170+
return;
171+
172+
var progress = 0f;
173+
while ( progress < 1f )
174+
{
175+
progress += Time.Delta / 2f;
176+
Scene.Camera.WorldPosition += Vector3.Random * 6f;
177+
await GameTask.DelaySeconds( Time.Delta / 2f );
178+
}
179+
}
180+
158181
protected override void DrawGizmos()
159182
{
160183
base.DrawGizmos();

0 commit comments

Comments
 (0)