/// <summary> /// Applies thrust to the ship in its current direction /// </summary> /// <param name="targetPosition"></param> private void Thrust() { Vector2 shipFacing; ParticleObject[] particleObjects; ParticleObject particleObj; // Calculate the vector towards which the ship is facing shipFacing = new Vector2((float)Math.Sin(Angle), (float)-Math.Cos(Angle)); // Scale down and add to the velocity _velocity += shipFacing / 10; // Stop the ship from traveling too fast if (_velocity.Length() > 25) { _velocity.Normalize(); _velocity *= 25; } // Add some particles for the thrust exhaust. // First retrieve the particles from the game. particleObjects = _game.GetParticleObjects(10); // Loop for each object for (int i = 0; i < particleObjects.Length; i++) { particleObj = particleObjects[i]; particleObj.ResetProperties(Position, _game.Textures["SmokeParticle"]); // Set to the rear of the spaceship particleObj.Position -= shipFacing * SpriteTexture.Width / 2 * ScaleX; switch (GameHelper.RandomNext(3)) { case 0: particleObj.SpriteColor = Color.White; break; case 1: particleObj.SpriteColor = Color.Cyan; break; case 2: particleObj.SpriteColor = Color.Blue; break; } particleObj.Scale = new Vector2(0.25f, 0.25f); particleObj.IsActive = true; particleObj.Intensity = 50; particleObj.IntensityFadeAmount = 3 + GameHelper.RandomNext(1.5f); particleObj.Speed = GameHelper.RandomNext(3.0f); particleObj.Inertia = 0.9f + GameHelper.RandomNext(0.015f); particleObj.Direction += -shipFacing * 5; } }
/// <summary> /// The rock has been damaged so divide it or remove it from the game /// </summary> internal void DamageRock() { RockObject newRock; ParticleObject[] particleObjects; ParticleObject particleObj; // Add some particles for the rock dust. // First retrieve the particles from the game. particleObjects = _game.GetParticleObjects(5); // Loop for each object for (int i = 0; i < particleObjects.Length; i++) { particleObj = particleObjects[i]; particleObj.ResetProperties(Position, _game.Textures["SmokeParticle"]); switch (GameHelper.RandomNext(3)) { case 0: particleObj.SpriteColor = Color.DarkGray; break; case 1: particleObj.SpriteColor = Color.LightGray; break; default: particleObj.SpriteColor = Color.White; break; } particleObj.Scale = new Vector2(0.4f, 0.4f); particleObj.IsActive = true; particleObj.Intensity = 255; particleObj.IntensityFadeAmount = 3 + GameHelper.RandomNext(1.5f); particleObj.Speed = GameHelper.RandomNext(3.0f); particleObj.Inertia = 0.9f + GameHelper.RandomNext(0.015f); } // Is this a generation-zero rock? // This is the smallest we get, so in this case the rock has actually been destroyed. if (_generation == 0) { // Remove the rock from the game _game.GameObjects.Remove(this); } else { // Re-initialize the rock at half its current size InitializeRock(ScaleX * 0.7f); // Decrease the generation value _generation -= 1; // Create another rock alongside this one newRock = new RockObject(_game, SpriteTexture, _generation, ScaleX, _constructorSpeed); // Position the new rock exactly on top of this rock newRock.Position = Position; // Add the new rock to the game _game.GameObjects.Add(newRock); } }