add muzzle flashes to pbox/hbox

This commit is contained in:
Chris Forbes
2011-05-30 20:26:57 +12:00
parent e24c8971b6
commit 0ba41acf4a
4 changed files with 45 additions and 17 deletions

View File

@@ -194,16 +194,17 @@ namespace OpenRA.Mods.RA
return Util.RotateVectorByFacing(localRecoil, facing, .7f);
}
public static float2 GetTurretPosition(Actor self, IFacing facing, Turret turret)
{
if(facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */
if (facing == null) return turret.ScreenSpacePosition; /* things that don't have a rotating base don't need the turrets repositioned */
var ru = self.TraitOrDefault<RenderUnit>();
var numDirs = (ru != null) ? ru.anim.CurrentSequence.Facings : 8;
var bodyFacing = facing.Facing;
var quantizedFacing = Util.QuantizeFacing(bodyFacing, numDirs) * (256 / numDirs);
return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f)
return (Util.RotateVectorByFacing(turret.UnitSpacePosition, quantizedFacing, .7f)
+ GetRecoil(self, turret.Recoil))
+ turret.ScreenSpacePosition;
}

View File

@@ -11,10 +11,11 @@
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Traits;
using System;
namespace OpenRA.Mods.RA.Render
{
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSimpleInfo>
class WithMuzzleFlashInfo : ITraitInfo, Requires<RenderSimpleInfo>, Requires<AttackBaseInfo>
{
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
}
@@ -28,21 +29,29 @@ namespace OpenRA.Mods.RA.Render
{
var attack = self.Trait<AttackBase>();
var render = self.Trait<RenderSimple>();
var facing = self.Trait<IFacing>();
var facing = self.TraitOrDefault<IFacing>();
var turreted = self.TraitOrDefault<Turreted>();
foreach (var t in attack.Turrets)
{
var turret = t;
var muzzleFlash = new Animation(render.GetImage(self), () => self.Trait<IFacing>().Facing);
muzzleFlash.Play("muzzle");
var getFacing = facing != null
? () => facing.Facing :
turreted != null ? (Func<int>)(() => turreted.turretFacing) : () => 0;
render.anims.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset(
muzzleFlash,
() => Combat.GetTurretPosition(self, facing, turret),
() => !isShowing));
foreach (var w in attack.Weapons)
foreach( var b in w.Barrels )
{
var barrel = b;
var turret = w.Turret;
muzzleFlashes.Add(muzzleFlash);
}
var muzzleFlash = new Animation(render.GetImage(self), getFacing);
muzzleFlash.Play("muzzle");
render.anims.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset(
muzzleFlash,
() => Combat.GetBarrelPosition(self, facing, turret, barrel),
() => !isShowing));
muzzleFlashes.Add(muzzleFlash);
}
}
public void Attacking(Actor self, Target target)

View File

@@ -379,12 +379,17 @@ PBOX:
Type: Wood
RevealsShroud:
Range: 6
AttackOmni:
AttackTurreted:
PrimaryWeapon: Vulcan
PrimaryOffset: 0,0,0,-2
PrimaryLocalOffset: 0,-12,0
AutoTarget:
IronCurtainable:
RenderRangeCircle:
-AcceptsSupplies:
WithMuzzleFlash:
Turreted:
ROT: 255
HBOX:
Inherits: ^Building
@@ -408,12 +413,17 @@ HBOX:
Type: Wood
RevealsShroud:
Range: 6
AttackOmni:
AttackTurreted:
PrimaryWeapon: Vulcan
PrimaryOffset: 0,0,0,-2
PrimaryLocalOffset: 0,-12,0
AutoTarget:
IronCurtainable:
RenderRangeCircle:
-AcceptsSupplies:
WithMuzzleFlash:
Turreted:
ROT: 255
GUN:
Inherits: ^Building

View File

@@ -285,6 +285,10 @@ pbox:
make: pboxmake
Start: 0
Length: *
muzzle: minigun
Start: 0
Length: 6
Facings: 8
hbox:
damaged-idle:
@@ -294,6 +298,10 @@ hbox:
make: hboxmake
Start: 0
Length: *
muzzle: minigun
Start: 0
Length: 6
Facings: 8
gap:
idle: