public void UnmuteSound() { muted = false; mutepos += new Vector2(128, 0); SoundEffect.MasterVolume = (float)selection / 10; Sound.GetSound(1000).Play(); mute = new UIButton(mutepos, 21, MuteSound); }
public void RaiseVolume() { selection = (selection += 1) > 10 ? 0 : selection; SetVolume(); Sound.GetSound(1000).Play(); }
//Raises and lowers the volume public void LowerVolume() { selection = (selection -= 1) < 0 ? 10 : selection; SetVolume(); Sound.GetSound(1000).Play(); }
public override void Update(GameTime gameTime) { //Sets the starting times. double curTime = gameTime.TotalGameTime.TotalSeconds; if (lastSingleShot < 0) { lastSingleShot = gameTime.TotalGameTime.TotalSeconds + 5.0f; lastDoubleShot = gameTime.TotalGameTime.TotalSeconds + 7.0f; lastTripleShot = gameTime.TotalGameTime.TotalSeconds + 10.0f; lastPowerUp = gameTime.TotalGameTime.TotalSeconds + 12.0f; } //Aims at the player. Always. Vector2 playPos = GameRoom.gameRoom.player.GetCenterPosition(); rotation = (float)(Math.Atan2(playPos.Y - position.Y, playPos.X - position.X)); canonMuzzle = new Vector2(position.X + (float)Math.Cos(rotation) * 128.0f, position.Y + (float)Math.Sin(rotation) * 128.0f); //Every triple shot, fire off 3 kinds of enemies. if (lastTripleShot < curTime) { GameRoom.gameRoom.AddActor(new TurnShot(canonMuzzle, (float)(rotation - Math.PI / 8), 64.0f * 8)); GameRoom.gameRoom.AddActor(new AcceleratedShot(canonMuzzle, rotation, 128.0f * 2)); GameRoom.gameRoom.AddActor(new MineShot(canonMuzzle, rotation, 64.0f * 9)); GameRoom.gameRoom.AddActor(new TurnShot(canonMuzzle, (float)(rotation + Math.PI / 8), 64.0f * 8)); lastTripleShot = gameTime.TotalGameTime.TotalSeconds + 5; canonSprite.SetAnimation("idle"); Sound.GetSound(1001).CreateInstance().Play(); //Every double, fire off 2 } else if (lastDoubleShot < curTime) { GameRoom.gameRoom.AddActor(new AcceleratedShot(canonMuzzle, (float)(rotation - Math.PI / 3), 64.0f * 2)); GameRoom.gameRoom.AddActor(new AcceleratedShot(canonMuzzle, (float)(rotation + Math.PI / 3), 64.0f * 2)); GameRoom.gameRoom.AddActor(new MineShot(canonMuzzle, rotation, 64.0f * 7)); lastDoubleShot = gameTime.TotalGameTime.TotalSeconds + 2; canonSprite.SetAnimation("idle"); Sound.GetSound(1001).CreateInstance().Play(); //Every single, fire off one. } else if (lastSingleShot < curTime) { GameRoom.gameRoom.AddActor(new StraightShot(canonMuzzle, rotation, 64.0f * 7)); lastSingleShot = gameTime.TotalGameTime.TotalSeconds + 0.5f; canonSprite.SetAnimation("idle"); Sound.GetSound(1001).CreateInstance().Play(); } //Powerups are a coinflip for now if (lastPowerUp < curTime) { double chance = rand.NextDouble(); if (chance < 0.5) { GameRoom.gameRoom.AddActor(new HealthPowerUpActor(canonMuzzle, rotation, 64.0f * 4)); } else { GameRoom.gameRoom.AddActor(new InvulnPowerUpActor(canonMuzzle, rotation, 64.0f * 4)); } lastPowerUp = curTime + 6.0f; canonSprite.SetAnimation("idle"); Sound.GetSound(1002).CreateInstance().Play(); } float closestShotTime = (float)Math.Min(lastTripleShot, Math.Min(lastSingleShot, lastDoubleShot)); //Plays an animation if (Math.Min(lastTripleShot, Math.Min(lastSingleShot, lastDoubleShot)) - 1.0f / 3.0f < curTime) { canonSprite.SetAnimation("firing"); } }
//Collision detection! public override void LateUpdate(GameTime gameTime) { Vector2 playPos = GetCenterPosition(); foreach (var actor in GameRoom.gameRoom.actors) { Type t = actor.GetType(); //Spend as little time as humanly possible comparing the player to every actor type that exists in the room. if (t.IsSubclassOf(typeof(EnemyActor))) { EnemyActor enem = (EnemyActor)actor; Vector2 enemPos = enem.GetCenterPosition(); float xDist = playPos.X - enemPos.X; float yDist = playPos.Y - enemPos.Y; //Collisions treat both objects as circle. Not the most accurate hit detection but computationally cheap and easier to write. if (Math.Sqrt((xDist * xDist + yDist * yDist)) < 32) { Damage(enem.damage); if (invuln) { enem.OnKilled(); Sound.GetSound(1004).CreateInstance().Play(); } else { enem.OnImpact(); Sound.GetSound(1003).CreateInstance().Play(); } } } else if (t.IsSubclassOf(typeof(PowerupActor))) { PowerupActor pow = (PowerupActor)actor; if (pow.picked) { continue; } Vector2 powPos = pow.GetCenterPosition(); float xDist = playPos.X - powPos.X; float yDist = playPos.Y - powPos.Y; if (Math.Sqrt((xDist * xDist + yDist * yDist)) < 32) { pow.OnPickup(this, gameTime); } } else { continue; } } base.LateUpdate(gameTime); //Out of bounds correction if (playPos.X < -GetBounds().Width / 2) { position = new Vector2(-GetBounds().Width / 2, position.Y); } else if (playPos.X > Game1.mainGame.ViewPort.Width) { position = new Vector2(Game1.mainGame.ViewPort.Width - GetBounds().Width / 2, position.Y); } if (playPos.Y < -GetBounds().Height / 2) { position = new Vector2(position.X, -GetBounds().Height / 2); } else if (playPos.Y > Game1.mainGame.ViewPort.Height) { position = new Vector2(position.X, Game1.mainGame.ViewPort.Height - GetBounds().Height / 2); } }