public Mine(Texture2D[] inputTexture, SoundEffect inputBlast) { blast = inputBlast; played = false; state = Minestate.Halted; color = Color.White; coreTexture = inputTexture[0]; spikeTexture = inputTexture[1]; explosionTexture = inputTexture[2]; borderTexture = inputTexture[3]; core = new Rectangle(0, 0, 40, 40); spikes = new Rectangle(90, 0, 40, 40); explosion = new Rectangle(0, 0, 125, 125); angle = 0; angleDiff = 0.3F; mineScale = 1; health = 100; // Velocity is randomized within a small range to present more challenge to the player. baseVelocity = 3; velocityMod = 7; velocity = baseVelocity + Helper.Rng((int)velocityMod); minePosition = new Vector2(0 - coreTexture.Width, 0 - coreTexture.Height); rotationOffset = new Vector2(20, 20); // Animation timer. rotation = new Stopwatch(); rotation.Start(); // Respawn timer. halt = new Stopwatch(); // Explosion. explosionTimer = new Stopwatch(); // Shot animation. shotTimer = new Stopwatch(); effects = SpriteEffects.None; if (Game.DEBUG) { velocity = 3; dString1 = dString2 = ""; dPosition1 = dPosition2 = new Vector2(0, 0); } }
private void Traverse() { Animate(); if (Game.DEBUG) { dString1 = "H: " + health + " " + "V: " + velocity; dString2 = "X: " + minePosition.X + " " + "Y: " + minePosition.Y; dPosition1 = new Vector2(minePosition.X + core.Width + 1, minePosition.Y - 13); dPosition2 = new Vector2(minePosition.X + core.Width + 1, minePosition.Y + 2); } // Proximity. distance = Vector2.Distance(minePosition, new Vector2(reference.X + (reference.Width / 2), reference.Y + (reference.Height / 2))); // Traverse left. minePosition.X -= velocity; // Check if it needs to be drawn. if (minePosition.X + core.Width < 0) state = Minestate.Halted; }
private void Shot() { Animate(); if (Game.DEBUG) { dString1 = "H: " + health + " " + "V: " + velocity; dString2 = "X: " + minePosition.X + " " + "Y: " + minePosition.Y; dPosition1 = new Vector2(minePosition.X + core.Width + 1, minePosition.Y - 13); dPosition2 = new Vector2(minePosition.X + core.Width + 1, minePosition.Y + 2); } if (!shotTimer.IsRunning) { shotTimer.Restart(); // Health decreases inverse to speed: Slower mines take less damage. TODO: Tweak. health -= (int)((velocity * (velocity * 0.3F)) * 5); } // Proximity to player. distance = Vector2.Distance(minePosition, new Vector2(reference.X + (reference.Width / 2), reference.Y + (reference.Height / 2))); if (shotTimer.ElapsedMilliseconds > 180) { if (health <= 0) state = Minestate.Explosion; else state = Minestate.Traverse; shotTimer.Stop(); } }
private void Halt() { if (!halt.IsRunning) halt.Restart(); health = 100; minePosition.X = Game.WIDTH + core.Width; minePosition.Y = Helper.Rng(Game.HEIGHT - spikes.Height); // Randomize speed for the next run. if (!Game.DEBUG) velocity = baseVelocity + Helper.Rng((int)velocityMod); if (Game.DEBUG) velocity = 3; haltDuration = Helper.Rng(10000); if (halt.ElapsedMilliseconds > haltDuration) { halt.Stop(); state = Minestate.Traverse; } }
private void Explosion() { float elapsed = explosionTimer.ElapsedMilliseconds * 0.002F; if (!played) { played = true; blast.Play(); } // Keep the explosion centered on the mine's position. explosionPosition.X = minePosition.X - spikes.Width / 3 * explosionScale; explosionPosition.Y = minePosition.Y - spikes.Height / 3 * explosionScale; if (!explosionTimer.IsRunning) explosionTimer.Restart(); explosionScale = elapsed; explosionOpacity = 1 - elapsed; if (explosionTimer.ElapsedMilliseconds >= 500) { explosionTimer.Stop(); state = Minestate.Halted; played = false; } }
public void State(int newState, Vector2 newBulletPosition = default(Vector2)) { if (newState == 1) state = Minestate.Traverse; if (newState == 2) state = Minestate.Halted; if (newState == 3) state = Minestate.Explosion; if (newState == 4) { bulletSnapshot = newBulletPosition; state = Minestate.Shot; } }