husk experiment

This commit is contained in:
Chris Forbes
2010-05-14 20:46:47 +12:00
parent 9606827f34
commit 6936c73b68
8 changed files with 205 additions and 4 deletions

View File

@@ -0,0 +1,42 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class LeavesHuskInfo : TraitInfo<LeavesHusk> { public readonly string HuskActor = null; }
class LeavesHusk : INotifyDamage
{
public void Damaged(Actor self, AttackInfo e)
{
if (e.DamageState == DamageState.Dead)
self.World.AddFrameEndTask(w =>
{
var info = self.Info.Traits.Get<LeavesHuskInfo>();
var husk = w.CreateActor(info.HuskActor, self.Location, self.Owner);
husk.CenterLocation = self.CenterLocation;
husk.traits.Get<Unit>().Altitude = self.traits.Get<Unit>().Altitude;
husk.traits.Get<Unit>().Facing = self.traits.Get<Unit>().Facing;
});
}
}
}

View File

@@ -62,6 +62,7 @@
<Compile Include="Effects\NukeLaunch.cs" />
<Compile Include="Activities\Harvest.cs" />
<Compile Include="Harvester.cs" />
<Compile Include="LeavesHusk.cs" />
<Compile Include="OreRefinery.cs" />
<Compile Include="ChronoshiftPaletteEffect.cs" />
<Compile Include="ChronoshiftPower.cs" />
@@ -94,6 +95,7 @@
<Compile Include="TeslaInstantKills.cs" />
<Compile Include="Thief.cs" />
<Compile Include="Crates\ResetRadarCrateAction.cs" />
<Compile Include="ThrowsParticles.cs" />
<Compile Include="TraitsInterfaces.cs" />
<Compile Include="DefaultShellmapScript.cs" />
</ItemGroup>

View File

@@ -0,0 +1,76 @@
#region Copyright & License Information
/*
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
* This file is part of OpenRA.
*
* OpenRA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenRA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
*/
#endregion
using OpenRA.Traits;
using OpenRA.Graphics;
namespace OpenRA.Mods.RA
{
class ThrowsParticleInfo : ITraitInfo
{
public readonly string Anim = null;
public readonly int[] Offset = new[] { 0, 0, 0, 0 };
public readonly int[] Spread = new[] { 0, 0 };
public readonly float Speed = 20;
public readonly string AnimKey = null;
public object Create(Actor self) { return new ThrowsParticle(self, this); }
}
class ThrowsParticle : ITick
{
ThrowsParticleInfo info;
float2 pos;
float alt;
float2 v;
float va;
const float gravity = 1.3f;
public ThrowsParticle(Actor self, ThrowsParticleInfo info) { this.info = info; }
public void Tick(Actor self)
{
if (info != null)
{
alt = 0;
pos = Util.GetTurretPosition(self, self.traits.Get<Unit>(), info.Offset, 0);
var ru = self.traits.Get<RenderUnit>();
v = Game.CosmeticRandom.Gauss2D(1) * info.Spread.RelOffset();
va = info.Speed;
var anim = new Animation(ru.GetImage(self), () => self.traits.Get<Unit>().Facing);
anim.PlayRepeating(info.Anim);
ru.anims.Add(info.AnimKey, new RenderSimple.AnimationWithOffset(
anim, () => pos - new float2(0, alt), null));
info = null;
}
pos += v;
v = .9f * v;
va -= gravity;
alt += va;
if (alt < 0) alt = 0;
}
}
}