Projectile重构

Posted on 2012-12-03 14:13  neocsl  阅读(217)  评论(0)    收藏  举报

  由于继承了不干净的Projectile,导致iOS上的AntGame运行缓慢,我将会重构这一部分代码。首先应从Projectile方式入手看看这个类中应该填充哪些内容.

  1.首先考虑用脚拇指都能想来的粒子,Bullet粒子,撞到墙壁的粒子。That's all.对于爆炸的子弹,无论人畜,都给他加载爆炸粒子吧。

var ParticleSystem FlightParticleTemplate;
var ParticleSystem ExplosionParticleTemplate;

 

  2.子弹在飞行的时候应该有呼啸的飞行声,爆炸的时候还有爆炸音儿。

var SoundCue AmbientFlightSoundCue;
var SoundCue ExplosionSoundCue;

  3.你也知道,飞行的子弹空中是永恒的,飞行的声音同样。

var ParticleSystemComponent FlightParticleSystemComponent;
var AudioComponent AmbientAudioComponent;

  4.标志子弹是否爆炸,以及后边是否对其威力来电加强。

var bool HasExplode;
var float DamageBoost;

 

  上边是第一部分的变量声明。我们就需要这么多。

   5.接着是初始化两个Component和template

if(FlightParticleTemplate!=none)
{
     FlightParticleSystemComponent= new () class'ParticleSystemComponent';

    if(FlightParticleSystemComponent!=none)
  {
        FlightParticleSystemComponent.SetTemplate(FlightParticleSystemTemplate);
   AttachComponent(FlightParticleSystemComponent);
  }

}

if(AmbientFlightSoundCue!=none)
{
     AmbientAudioComponent=CreateAudioComponent(AmbientFlightSoundCue,true,true);
}

  两个可选True,第一个是否Play?第二个在Actor销毁的时候是否停止演奏?

  6.处理接触敌人的伤害。

  

simulated function ProcessTouch(Actor Other,Vector HitLocation,Vector HitNormal)
{
     local Pawn Pawn;

     if(HasExplode)
     return;
   
     Pawn=Pawn(Other);
    if(Pawn!=none)
{ 
if(pawn!=none&&Other!=Instigator&&!Other.bStatic&&DamageRadius==0.f)
     {           Other.TakeDamage(Damage*DamageBoost,InstigatorController,location,MomentumTransfer*Normal(velocity),MyDamageType,, Self);
      }  
}
    else if(DamageRadius==0)
{      Other.TakeDamage(Damage*DamageBoost,InstigatorController,Location,MomentumTransfer*Normal(velocity),MyDamageType,,self);
}

    Explode(HitLocation,HitNormal);
}