private Particle newParticle(Vector2 pos, float angle, Vector2 sourceVelocity) { Particle particle = new Particle(); particle.Position = pos; float directionAngle = (float)MathHelper.ToRadians((XnaHelper.RandomAngle(angle, _arc))); float speed = applyVariance(_particleSpeed, _speedVariance); particle.Velocity = speed * XnaHelper.VectorFromAngle(directionAngle); particle.Scale = applyVariance(_particleScale, _scaleVariance); particle.Angle = angle; particle.LifeTime = TimeSpan.FromSeconds(applyVariance((float)_particleLife.TotalSeconds, _particleLifeVariance)); if (Reversed) { float secondsAlive = (float)particle.LifeTime.TotalSeconds; //start at the end particle.Position = particle.Position + particle.Velocity * secondsAlive; //comment above and uncomment below for a cool effect (unintentional side effect while working on particles. //not sure why it looks so awesome, but it does) //particle.Position = particle.Position + particle.Velocity * secondsAlive * (1 - _particleDecelerationFactor); //movce in reverse particle.Velocity = Vector2.Negate(particle.Velocity); //start at end scale particle.Scale = _particleScale + _scaleRate * secondsAlive; //start at end rotation particle.Angle = _particleRotationSpeed * secondsAlive; } particle.Velocity += sourceVelocity; return(particle); }
private void shatter() { _lifeState = LifeState.Shattered; for (int row = 0; row < ICE_DIVISIONS; row++) { for (int col = 0; col < ICE_DIVISIONS; col++) { _fragments[row, col].Health = FRAGMENT_HEALTH * _statusEffects.Cryo / MAX_STAT_EFFECT; _fragments[row, col].Position.X = Position.X + (0.5f + _sprite.Width * (float)col / ICE_DIVISIONS); _fragments[row, col].Position.Y = Position.Y + (0.5f + _sprite.Height * (float)row / ICE_DIVISIONS); XnaHelper.RandomizeVector(ref _fragments[row, col].Velocity, -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY, -FRAGMENT_MAX_VELOCITY, FRAGMENT_MAX_VELOCITY); Vector2.Add(ref _fragments[row, col].Velocity, ref _velocity, out _fragments[row, col].Velocity); Vector2.Multiply(ref _fragments[row, col].Velocity, FRAGMENT_VELOCITY_FACTOR, out _fragments[row, col].Velocity); _fragments[row, col].Angle = 0f; _fragments[row, col].AngularVelocity = XnaHelper.RandomAngle(0.0f, FRAGMENT_MAX_ANGULAR_VELOCITY); _fragments[row, col].ScaleFactor = 1f; _fragments[row, col].Active = true; } } }
protected override void UpdateWeapon(GameTime gameTime) { _contactEffect.Update(gameTime); _destinationEffect.Update(gameTime); _proximityEffect.Update(gameTime); int projectilesToSpawn = _firing ? _projectilesPerFire : 0; foreach (Projectile p in _projectiles) { if (p.ProjectileState == Projectile.State.Dormant && projectilesToSpawn > 0) { float rotAngle = XnaHelper.RandomAngle(0, _spread); Matrix.CreateRotationZ(MathHelper.ToRadians(rotAngle), out tempMatrix); p.Initialize(_owner.Position, Vector2.Transform(_fireDirection, tempMatrix), _projectileInfo, _targetDestination, _owner.Velocity, _contactEffect, _destinationEffect, _proximityEffect); projectilesToSpawn--; } p.Update(gameTime); } System.Diagnostics.Debug.Assert(projectilesToSpawn == 0, "did not spawn all projectiles", "Number left: " + projectilesToSpawn, new object[] { this }); if (_fireParticleEffect != null) { if (_firing) { _fireParticleEffect.Spawn( _owner.Position, XnaHelper.DegreesFromVector(_fireDirection), gameTime.ElapsedGameTime, _owner.Velocity); } _fireParticleEffect.Update(gameTime); } }