Convert ScreenShaker to world coords.
This commit is contained in:
@@ -14,12 +14,12 @@ using System.Linq;
|
||||
|
||||
namespace OpenRA.Traits
|
||||
{
|
||||
class ScreenShakerInfo : TraitInfo<ScreenShaker> {}
|
||||
public class ScreenShakerInfo : TraitInfo<ScreenShaker> { }
|
||||
|
||||
public class ScreenShaker : ITick
|
||||
{
|
||||
int ticks = 0;
|
||||
List<ShakeEffect> shakeEffects = new List<ShakeEffect>();
|
||||
int ticks = 0;
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
@@ -28,33 +28,36 @@ namespace OpenRA.Traits
|
||||
Game.viewport.Scroll(GetScrollOffset(), true);
|
||||
shakeEffects.RemoveAll(t => t.ExpiryTime == ticks);
|
||||
}
|
||||
|
||||
ticks++;
|
||||
}
|
||||
|
||||
public void AddEffect(int time, float2 position, int intensity)
|
||||
public void AddEffect(int time, WPos position, int intensity)
|
||||
{
|
||||
shakeEffects.Add(new ShakeEffect { ExpiryTime = ticks + time, Position = position, Intensity = intensity });
|
||||
}
|
||||
|
||||
float2 GetScrollOffset()
|
||||
{
|
||||
int xFreq = 4;
|
||||
int yFreq = 5;
|
||||
|
||||
return GetIntensity() * new float2(
|
||||
(float) Math.Sin((ticks*2*Math.PI)/xFreq) ,
|
||||
(float) Math.Cos((ticks*2*Math.PI)/yFreq));
|
||||
(float)Math.Sin((ticks * 2 * Math.PI) / 4),
|
||||
(float)Math.Cos((ticks * 2 * Math.PI) / 5));
|
||||
}
|
||||
|
||||
float GetIntensity()
|
||||
{
|
||||
var cp = Game.viewport.CenterLocation;
|
||||
var intensity = Game.CellSize * Game.CellSize * 100 * shakeEffects.Sum(
|
||||
e => e.Intensity / (e.Position - cp).LengthSquared);
|
||||
var cp = ((PPos)Game.viewport.CenterLocation.ToInt2()).ToWPos(0);
|
||||
var intensity = 100 * 1024 * 1024 * shakeEffects.Sum(
|
||||
e => (float)e.Intensity / (e.Position - cp).LengthSquared);
|
||||
|
||||
return Math.Min(intensity, 10);
|
||||
}
|
||||
}
|
||||
|
||||
class ShakeEffect { public int ExpiryTime; public float2 Position; public int Intensity; }
|
||||
struct ShakeEffect
|
||||
{
|
||||
public int ExpiryTime;
|
||||
public WPos Position;
|
||||
public int Intensity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA.Buildings
|
||||
|
||||
public void Killed(Actor self, AttackInfo e)
|
||||
{
|
||||
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(Info.Intensity, self.CenterLocation.ToFloat2(), 1);
|
||||
self.World.WorldActor.Trait<ScreenShaker>().AddEffect(Info.Intensity, self.CenterPosition, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Remove(this));
|
||||
Combat.DoExplosion(firedBy.PlayerActor, weapon, pos);
|
||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, PPos.FromWPos(pos).ToFloat2(), 5);
|
||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(20, pos, 5);
|
||||
|
||||
foreach (var a in world.ActorsWithTrait<NukePaletteEffect>())
|
||||
a.Trait.Enable();
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace OpenRA.Mods.RA.Missions
|
||||
.OrderBy(a => (startJeep.CenterPosition - a.CenterPosition).LengthSquared)
|
||||
.First();
|
||||
Combat.DoExplosion(bridge, "Demolish", bridge.CenterPosition);
|
||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(15, bridge.CenterLocation.ToFloat2(), 6);
|
||||
world.WorldActor.Trait<ScreenShaker>().AddEffect(15, bridge.CenterPosition, 6);
|
||||
bridge.Kill(bridge);
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user