예제 #1
0
        protected ProjectileWeapon(ProjectileWeaponData data, PhysicalUnit owner)
            : base(TimeSpan.FromSeconds(1.0 / data.FireRate), owner)
        {
            _name = data.Name;
            _projectilesPerFire = data.ProjectilesPerFire;
            _projectileInfo = data.ProjectileInfo;
            _spread = data.Spread;

            _contactEffect = _projectileInfo.ContactEffect == null ?
                ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ContactEffect);
            _proximityEffect = _projectileInfo.ProximityEffect == null ?
                 ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ProximityEffect);
            _destinationEffect = _projectileInfo.DestinationEffect == null ?
                ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.DestinationEffect);

            _fireParticleEffect = data.FireParticleEffectName == null ?
                null : new ParticleEffect(data.FireParticleEffectName);
            float maxProjLife = data.ProjectileInfo.SecondsToLive +
                Math.Max((float)_contactEffect.Duration.TotalSeconds, (float)_destinationEffect.Duration.TotalSeconds);
            float maxProjectiles = data.FireRate * maxProjLife * data.ProjectilesPerFire;
            maxProjectiles = Math.Max(maxProjectiles, _projectilesPerFire);
            _projectiles = new Projectile[(int)maxProjectiles + 1];
            for (int i = 0; i < _projectiles.Length; i++)
            {
                _projectiles[i] = new Projectile(data.ProjectileInfo.SpriteName);
            }
        }
예제 #2
0
        protected ProjectileWeapon(ProjectileWeaponData data, PhysicalUnit owner)
            : base(TimeSpan.FromSeconds(1.0 / data.FireRate), 1, 0, owner)
        {
            _name = data.Name;
            _projectilesPerFire = data.ProjectilesPerFire;
            _projectileInfo     = data.ProjectileInfo;
            _spread             = data.Spread;

            _contactEffect = _projectileInfo.ContactEffect == null ?
                             ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ContactEffect);
            _proximityEffect = _projectileInfo.ProximityEffect == null ?
                               ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.ProximityEffect);
            _destinationEffect = _projectileInfo.DestinationEffect == null ?
                                 ProjectileEffect.NullEffect : new ProjectileEffect(_projectileInfo.DestinationEffect);

            _fireParticleEffect = data.FireParticleEffectName == null ?
                                  null : new ParticleEffect(data.FireParticleEffectName);
            float maxProjLife = data.ProjectileInfo.SecondsToLive +
                                Math.Max((float)_contactEffect.Duration.TotalSeconds, (float)_destinationEffect.Duration.TotalSeconds);
            float maxProjectiles = data.FireRate * maxProjLife * data.ProjectilesPerFire;

            maxProjectiles = Math.Max(maxProjectiles, _projectilesPerFire);
            _projectiles   = new Projectile[(int)maxProjectiles + 1];
            for (int i = 0; i < _projectiles.Length; i++)
            {
                _projectiles[i] = new Projectile(data.ProjectileInfo.SpriteName);
            }
        }
예제 #3
0
 /// <summary>
 /// initialize a new projectile
 /// </summary>
 /// <param name="pos">start position</param>
 /// <param name="direction">fire direction</param>
 /// <param name="data">data to initialize projectile with</param>
 public void Initialize(Vector2 pos, Vector2 direction, ProjectileData data,
                        Vector2 targetDestination, Vector2 sourceVelocity,
                        ProjectileEffect contactEffect, ProjectileEffect destinationEffect,
                        ProjectileEffect proximityEffect)
 {
     _position = pos;
     Vector2.Multiply(ref direction, data.Speed, out _velocity);
     Vector2.Add(ref _velocity, ref sourceVelocity, out _velocity);
     Vector2.Multiply(ref direction, data.Acceleration, out _acceleration);
     _lifeTime = TimeSpan.FromSeconds(data.SecondsToLive);
     _sprite.Reset();
     //_sprite = new Sprite(data.SpriteName);
     _penetration       = data.Penetration;
     _mass              = data.Mass;
     _contactEffect     = contactEffect;
     _proximityEffect   = proximityEffect;
     _destinationEffect = destinationEffect;
     _distanceLeft      = Vector2.Distance(pos, targetDestination);
     _state             = State.Moving;
     _sprite.Angle      = utility.XnaHelper.RadiansFromVector(direction);
     _angularVelocity   = MathHelper.ToRadians(data.Rotation);
 }
예제 #4
0
 /// <summary>
 /// initialize a new projectile
 /// </summary>
 /// <param name="pos">start position</param>
 /// <param name="direction">fire direction</param>
 /// <param name="data">data to initialize projectile with</param>
 public void Initialize(Vector2 pos, Vector2 direction, ProjectileData data,
     Vector2 targetDestination, Vector2 sourceVelocity,
     ProjectileEffect contactEffect, ProjectileEffect destinationEffect,
     ProjectileEffect proximityEffect)
 {
     _position = pos;
     Vector2.Multiply(ref direction, data.Speed, out _velocity);
     Vector2.Add(ref _velocity, ref sourceVelocity, out _velocity);
     Vector2.Multiply(ref direction, data.Acceleration, out _acceleration);
     _lifeTime = TimeSpan.FromSeconds(data.SecondsToLive);
     _sprite.Reset();
     //_sprite = new Sprite(data.SpriteName);
     _penetration = data.Penetration;
     _mass = data.Mass;
     _contactEffect = contactEffect;
     _proximityEffect = proximityEffect;
     _destinationEffect = destinationEffect;
     _distanceLeft = Vector2.Distance(pos, targetDestination);
     _state = State.Moving;
     _sprite.Angle = utility.XnaHelper.RadiansFromVector(direction);
     _angularVelocity = MathHelper.ToRadians(data.Rotation);
 }