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 OpenRA.Effects;
using OpenRA.GameRules;
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA.Effects
@@ -19,12 +20,14 @@ namespace OpenRA.Mods.RA.Effects
class LaserZapInfo : IProjectileInfo
{
public readonly int BeamRadius = 1;
public readonly int BeamDuration = 10;
public readonly bool UsePlayerColor = false;
public readonly string Explosion = "laserfire";
public IEffect Create(ProjectileArgs args)
{
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;
readonly int radius;
int timeUntilRemove = 10; // # of frames
int totalTime = 10;
int ticks = 0;
int beamTicks; // Duration of beam
Color color;
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.color = color;
this.radius = radius;
this.beamTicks = beamTicks;
this.explosion = new Animation(explosion);
}
public void Tick(World world)
{
if (timeUntilRemove <= 0)
world.AddFrameEndTask(w => w.Remove(this));
--timeUntilRemove;
// Beam tracks target
if (args.target.IsValid)
args.dest = args.target.CenterLocation;
if (!doneDamage)
{
if (args.target.IsValid)
args.dest = args.target.CenterLocation;
explosion.PlayThen("idle",
() => world.AddFrameEndTask(w => w.Remove(this)));
Combat.DoImpacts(args);
doneDamage = true;
}
++ticks;
explosion.Tick();
}
public IEnumerable<Renderable> Render()
{
int alpha = (int)((1-(float)(totalTime-timeUntilRemove)/totalTime)*255);
Color rc = Color.FromArgb(alpha,color);
yield return new Renderable(explosion.Image, args.dest - .5f * explosion.Image.size, "effect", (int)args.dest.Y);
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 norm = new float2(-unit.Y, unit.X);
for (int i = -radius; i < radius; i++)
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
Length: 26
laserfire:
idle:veh-hit3
Start: 0
Length: *
dragon:
idle:
Start: 0

View File

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