示例#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), 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
 public Projectile(string spriteName)
 {
     _sprite            = new Sprite(spriteName, graphics.Sprite.SpriteType.Projectile);
     _hitRect           = new Rectangle(0, 0, (int)_sprite.Width, (int)_sprite.Height);
     _contactEffect     = ProjectileEffect.NullEffect;
     _destinationEffect = ProjectileEffect.NullEffect;
     _proximityEffect   = ProjectileEffect.NullEffect;
 }
 public Projectile(string spriteName)
 {
     _sprite = new Sprite(spriteName);
     _hitRect = new Rectangle(0, 0, (int)_sprite.Width, (int)_sprite.Height);
     _contactEffect = ProjectileEffect.NullEffect;
     _destinationEffect = ProjectileEffect.NullEffect;
     _proximityEffect = ProjectileEffect.NullEffect;
 }
 public Obstacle(ObstacleData data)
     : base(data, graphics.Sprite.SpriteType.Obstacle)
 {
     _minSpawnTime = data.MinSpawnTime;
     _maxSpawnTime = data.MaxSpawnTime;
     _respawnTimer = XnaHelper.RandomTime(_minSpawnTime, _maxSpawnTime);
     _destroyEffect = data.DestroyEffect == null ? ProjectileEffect.NullEffect : new ProjectileEffect(data.DestroyEffect);
     _explodeTimer = TimeSpan.Zero;
     _isSpawned = false;
 }
示例#6
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);
 }
 /// <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);
 }