private void FireParticles(GameTime gameTime, ParticleManager <ParticleState> particleManager) { double t = gameTime.TotalGameTime.TotalSeconds; var direction = new Vector2((float)Math.Sin(Ship.Rotation), (float)Math.Cos(Ship.Rotation) * -1); float aimAngle = direction.ToAngle(); Quaternion rot = Quaternion.CreateFromYawPitchRoll(0, 0, aimAngle); // The primary velocity of the particles is 3 pixels/frame in the direction opposite to which the ship is travelling. Vector2 baseVel = direction.ScaleTo(2); // Calculate the sideways velocity for the two side streams. The direction is perpendicular to the ship's velocity and the // magnitude varies sinusoidally. var perpVel = new Vector2(baseVel.Y, -baseVel.X) * (0.6f * (float)Math.Sin(t * 10)); var sideColor = new Color(200, 38, 9); // deep red var midColor = new Color(255, 187, 30); // orange-yellow var pos = Ship.Position; // position of the ship's exhaust pipe. const float alpha = 0.7f; // middle particle stream Vector2 velMid = baseVel + random.NextVector2(0, 1); particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(velMid, ParticleType.Enemy)); particleManager.CreateGlowParticle(pos, midColor * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(velMid, ParticleType.Enemy)); // side particle streams Vector2 vel1 = baseVel + perpVel + random.NextVector2(0, 0.3f); Vector2 vel2 = baseVel - perpVel + random.NextVector2(0, 0.3f); particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(vel1, ParticleType.Enemy)); particleManager.CreateLineParticle(pos, Color.White * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(vel2, ParticleType.Enemy)); particleManager.CreateGlowParticle( pos, sideColor * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(vel1, ParticleType.Enemy) ); particleManager.CreateGlowParticle( pos, sideColor * alpha, 60f, new Vector2(0.5f, 1), new ParticleState(vel2, ParticleType.Enemy) ); }
public void Hit(ParticleManager <ParticleState> particleManager) { _lives--; _deadSound.Play(); var yellow = new Color(0.8f, 0.8f, 0.4f); for (int i = 0; i < 1200; i++) { float speed = 18f * (1f - 1 / random.NextFloat(1f, 10f)); Color color = Color.Lerp(Color.White, yellow, random.NextFloat(0, 1)); var state = new ParticleState() { Velocity = random.NextVector2(speed, speed), Type = ParticleType.None, LengthMultiplier = 1 }; particleManager.CreateLineParticle(Ship.Position, color, 190, 1.5f, state); } _timeBeforeRespawn = Config.PlayerTimeBeforeRespawn; Ship.EnableShield(); }