working missile trails
This commit is contained in:
@@ -14,6 +14,7 @@ using OpenRA.Effects;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Traits;
|
||||
using System.Drawing;
|
||||
|
||||
namespace OpenRA.Mods.RA.Effects
|
||||
{
|
||||
@@ -30,6 +31,9 @@ namespace OpenRA.Mods.RA.Effects
|
||||
public readonly bool Proximity = false;
|
||||
public readonly float Angle = 0;
|
||||
public readonly int TrailInterval = 2;
|
||||
public readonly int ContrailLength = 0;
|
||||
public readonly bool ContrailUsePlayerColor = false;
|
||||
public readonly int ContrailDelay = 1;
|
||||
|
||||
public IEffect Create(ProjectileArgs args) { return new Bullet( this, args ); }
|
||||
}
|
||||
@@ -43,6 +47,7 @@ namespace OpenRA.Mods.RA.Effects
|
||||
Animation anim;
|
||||
|
||||
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
|
||||
ContrailHistory Trail;
|
||||
|
||||
public Bullet(BulletInfo info, ProjectileArgs args)
|
||||
{
|
||||
@@ -60,6 +65,13 @@ namespace OpenRA.Mods.RA.Effects
|
||||
anim = new Animation(Info.Image, GetEffectiveFacing);
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
|
||||
if (Info.ContrailLength > 0)
|
||||
{
|
||||
Trail = new ContrailHistory(Info.ContrailLength,
|
||||
Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Color.White,
|
||||
Info.ContrailDelay);
|
||||
}
|
||||
}
|
||||
|
||||
int TotalTime() { return (Args.dest - Args.src).Length * BaseBulletSpeed / Info.Speed; }
|
||||
@@ -94,7 +106,6 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
if (t > TotalTime()) Explode( world );
|
||||
|
||||
if (Info.Trail != null)
|
||||
{
|
||||
var at = (float)t / TotalTime();
|
||||
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
|
||||
@@ -104,12 +115,15 @@ namespace OpenRA.Mods.RA.Effects
|
||||
? (pos - new float2(0, GetAltitude()))
|
||||
: pos;
|
||||
|
||||
if (--ticksToNextSmoke < 0)
|
||||
if (Info.Trail != null && --ticksToNextSmoke < 0)
|
||||
{
|
||||
world.AddFrameEndTask(w => w.Add(
|
||||
new Smoke(w, highPos.ToInt2(), Info.Trail)));
|
||||
ticksToNextSmoke = Info.TrailInterval;
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Tick(highPos);
|
||||
}
|
||||
|
||||
if (!Info.High) // check for hitting a wall
|
||||
@@ -129,29 +143,35 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
const float height = .1f;
|
||||
|
||||
public IEnumerable<Renderable> Render()
|
||||
{
|
||||
if (anim != null)
|
||||
{
|
||||
var at = (float)t / TotalTime();
|
||||
public IEnumerable<Renderable> Render()
|
||||
{
|
||||
if (anim != null)
|
||||
{
|
||||
var at = (float)t / TotalTime();
|
||||
|
||||
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
|
||||
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
|
||||
var altitude = float2.Lerp(Args.srcAltitude, Args.destAltitude, at);
|
||||
var pos = float2.Lerp(Args.src, Args.dest, at) - new float2(0, altitude);
|
||||
|
||||
if (Info.High || Info.Angle > 0)
|
||||
{
|
||||
if (Info.Shadow)
|
||||
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "shadow", (int)pos.Y);
|
||||
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(pos)))
|
||||
{
|
||||
if (Info.High || Info.Angle > 0)
|
||||
{
|
||||
if (Info.Shadow)
|
||||
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, "shadow", (int)pos.Y);
|
||||
|
||||
var highPos = pos - new float2(0, GetAltitude());
|
||||
var highPos = pos - new float2(0, GetAltitude());
|
||||
|
||||
yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, Args.firedBy.Owner.Palette, (int)pos.Y);
|
||||
}
|
||||
else
|
||||
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size,
|
||||
Args.weapon.Underwater ? "shadow" : Args.firedBy.Owner.Palette, (int)pos.Y);
|
||||
}
|
||||
}
|
||||
yield return new Renderable(anim.Image, highPos - .5f * anim.Image.size, Args.firedBy.Owner.Palette, (int)pos.Y);
|
||||
}
|
||||
else
|
||||
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size,
|
||||
Args.weapon.Underwater ? "shadow" : Args.firedBy.Owner.Palette, (int)pos.Y);
|
||||
}
|
||||
}
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(Args.firedBy);
|
||||
}
|
||||
|
||||
void Explode( World world )
|
||||
{
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace OpenRA.Mods.RA
|
||||
List<float2> positions = new List<float2>();
|
||||
readonly int TrailLength;
|
||||
readonly Color Color;
|
||||
readonly int StartSkip;
|
||||
|
||||
public static Color ChooseColor(Actor self)
|
||||
{
|
||||
@@ -66,9 +67,13 @@ namespace OpenRA.Mods.RA
|
||||
}
|
||||
|
||||
public ContrailHistory(int trailLength, Color color)
|
||||
: this(trailLength, color, 0) { }
|
||||
|
||||
public ContrailHistory(int trailLength, Color color, int startSkip)
|
||||
{
|
||||
this.TrailLength = trailLength;
|
||||
this.Color = color;
|
||||
this.StartSkip = startSkip;
|
||||
}
|
||||
|
||||
public void Tick(float2 currentPos)
|
||||
@@ -84,7 +89,7 @@ namespace OpenRA.Mods.RA
|
||||
Color trailEnd = Color.FromArgb(trailStart.A - 255 / TrailLength, trailStart.R,
|
||||
trailStart.G, trailStart.B);
|
||||
|
||||
for (int i = positions.Count - 1; i >= 1; --i)
|
||||
for (int i = positions.Count - 1 - StartSkip; i >= 1; --i)
|
||||
{
|
||||
var conPos = positions[i];
|
||||
var nextPos = positions[i - 1];
|
||||
|
||||
@@ -34,7 +34,8 @@ namespace OpenRA.Mods.RA.Effects
|
||||
public readonly bool TurboBoost = false;
|
||||
public readonly int TrailInterval = 2;
|
||||
public readonly int ContrailLength = 0;
|
||||
public readonly bool ContrailUsePlayerColor = true;
|
||||
public readonly bool ContrailUsePlayerColor = false;
|
||||
public readonly int ContrailDelay = 1;
|
||||
|
||||
public IEffect Create(ProjectileArgs args) { return new Missile( this, args ); }
|
||||
}
|
||||
@@ -54,28 +55,31 @@ namespace OpenRA.Mods.RA.Effects
|
||||
int Altitude;
|
||||
ContrailHistory Trail;
|
||||
|
||||
public Missile(MissileInfo info, ProjectileArgs args)
|
||||
{
|
||||
Info = info;
|
||||
Args = args;
|
||||
public Missile(MissileInfo info, ProjectileArgs args)
|
||||
{
|
||||
Info = info;
|
||||
Args = args;
|
||||
|
||||
SubPxPosition = 1024*Args.src;
|
||||
Altitude = Args.srcAltitude;
|
||||
Facing = Args.facing;
|
||||
SubPxPosition = 1024 * Args.src;
|
||||
Altitude = Args.srcAltitude;
|
||||
Facing = Args.facing;
|
||||
|
||||
if (info.Inaccuracy > 0)
|
||||
offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
|
||||
if (info.Inaccuracy > 0)
|
||||
offset = (info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
|
||||
|
||||
if (Info.Image != null)
|
||||
{
|
||||
anim = new Animation(Info.Image, () => Facing);
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
if (Info.Image != null)
|
||||
{
|
||||
anim = new Animation(Info.Image, () => Facing);
|
||||
anim.PlayRepeating("idle");
|
||||
}
|
||||
|
||||
if (Info.ContrailLength > 0)
|
||||
Trail = new ContrailHistory(Info.ContrailLength,
|
||||
Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Color.White);
|
||||
}
|
||||
{
|
||||
Trail = new ContrailHistory(Info.ContrailLength,
|
||||
Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Color.White,
|
||||
Info.ContrailDelay);
|
||||
}
|
||||
}
|
||||
|
||||
// In pixels
|
||||
const int MissileCloseEnough = 7;
|
||||
@@ -149,8 +153,9 @@ namespace OpenRA.Mods.RA.Effects
|
||||
|
||||
public IEnumerable<Renderable> Render()
|
||||
{
|
||||
yield return new Renderable(anim.Image,PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
|
||||
Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y);
|
||||
if (Args.firedBy.World.LocalShroud.IsVisible(OpenRA.Traits.Util.CellContaining(PxPosition.ToFloat2())))
|
||||
yield return new Renderable(anim.Image,PxPosition.ToFloat2() - 0.5f * anim.Image.size - new float2(0, Altitude),
|
||||
Args.weapon.Underwater ? "shadow" : "effect", PxPosition.Y);
|
||||
|
||||
if (Trail != null)
|
||||
Trail.Render(Args.firedBy);
|
||||
|
||||
Reference in New Issue
Block a user