TeslaZap. (Doesn't look much like real-ra, but it's only there for small-N frames, so no-one will notice, right? :)

This commit is contained in:
Bob
2009-12-16 14:29:57 +13:00
parent 4a01a911ff
commit 87e5141600
8 changed files with 157 additions and 7 deletions

86
OpenRa.Game/Effects/TeslaZap.cs Executable file
View File

@@ -0,0 +1,86 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.Graphics;
namespace OpenRa.Game.Effects
{
class TeslaZap : IEffect
{
readonly int2 from, to;
readonly Sequence tesla;
int timeUntilRemove = 2; // # of frames
public TeslaZap( int2 from, int2 to )
{
this.from = from;
this.to = to;
this.tesla = SequenceProvider.GetSequence( "litning", "bright" );
}
public void Tick()
{
if( timeUntilRemove <= 0 )
Game.world.AddFrameEndTask( w => w.Remove( this ) );
--timeUntilRemove;
}
public IEnumerable<Tuple<Sprite, float2, int>> Render()
{
if( from.X < to.X )
return Foo( from, to, tesla );
else if( from.X > to.X || from.Y > to.Y )
return Foo( to, from, tesla );
else
return Foo( from, to, tesla );
}
static IEnumerable<Tuple<Sprite, float2, int>> Foo( int2 from, int2 to, Sequence tesla )
{
int2 d = to - from;
if( d.X < 8 )
{
var prev = new int2( 0, 0 );
var y = d.Y;
while( y >= prev.Y + 8 )
{
yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 8 ) ), 0 );
prev.Y += 8;
}
}
else
{
var prev = new int2( 0, 0 );
for( int i = 1 ; i < d.X ; i += 8 )
{
var y = i * d.Y / d.X;
if( y <= prev.Y - 8 )
{
yield return Tuple.New( tesla.GetSprite( 3 ), (float2)( from + prev - new int2( 8, 16 ) ), 0 );
prev.Y -= 8;
while( y <= prev.Y - 8 )
{
yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 16 ) ), 0 );
prev.Y -= 8;
}
}
else if( y >= prev.Y + 8 )
{
yield return Tuple.New( tesla.GetSprite( 0 ), (float2)( from + prev - new int2( 8, 8 ) ), 0 );
prev.Y += 8;
while( y >= prev.Y + 8 )
{
yield return Tuple.New( tesla.GetSprite( 2 ), (float2)( from + prev - new int2( 0, 8 ) ), 0 );
prev.Y -= 8;
}
}
else
yield return Tuple.New( tesla.GetSprite( 1 ), (float2)( from + prev - new int2( 8, 8 ) ), 0 );
prev.X += 8;
}
}
}
}
}

View File

@@ -16,5 +16,7 @@ namespace OpenRa.Game.GameRules
public readonly bool Supress = false;
public readonly bool TurboBoost = false;
public readonly string Warhead = null;
public readonly bool RenderAsTesla = false;
}
}

View File

@@ -81,6 +81,7 @@
<Compile Include="Chrome.cs" />
<Compile Include="Combat.cs" />
<Compile Include="Effects\Smoke.cs" />
<Compile Include="Effects\TeslaZap.cs" />
<Compile Include="Exts.cs" />
<Compile Include="GameRules\ActorInfo.cs" />
<Compile Include="GameRules\GeneralInfo.cs" />

View File

@@ -108,7 +108,10 @@ namespace OpenRa.Game.Traits
var thisTarget = target;
ScheduleDelayedAction(self.Info.FireDelay, () =>
{
if (Rules.ProjectileInfo[weapon.Projectile].ROT != 0)
if( weapon.RenderAsTesla )
Game.world.Add( new TeslaZap( firePos, thisTarget.CenterLocation.ToInt2() ) );
if( Rules.ProjectileInfo[ weapon.Projectile ].ROT != 0 )
Game.world.Add(new Missile(weaponName, self.Owner, self,
firePos, thisTarget));
else