Skip to content

Commit

Permalink
Added ShakeScreenUntil
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Dec 9, 2023
1 parent c9c952c commit 7b21864
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using FlatRedBall.Math;
using FlatRedBall.Math.Geometry;
using Microsoft.Xna.Framework;
Expand Down Expand Up @@ -718,9 +719,9 @@ public void ApplySeparationForZoom(Vector2 separationVector)
Camera.FixAspectRatioYConstant();
}

const float individualShakeDurationInSeconds = .05f;
public async void ShakeScreen(float shakeRadius, float durationInSeconds)
{
const float individualShakeDurationInSeconds = .05f;

var random = FlatRedBallServices.Random;
for (float timePassed = 0; timePassed < durationInSeconds; timePassed += individualShakeDurationInSeconds)
Expand All @@ -737,5 +738,23 @@ public async void ShakeScreen(float shakeRadius, float durationInSeconds)
CameraOffset.X = 0;
CameraOffset.Y = 0;
}

public async void ShakeScreenUntil(float shakeRadius, Task taskToAwait)
{
var random = FlatRedBallServices.Random;
while(!taskToAwait.IsCompleted)
{
var point = random.PointInCircle(shakeRadius);

// todo - use velocity here instead of snapping
CameraOffset.X = point.X;
CameraOffset.Y = point.Y;

await TimeManager.DelaySeconds(individualShakeDurationInSeconds);
}

CameraOffset.X = 0;
CameraOffset.Y = 0;
}
}
}

0 comments on commit 7b21864

Please sign in to comment.