LaserZap rendering and damage wired up.

This commit is contained in:
Matthew
2010-04-09 20:31:34 +12:00
parent 4f9fb8f08d
commit 55ee313f6c

View File

@@ -1,4 +1,4 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford. * Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA. * This file is part of OpenRA.
@@ -30,21 +30,25 @@ namespace OpenRA.Effects
public readonly int BeamRadius = 1; public readonly int BeamRadius = 1;
public readonly bool UsePlayerColor = false; public readonly bool UsePlayerColor = false;
public IEffect Create(ProjectileArgs args) { return null; /* todo: fix me so OBLI works again */ } public IEffect Create(ProjectileArgs args)
{
Color c = UsePlayerColor ? args.firedBy.Owner.Color : Color.Red;
return new LaserZap(args, BeamRadius, c);
}
} }
class LaserZap : IEffect class LaserZap : IEffect
{ {
readonly int2 from, to; ProjectileArgs args;
readonly int radius; readonly int radius;
int timeUntilRemove = 10; // # of frames int timeUntilRemove = 10; // # of frames
int totalTime = 10; int totalTime = 10;
Color color; Color color;
bool doneDamage = false;
public LaserZap(int2 from, int2 to, int radius, Color color) public LaserZap(ProjectileArgs args, int radius, Color color)
{ {
this.from = from; this.args = args;
this.to = to;
this.color = color; this.color = color;
this.radius = radius; this.radius = radius;
} }
@@ -54,6 +58,12 @@ namespace OpenRA.Effects
if (timeUntilRemove <= 0) if (timeUntilRemove <= 0)
world.AddFrameEndTask(w => w.Remove(this)); world.AddFrameEndTask(w => w.Remove(this));
--timeUntilRemove; --timeUntilRemove;
if (!doneDamage)
{
Combat.DoImpacts(args, args.dest);
doneDamage = true;
}
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
@@ -61,11 +71,11 @@ namespace OpenRA.Effects
int alpha = (int)((1-(float)(totalTime-timeUntilRemove)/totalTime)*255); int alpha = (int)((1-(float)(totalTime-timeUntilRemove)/totalTime)*255);
Color rc = Color.FromArgb(alpha,color); Color rc = Color.FromArgb(alpha,color);
float2 unit = 1.0f/(from - to).Length*(from - to).ToFloat2(); float2 unit = 1.0f/(args.src - args.dest).Length*(args.src - args.dest).ToFloat2();
float2 norm = new float2(-unit.Y, unit.X); float2 norm = new float2(-unit.Y, unit.X);
for (int i = -radius; i < radius; i++) for (int i = -radius; i < radius; i++)
Game.world.WorldRenderer.lineRenderer.DrawLine(from + i * norm, to + i * norm, rc, rc); Game.world.WorldRenderer.lineRenderer.DrawLine(args.src + i * norm, args.dest + i * norm, rc, rc);
yield break; yield break;
} }