Laser tweaks:

- Expose the beam duration to the projectileinfo
 - Play an explosion animation at the target
 - Beam tracks moving targets
 - Disable player beam color in C&C
This commit is contained in:
Paul Chote
2011-07-16 20:13:22 +12:00
parent d9d20338bf
commit ee3be9c89b
3 changed files with 29 additions and 16 deletions

View File

@@ -12,6 +12,7 @@ using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using OpenRA.Effects; using OpenRA.Effects;
using OpenRA.GameRules; using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects namespace OpenRA.Mods.RA.Effects
@@ -19,12 +20,14 @@ namespace OpenRA.Mods.RA.Effects
class LaserZapInfo : IProjectileInfo class LaserZapInfo : IProjectileInfo
{ {
public readonly int BeamRadius = 1; public readonly int BeamRadius = 1;
public readonly int BeamDuration = 10;
public readonly bool UsePlayerColor = false; public readonly bool UsePlayerColor = false;
public readonly string Explosion = "laserfire";
public IEffect Create(ProjectileArgs args) public IEffect Create(ProjectileArgs args)
{ {
Color c = UsePlayerColor ? args.firedBy.Owner.ColorRamp.GetColor(0) : Color.Red; Color c = UsePlayerColor ? args.firedBy.Owner.ColorRamp.GetColor(0) : Color.Red;
return new LaserZap(args, BeamRadius, c); return new LaserZap(args, BeamRadius, c, BeamDuration, Explosion);
} }
} }
@@ -32,46 +35,52 @@ namespace OpenRA.Mods.RA.Effects
{ {
ProjectileArgs args; ProjectileArgs args;
readonly int radius; readonly int radius;
int timeUntilRemove = 10; // # of frames int ticks = 0;
int totalTime = 10; int beamTicks; // Duration of beam
Color color; Color color;
bool doneDamage = false; bool doneDamage = false;
Animation explosion;
public LaserZap(ProjectileArgs args, int radius, Color color) public LaserZap(ProjectileArgs args, int radius, Color color, int beamTicks, string explosion)
{ {
this.args = args; this.args = args;
this.color = color; this.color = color;
this.radius = radius; this.radius = radius;
this.beamTicks = beamTicks;
this.explosion = new Animation(explosion);
} }
public void Tick(World world) public void Tick(World world)
{ {
if (timeUntilRemove <= 0) // Beam tracks target
world.AddFrameEndTask(w => w.Remove(this)); if (args.target.IsValid)
--timeUntilRemove; args.dest = args.target.CenterLocation;
if (!doneDamage) if (!doneDamage)
{ {
if (args.target.IsValid) explosion.PlayThen("idle",
args.dest = args.target.CenterLocation; () => world.AddFrameEndTask(w => w.Remove(this)));
Combat.DoImpacts(args); Combat.DoImpacts(args);
doneDamage = true; doneDamage = true;
} }
++ticks;
explosion.Tick();
} }
public IEnumerable<Renderable> Render() public IEnumerable<Renderable> Render()
{ {
int alpha = (int)((1-(float)(totalTime-timeUntilRemove)/totalTime)*255); yield return new Renderable(explosion.Image, args.dest - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
Color rc = Color.FromArgb(alpha,color);
if (ticks >= beamTicks)
yield break;
Color rc = Color.FromArgb((beamTicks-ticks)*255/beamTicks, color);
float2 unit = 1.0f/(args.src - args.dest).Length*(args.src - args.dest).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.Renderer.LineRenderer.DrawLine(args.src + i * norm, args.dest + i * norm, rc, rc); Game.Renderer.LineRenderer.DrawLine(args.src + i * norm, args.dest + i * norm, rc, rc);
yield break;
} }
} }
} }

View File

@@ -21,6 +21,11 @@ smoke_m:
Start: 0 Start: 0
Length: 26 Length: 26
laserfire:
idle:veh-hit3
Start: 0
Length: *
dragon: dragon:
idle: idle:
Start: 0 Start: 0

View File

@@ -678,7 +678,6 @@ Laser:
Report: OBELRAY1 Report: OBELRAY1
Projectile: LaserZap Projectile: LaserZap
BeamRadius: 1 BeamRadius: 1
UsePlayerColor: true
Warhead: Warhead:
Spread: 1 Spread: 1
InfDeath: 4 InfDeath: 4