/// <summary> /// Creates an AudioStream /// </summary> /// <param name="sampleFrequency">Frequency</param> /// <param name="format">format of stream data</param> /// <param name="channels">Mono or Stereo</param> /// <param name="samples">number of samples</param> /// <param name="callback">Method callback to get more data</param> /// <param name="data">data object</param> public AudioStream(int sampleFrequency, AudioFormat format, SoundChannel channels, short samples, AudioCallback callback, object data) { this.samples = samples; this.queue = new Queue<short[]>(5); this.sampleFrequency = sampleFrequency; // To keep compiler happy, we must 'initialize' these values spec.padding = 0; spec.size = 0; spec.silence = 0; spec.freq = sampleFrequency; spec.format = (short)format; spec.channels = (byte)channels; if (callback != null) { spec.callback = Marshal.GetFunctionPointerForDelegate(callback); } spec.samples = samples; spec.userdata = data; if (((ushort)spec.format & 0x8000) != 0x8000) // signed { this.offset = 2 << ((byte)spec.format - 2); //this.offset = 0; } //else //{ // this.offset = 2 << ((byte)spec.format - 2); //} }
public MainMenu(TimeGuardianGame game) { _game = game; SetBackground(); SetHeader(); _buttons = new [] { new Button(UtilStrings.SpritesMenu + "button_newgame.png", 2, game.width/2, 350, "Level1"), new Button(UtilStrings.SpritesMenu + "button_highscore.png", 2, game.width/2, 450, "HighScores"), new Button(UtilStrings.SpritesMenu + "button_credits.png", 2, game.width/2, 550, "Credits"), new Button(UtilStrings.SpritesMenu + "button_exit.png", 2, game.width/2, 650, "Exit") }; foreach (Button button in _buttons) { AddChild(button); } _selectedSound = new Sound(UtilStrings.SoundsMenu + "sound_selected.wav"); _music = new Sound(UtilStrings.SoundsMenu + "music_menu.mp3", true, true); _musicChannel = _music.Play(); _buttons[0].Selected(); }
private void Initialize() { //this.stage.fullScreenSourceRect = new Rectangle //{ // width = DefaultControlWidth, // height = DefaultControlHeight //}; //#region fullscreen support //bool NextFullscreenMode = true; //this.stage.fullScreen += // e => // { // NextFullscreenMode = !e.fullScreen; // // hide chat while fullscreen zoom // //this.GetStageChild().Siblings().ForEach(k => k.visible = !e.fullScreen); // }; //this.contextMenu = new ContextMenuEx //{ // { "Fullscreen", // delegate // { // this.stage.SetFullscreen(NextFullscreenMode); // } // } //}; //#endregion this.music = Assets.Default.Music.music.play(0, 9999, new SoundTransform(0.5)); EgoView = new ViewEngine(DefaultWidth, DefaultHeight) { FloorAndCeilingVisible = false, RenderLowQualityWalls = false, ViewDirection = 0, ViewPosition = new Point(0, 0) }; EgoView.Image.scaleX = DefaultScale; EgoView.Image.scaleY = DefaultScale; EgoView.Image.alpha = 0; EgoView.Image.AttachTo(this); EgoView.ViewPositionChanged += delegate { this.NextViewPosition = EgoView.ViewPosition; }; EgoView.ViewDirectionChanged += delegate { this.NextViewDirection = EgoView.ViewDirection; }; EgoView.FramesPerSecondChanged += delegate { if (EgoView.FramesPerSecond < 14) { if (!EgoView.RenderLowQualityWalls) { EgoView.RenderLowQualityWalls = true; } } if (EgoView.FramesPerSecond > 20) { if (EgoView.RenderLowQualityWalls) { EgoView.RenderLowQualityWalls = false; } } }; this.HudContainer = new Sprite().AttachTo(this); this.HudContainer.alpha = 0; getpsyched = Assets.Default.getpsyched.AttachTo(this); getpsyched.scaleX = 2; getpsyched.scaleY = 2; getpsyched.MoveTo((DefaultControlWidth - getpsyched.width) / 2, (DefaultControlHeight - getpsyched.height) / 2); getpsyched.alpha = 0; InitializeWriteLine(); this.WriteLine("init: getpsyched"); //WriteLine("with minimap"); getpsyched.FadeIn( delegate { Assets.Default.Sounds.gutentag.play(); this.WriteLine("init: gutentag"); var TryLoad = default(Action); TryLoad = delegate { Assets.Default.dude5.ToBitmapArray( CachedGuardTextures, Bitmaps => { TryLoad = null; LoadGuardTextures(Bitmaps); } ); }; 10000.AtDelayDo( delegate { if (TryLoad != null) { TryLoad(); } } ); TryLoad(); } ); }
partial void InitProjSpecific() { Sprite?.EnsureLazyLoaded(); SpecularSprite?.EnsureLazyLoaded(); Prefab.DeformableSprite?.EnsureLazyLoaded(); CurrentSwingAmount = Prefab.SwingAmountRad; CurrentScaleOscillation = Prefab.ScaleOscillation; SwingTimer = Rand.Range(0.0f, MathHelper.TwoPi); ScaleOscillateTimer = Rand.Range(0.0f, MathHelper.TwoPi); if (Prefab.ParticleEmitterPrefabs != null) { ParticleEmitters = new ParticleEmitter[Prefab.ParticleEmitterPrefabs.Count]; ParticleEmitterTriggers = new LevelTrigger[Prefab.ParticleEmitterPrefabs.Count]; for (int i = 0; i < Prefab.ParticleEmitterPrefabs.Count; i++) { ParticleEmitters[i] = new ParticleEmitter(Prefab.ParticleEmitterPrefabs[i]); ParticleEmitterTriggers[i] = Prefab.ParticleEmitterTriggerIndex[i] > -1 ? Triggers[Prefab.ParticleEmitterTriggerIndex[i]] : null; } } if (Prefab.LightSourceParams != null) { LightSources = new LightSource[Prefab.LightSourceParams.Count]; LightSourceTriggers = new LevelTrigger[Prefab.LightSourceParams.Count]; for (int i = 0; i < Prefab.LightSourceParams.Count; i++) { LightSources[i] = new LightSource(Prefab.LightSourceParams[i]) { Position = new Vector2(Position.X, Position.Y), IsBackground = true }; LightSourceTriggers[i] = Prefab.LightSourceTriggerIndex[i] > -1 ? Triggers[Prefab.LightSourceTriggerIndex[i]] : null; } } Sounds = new RoundSound[Prefab.Sounds.Count]; SoundChannels = new SoundChannel[Prefab.Sounds.Count]; SoundTriggers = new LevelTrigger[Prefab.Sounds.Count]; for (int i = 0; i < Prefab.Sounds.Count; i++) { Sounds[i] = Submarine.LoadRoundSound(Prefab.Sounds[i].SoundElement, false); SoundTriggers[i] = Prefab.Sounds[i].TriggerIndex > -1 ? Triggers[Prefab.Sounds[i].TriggerIndex] : null; } int j = 0; foreach (XElement subElement in Prefab.Config.Elements()) { if (subElement.Name.ToString().ToLowerInvariant() != "deformablesprite") { continue; } foreach (XElement animationElement in subElement.Elements()) { var newDeformation = SpriteDeformation.Load(animationElement, Prefab.Name); if (newDeformation != null) { newDeformation.DeformationParams = Prefab.SpriteDeformations[j].DeformationParams; spriteDeformations.Add(newDeformation); j++; } } } }
public void PlaySound(ActionType type, Vector2 position, Character user = null) { if (!hasSoundsOfType[(int)type]) { return; } if (loopingSound != null) { float targetGain = 0.0f; if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(position.X, position.Y, 0.0f)) > loopingSound.Range * loopingSound.Range || (targetGain = GetSoundVolume(loopingSound)) <= 0.0001f) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(position.X, position.Y, 0.0f), 0.01f, SoundPlayer.ShouldMuffleSound(Character.Controlled, position, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } if (loopingSoundChannel != null) { if (Timing.TotalTime > lastMuffleCheckTime + 0.2f) { shouldMuffleLooping = SoundPlayer.ShouldMuffleSound(Character.Controlled, position, loopingSound.Range, Character.Controlled?.CurrentHull); lastMuffleCheckTime = (float)Timing.TotalTime; } loopingSoundChannel.Muffled = shouldMuffleLooping; float gainDiff = targetGain - loopingSoundChannel.Gain; loopingSoundChannel.Gain += Math.Abs(gainDiff) < 0.1f ? gainDiff : Math.Sign(gainDiff) * 0.1f; loopingSoundChannel.Position = new Vector3(position.X, position.Y, 0.0f); } return; } ItemSound itemSound = null; var matchingSounds = sounds[type]; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, position, user); } return; } else { index = Rand.Int(matchingSounds.Count); } itemSound = matchingSounds[index]; PlaySound(matchingSounds[index], position, user); } }
public static Sound RegisterCustomSound(string id, AudioClip audio, SoundChannel soundChannel = SoundChannel.Master) { return(Main.RegisterCustomSound(id, audio, soundChannel)); }
void ICustomSoundHandler.RegisterCustomSound(string id, Sound sound, SoundChannel soundChannel) { CustomSoundPatcher.CustomSounds[id] = sound; CustomSoundPatcher.CustomSoundChannels[id] = soundChannel; }
partial void UpdateProjSpecific(float deltaTime) { recoilTimer -= deltaTime; if (crosshairSprite != null) { Vector2 itemPos = cam.WorldToScreen(new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y)); Vector2 turretDir = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); Vector2 mouseDiff = itemPos - PlayerInput.MousePosition; crosshairPos = new Vector2( MathHelper.Clamp(itemPos.X + turretDir.X * mouseDiff.Length(), 0, GameMain.GraphicsWidth), MathHelper.Clamp(itemPos.Y + turretDir.Y * mouseDiff.Length(), 0, GameMain.GraphicsHeight)); } crosshairPointerPos = PlayerInput.MousePosition; if (Math.Abs(angularVelocity) > 0.1f) { if (moveSoundChannel == null && startMoveSound != null) { moveSoundChannel = SoundPlayer.PlaySound(startMoveSound.Sound, startMoveSound.Volume, startMoveSound.Range, item.WorldPosition); } else if (moveSoundChannel == null || !moveSoundChannel.IsPlaying) { if (moveSound != null) { moveSoundChannel.Dispose(); moveSoundChannel = SoundPlayer.PlaySound(moveSound.Sound, moveSound.Volume, moveSound.Range, item.WorldPosition); if (moveSoundChannel != null) { moveSoundChannel.Looping = true; } } } } else if (Math.Abs(angularVelocity) < 0.05f) { if (moveSoundChannel != null) { if (endMoveSound != null && moveSoundChannel.Sound != endMoveSound.Sound) { moveSoundChannel.Dispose(); moveSoundChannel = SoundPlayer.PlaySound(endMoveSound.Sound, endMoveSound.Volume, endMoveSound.Range, item.WorldPosition); if (moveSoundChannel != null) { moveSoundChannel.Looping = false; } } else if (!moveSoundChannel.IsPlaying) { moveSoundChannel.Dispose(); moveSoundChannel = null; } } } if (moveSoundChannel != null && moveSoundChannel.IsPlaying) { moveSoundChannel.Gain = MathHelper.Clamp(Math.Abs(angularVelocity), 0.5f, 1.0f); } if (flashLowPower || flashNoAmmo) { flashTimer += deltaTime; if (flashTimer >= flashLength) { flashTimer = 0; flashLowPower = false; flashNoAmmo = false; } } }
partial void UpdateProjSpecific(float deltaTime) { recoilTimer -= deltaTime; if (crosshairSprite != null) { Vector2 itemPos = cam.WorldToScreen(new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y)); Vector2 turretDir = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); Vector2 mouseDiff = itemPos - PlayerInput.MousePosition; crosshairPos = new Vector2( MathHelper.Clamp(itemPos.X + turretDir.X * mouseDiff.Length(), 0, GameMain.GraphicsWidth), MathHelper.Clamp(itemPos.Y + turretDir.Y * mouseDiff.Length(), 0, GameMain.GraphicsHeight)); } crosshairPointerPos = PlayerInput.MousePosition; if (Math.Abs(angularVelocity) > 0.1f) { if (moveSoundChannel == null && startMoveSound != null) { moveSoundChannel = SoundPlayer.PlaySound(startMoveSound.Sound, item.WorldPosition, startMoveSound.Volume, startMoveSound.Range, ignoreMuffling: startMoveSound.IgnoreMuffling); } else if (moveSoundChannel == null || !moveSoundChannel.IsPlaying) { if (moveSound != null) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(moveSound.Sound, item.WorldPosition, moveSound.Volume, moveSound.Range, ignoreMuffling: moveSound.IgnoreMuffling); if (moveSoundChannel != null) { moveSoundChannel.Looping = true; } } } } else if (Math.Abs(angularVelocity) < 0.05f) { if (moveSoundChannel != null) { if (endMoveSound != null && moveSoundChannel.Sound != endMoveSound.Sound) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(endMoveSound.Sound, item.WorldPosition, endMoveSound.Volume, endMoveSound.Range, ignoreMuffling: endMoveSound.IgnoreMuffling); if (moveSoundChannel != null) { moveSoundChannel.Looping = false; } } else if (!moveSoundChannel.IsPlaying) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = null; } } } float chargeRatio = currentChargeTime / MaxChargeTime; currentBarrelSpin = (currentBarrelSpin + MaxCircle * chargeRatio * deltaTime * 3f) % MaxCircle; switch (currentChargingState) { case ChargingState.WindingUp: Vector2 particlePos = GetRelativeFiringPosition(); float sizeMultiplier = Math.Clamp(chargeRatio, 0.1f, 1f); foreach (ParticleEmitter emitter in particleEmitterCharges) { // color is currently not connected to ammo type, should be updated when ammo is changed emitter.Emit(deltaTime, particlePos, hullGuess: null, angle: -rotation, particleRotation: rotation, sizeMultiplier: sizeMultiplier, colorMultiplier: emitter.Prefab.Properties.ColorMultiplier); } if (chargeSoundChannel == null || !chargeSoundChannel.IsPlaying) { if (chargeSound != null) { chargeSoundChannel = SoundPlayer.PlaySound(chargeSound.Sound, item.WorldPosition, chargeSound.Volume, chargeSound.Range, ignoreMuffling: chargeSound.IgnoreMuffling); if (chargeSoundChannel != null) { chargeSoundChannel.Looping = true; } } } else if (chargeSoundChannel != null) { chargeSoundChannel.FrequencyMultiplier = MathHelper.Lerp(0.5f, 1.5f, chargeRatio); } break; default: if (chargeSoundChannel != null) { if (chargeSoundChannel.IsPlaying) { chargeSoundChannel.FadeOutAndDispose(); chargeSoundChannel.Looping = false; } else { chargeSoundChannel = null; } } break; } if (moveSoundChannel != null && moveSoundChannel.IsPlaying) { moveSoundChannel.Gain = MathHelper.Clamp(Math.Abs(angularVelocity), 0.5f, 1.0f); } if (flashLowPower || flashNoAmmo || flashLoaderBroken) { flashTimer += deltaTime; if (flashTimer >= flashLength) { flashTimer = 0; flashLowPower = false; flashNoAmmo = false; flashLoaderBroken = false; } } }
void Update() { if (CheckMouseInRectClick(play) && !isPlaying && option.visible == false) { if (!hasStarted) { level = new Level(this, option); musicChannel = music.Play(); hasStarted = true; } if (option.isSoundPlaying) { click.Play(); } AddChild(level); isPlaying = true; } if (CheckMouseInRectClick(easterEgg) && !hasStarted && !inEasterEgg) { musicChannel = change.Play(); AddChild(changedaworld); inEasterEgg = true; } if (musicChannel != null) { if (!option.isMusicPlaying) { musicChannel.Volume = 0f; } if (option.isMusicPlaying) { musicChannel.Volume = 1f; } } if (inEasterEgg) { timer -= Time.deltaTime; if (timer <= 0) { changedaworld.alpha -= 0.005f; } if (changedaworld.alpha <= 0f) { RemoveChild(changedaworld); } } if (CheckMouseInRectClick(options) && !isPlaying && option.visible == false) { option.visible = true; if (option.isSoundPlaying) { click.Play(); } } if (CheckMouseInRectClick(exit) && !isPlaying && option.visible == false) { if (option.isSoundPlaying) { click.Play(); } Environment.Exit(0); } }
public static void remove_soundComplete(SoundChannel that, Action <Event> value) { CommonExtensions.RemoveDelegate(that, value, Event.SOUND_COMPLETE); }
public Menu(int numberOfLevel, float pSoundVolume) : base() { BATOOT = new Sprite("BATOOT.png"); soundVolume = pSoundVolume; _cursorIMG = new Sprite("HUD/cursor_PNG50.png"); backgroundMusic = new Sound("music_for_menu.mp3", true, true); soundChannel = backgroundMusic.Play(); _numberOfLevel = numberOfLevel; _clickSound = new Sound("1.mp3"); _fon = new Sprite("fon.png"); _startButton = new Sprite("HUD/main_menu/start/1_start_deactiv.png"); _startButton.SetOrigin(_startButton.width / 2f, _startButton.height / 2f); _startButton.SetXY(game.width / 2f, 300); _startButtonActive = new Sprite("HUD/main_menu/start/1_start_active.png"); _startButtonActive.SetOrigin(_startButtonActive.width / 2f, _startButtonActive.height / 2f); _startButtonActive.SetXY(game.width / 2f - 10000, 300 - 10000); _optionsButton = new Sprite("HUD/main_menu/options/2_options_deactiv.png"); _optionsButton.SetOrigin(_optionsButton.width / 2f, _optionsButton.height / 2f); _optionsButton.SetXY(game.width / 2f, 500); _optionsButtonActive = new Sprite("HUD/main_menu/options/2_options_active.png"); _optionsButtonActive.SetOrigin(_optionsButtonActive.width / 2f, _optionsButtonActive.height / 2f); _optionsButtonActive.SetXY(game.width / 2f, 500 - 10000); _exitButton = new Sprite("HUD/main_menu/exit/3_exit_deactiv.png"); _exitButton.SetOrigin(_exitButton.width / 2f, _exitButton.height / 2f); _exitButton.SetXY(game.width / 2f, 700); _exitButtonActive = new Sprite("HUD/main_menu/exit/3_exit_active.png"); _exitButtonActive.SetOrigin(_exitButtonActive.width / 2f, _exitButtonActive.height / 2f); _exitButtonActive.SetXY(game.width / 2f, 700 - 10000); _minusButton = new Sprite("HUD/main_menu/options/minus.png"); _minusButton.SetOrigin(_minusButton.width / 2f, _minusButton.height / 2f); _minusButton.SetXY(game.width / 2f - 200 + 10000, game.height / 2f + 100); _minusButtonActive = new Sprite("HUD/main_menu/options/minus_active.png"); _minusButtonActive.SetOrigin(_minusButtonActive.width / 2f, _minusButtonActive.height / 2f); _minusButtonActive.SetXY(game.width / 2f - 200 + 10000, game.height / 2f + 100); _plusButton = new Sprite("HUD/main_menu/options/plus.png"); _plusButton.SetOrigin(_plusButton.width / 2f, _plusButton.height / 2f); _plusButton.SetXY(game.width / 2f + 200 + 10000, game.height / 2f + 100); _plusButtonActive = new Sprite("HUD/main_menu/options/plus_active.png"); _plusButtonActive.SetOrigin(_plusButtonActive.width / 2f, _plusButtonActive.height / 2f); _plusButtonActive.SetXY(game.width / 2f + 200 + 10000, game.height / 2f + 100); _goBackButton = new Sprite("HUD/main_menu/options/go_back.png"); _goBackButton.SetOrigin(_goBackButton.width / 2f, _goBackButton.height / 2f); _goBackButton.SetXY(game.width / 2f + 10000, game.height / 2f + 300); _goBackButtonActive = new Sprite("HUD/main_menu/options/go_back_active.png"); _goBackButtonActive.SetOrigin(_goBackButtonActive.width / 2f, _goBackButtonActive.height / 2f); _goBackButtonActive.SetXY(game.width / 2f + 10000, game.height / 2f + 300); _aKakButton = new Sprite("question_mark_PNG52.png"); _aKakButton.SetOrigin(_aKakButton.width / 2f, _aKakButton.height / 2f); _aKakButton.SetXY(1830, 60); _obratnoButton = new Sprite("HUD/main_menu/options/go_back.png"); _obratnoButton.SetOrigin(_obratnoButton.width / 2f, _obratnoButton.height / 2f); _obratnoButton.SetXY(game.width / 2f + 10000, game.height / 2f + 300); _obratnoButtonActive = new Sprite("HUD/main_menu/options/go_back_active.png"); _obratnoButtonActive.SetOrigin(_obratnoButtonActive.width / 2f, _obratnoButtonActive.height / 2f); _obratnoButtonActive.SetXY(game.width / 2f + 10000, game.height / 2f + 300); _tutor = new TextBoard(600, 400); _tutor.x += -10000; _tutor.y += game.height / 2f - 250; _sVolume = new TextBoard(220, 200); _sVolume.x += -10000; _sVolume.y += game.height / 2f - 150; BATOOT.SetOrigin(BATOOT.width / 2, BATOOT.height / 2); BATOOT.SetXY(game.width / 2, 90); AddChild(_fon); AddChild(_aKakButton); AddChild(_obratnoButton); AddChild(BATOOT); AddChild(_tutor); AddChild(_sVolume); AddChild(_startButton); AddChild(_startButtonActive); AddChild(_optionsButton); AddChild(_optionsButtonActive); AddChild(_exitButton); AddChild(_exitButtonActive); AddChild(_goBackButton); AddChild(_minusButton); AddChild(_minusButtonActive); AddChild(_plusButton); AddChild(_plusButtonActive); AddChild(_goBackButtonActive); AddChild(_obratnoButtonActive); AddChild(_cursorIMG); }
public static void PlayMusic(Sound sound) { musicSoundChannel = sound.Play(); musicSoundChannel.Volume = _musicVolume; }
partial void ApplyProjSpecific(float deltaTime, Entity entity, List <ISerializableEntity> targets, Hull hull) { if (entity == null) { return; } if (sounds.Count > 0) { if (soundChannel == null || !soundChannel.IsPlaying) { if (soundSelectionMode == SoundSelectionMode.All) { foreach (RoundSound sound in sounds) { soundChannel = SoundPlayer.PlaySound(sound.Sound, entity.WorldPosition, sound.Volume, sound.Range, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } else { int selectedSoundIndex = 0; if (soundSelectionMode == SoundSelectionMode.ItemSpecific && entity is Item item) { selectedSoundIndex = item.ID % sounds.Count; } else if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && entity is Character user) { selectedSoundIndex = user.ID % sounds.Count; } else { selectedSoundIndex = Rand.Int(sounds.Count); } var selectedSound = sounds[selectedSoundIndex]; soundChannel = SoundPlayer.PlaySound(selectedSound.Sound, entity.WorldPosition, selectedSound.Volume, selectedSound.Range, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } if (soundChannel != null && soundChannel.Looping) { ActiveLoopingSounds.Add(this); soundEmitter = entity; loopStartTime = Timing.TotalTime; } } foreach (ParticleEmitter emitter in particleEmitters) { float angle = 0.0f; if (emitter.Prefab.CopyEntityAngle) { if (entity is Item item && item.body != null) { angle = item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi); } } emitter.Emit(deltaTime, entity.WorldPosition, hull, angle); } }
public void PlaySoundOnCollision() { _soundChannel = _powerUpSound.Play(); _soundChannel.Volume = 1f; }
public static void PlaySound(Sound sound) { sfxSoundChannel = sound.Play(); sfxSoundChannel.Volume = _sfxVolume; }
/// <summary> /// Re-opens the sound-system. You do not have to call this method /// in order to start using the Mixer object. /// </summary> /// <param name="frequency">The frequency to mix at</param> /// <param name="format">The audio format to use</param> /// <param name="soundChannels"> /// Number of sound channels in output. /// Set to SoundChannel.Stereo for stereo, SoundChannel.Mono for mono. /// This has nothing to do with mixing channels. /// </param> /// <param name="chunkSize">The chunk size for samples</param> public static void Open(int frequency, AudioFormat format, SoundChannel soundChannels, int chunkSize) { Close(); PrivateOpen(frequency, format, soundChannels, chunkSize); }
public void PlaySound(ActionType type, Character user = null) { if (!hasSoundsOfType[(int)type]) { return; } if (loopingSound != null) { if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(item.WorldPosition, 0.0f)) > loopingSound.Range * loopingSound.Range || (GetSoundVolume(loopingSound)) <= 0.0001f) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(item.WorldPosition, 0.0f), 0.01f, SoundPlayer.ShouldMuffleSound(Character.Controlled, item.WorldPosition, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } return; } var matchingSounds = sounds[type]; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, item.WorldPosition); } return; } else { index = Rand.Int(matchingSounds.Count); } PlaySound(matchingSounds[index], item.WorldPosition); } }
/// <summary> /// Plays a <see cref="Sound"/> globally from a path. Must be a .wav file. Has overload for controlling volume /// </summary> /// <param name="path">The path of the sound. Relative to the base game folder.</param> /// <param name="mode"></param> /// <param name="volumeControl">Which volume control to adjust sound levels by. How loud sound is.</param> /// <returns>The channel on which the sound was created</returns> public static Channel PlaySound(string path, SoundChannel volumeControl, MODE mode = MODE.DEFAULT) { return(PlaySound(CreateSound(path, mode), volumeControl)); }
void OnChannelPlayEnd(SoundChannel channel) { soundChannels.Remove(channel.Key); pool_channels.RecycleObject(channel.gameObject); }
public void PlaySound(ActionType type, Character user = null) { if (!hasSoundsOfType[(int)type]) { return; } if (GameMain.Client?.MidRoundSyncing ?? false) { return; } if (loopingSound != null) { if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(item.WorldPosition, 0.0f)) > loopingSound.Range * loopingSound.Range || (GetSoundVolume(loopingSound)) <= 0.0001f) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(item.WorldPosition, 0.0f), 0.01f, loopingSound.RoundSound.GetRandomFrequencyMultiplier(), SoundPlayer.ShouldMuffleSound(Character.Controlled, item.WorldPosition, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } // Looping sound with manual selection mode should be changed if value of ManuallySelectedSound has changed // Otherwise the sound won't change until the sound condition (such as being active) is disabled and re-enabled if (loopingSoundChannel != null && loopingSoundChannel.IsPlaying && soundSelectionModes[type] == SoundSelectionMode.Manual) { var playingIndex = sounds[type].IndexOf(loopingSound); var shouldBePlayingIndex = Math.Clamp(ManuallySelectedSound, 0, sounds[type].Count); if (playingIndex != shouldBePlayingIndex) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } } return; } var matchingSounds = sounds[type]; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, item.WorldPosition); } return; } else if (soundSelectionMode == SoundSelectionMode.Manual) { index = Math.Clamp(ManuallySelectedSound, 0, matchingSounds.Count); } else { index = Rand.Int(matchingSounds.Count); } PlaySound(matchingSounds[index], item.WorldPosition); } }
public static Sound RegisterCustomSound(string id, string filePath, SoundChannel soundChannel = SoundChannel.Master) { return(Main.RegisterCustomSound(id, filePath, soundChannel)); }
public void GotHit() { _playerHitChannel = _playerHitSound.Play(); _playerHitChannel.Volume = 1f; }
public static void RegisterCustomSound(string id, Sound sound, SoundChannel soundChannel = SoundChannel.Master) { Main.RegisterCustomSound(id, sound, soundChannel); }
/// <summary> /// Creates an AudioStream /// </summary> /// <param name="sampleFrequency">Frequency</param> /// <param name="format">format of stream data</param> /// <param name="channels">Mono or Stereo</param> /// <param name="samples">number of samples</param> public AudioStream(int sampleFrequency, AudioFormat format, SoundChannel channels, short samples) : this(sampleFrequency, format, channels, samples, null, null) { if (format != AudioFormat.Unsigned16Little) { throw new AudioException(Events.StringManager.GetString("SupportedAudioFormats")); } callback = new AudioCallback(Unsigned16LittleStream); spec.callback = Marshal.GetFunctionPointerForDelegate(callback); }
public float GetVolume(SoundChannel channel) { return(_sliders[channel].value); }
/** * Get the volume of a channel. */ public static float GetVolume(SoundChannel channel) { TryCreate(); return(I.channelVolumes[( int )channel]); }
partial void ApplyProjSpecific(float deltaTime, Entity entity, List <ISerializableEntity> targets, Hull hull, Vector2 worldPosition) { if (entity == null) { return; } if (sounds.Count > 0) { if (soundChannel == null || !soundChannel.IsPlaying) { if (soundSelectionMode == SoundSelectionMode.All) { foreach (RoundSound sound in sounds) { if (sound?.Sound == null) { string errorMsg = $"Error in StatusEffect.ApplyProjSpecific1 (sound \"{sound.Filename ?? "unknown"}\" was null)\n" + Environment.StackTrace; GameAnalyticsManager.AddErrorEventOnce("StatusEffect.ApplyProjSpecific:SoundNull1" + Environment.StackTrace, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return; } soundChannel = SoundPlayer.PlaySound(sound.Sound, worldPosition, sound.Volume, sound.Range, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } else { int selectedSoundIndex = 0; if (soundSelectionMode == SoundSelectionMode.ItemSpecific && entity is Item item) { selectedSoundIndex = item.ID % sounds.Count; } else if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && entity is Character user) { selectedSoundIndex = user.ID % sounds.Count; } else { selectedSoundIndex = Rand.Int(sounds.Count); } var selectedSound = sounds[selectedSoundIndex]; if (selectedSound?.Sound == null) { string errorMsg = $"Error in StatusEffect.ApplyProjSpecific2 (sound \"{selectedSound.Filename ?? "unknown"}\" was null)\n" + Environment.StackTrace; GameAnalyticsManager.AddErrorEventOnce("StatusEffect.ApplyProjSpecific:SoundNull2" + Environment.StackTrace, GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return; } soundChannel = SoundPlayer.PlaySound(selectedSound.Sound, worldPosition, selectedSound.Volume, selectedSound.Range, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } if (soundChannel != null && soundChannel.Looping) { ActiveLoopingSounds.Add(this); soundEmitter = entity; loopStartTime = Timing.TotalTime; } } foreach (ParticleEmitter emitter in particleEmitters) { float angle = 0.0f; if (emitter.Prefab.CopyEntityAngle) { if (entity is Item item && item.body != null) { angle = item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi); } } emitter.Emit(deltaTime, worldPosition, hull, angle); } }
/** * Set the volume of a channel. */ public static void SetVolume(SoundChannel channel, float volume) { TryCreate(); I.channelVolumes[( int )channel] = volume; }
partial void ApplyProjSpecific(float deltaTime, Entity entity, IEnumerable <ISerializableEntity> targets, Hull hull, Vector2 worldPosition, bool playSound) { if (entity == null) { return; } if (sounds.Count > 0 && playSound) { if (soundChannel == null || !soundChannel.IsPlaying) { if (soundSelectionMode == SoundSelectionMode.All) { foreach (RoundSound sound in sounds) { if (sound?.Sound == null) { string errorMsg = $"Error in StatusEffect.ApplyProjSpecific1 (sound \"{sound?.Filename ?? "unknown"}\" was null)\n" + Environment.StackTrace.CleanupStackTrace(); GameAnalyticsManager.AddErrorEventOnce("StatusEffect.ApplyProjSpecific:SoundNull1" + Environment.StackTrace.CleanupStackTrace(), GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return; } soundChannel = SoundPlayer.PlaySound(sound.Sound, worldPosition, sound.Volume, sound.Range, hullGuess: hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } else { int selectedSoundIndex; if (soundSelectionMode == SoundSelectionMode.ItemSpecific && entity is Item item) { selectedSoundIndex = item.ID % sounds.Count; } else if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && entity is Character user) { selectedSoundIndex = user.ID % sounds.Count; } else { selectedSoundIndex = Rand.Int(sounds.Count); } var selectedSound = sounds[selectedSoundIndex]; if (selectedSound?.Sound == null) { string errorMsg = $"Error in StatusEffect.ApplyProjSpecific2 (sound \"{selectedSound?.Filename ?? "unknown"}\" was null)\n" + Environment.StackTrace.CleanupStackTrace(); GameAnalyticsManager.AddErrorEventOnce("StatusEffect.ApplyProjSpecific:SoundNull2" + Environment.StackTrace.CleanupStackTrace(), GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg); return; } if (selectedSound.Sound.Disposed) { Submarine.ReloadRoundSound(selectedSound); } soundChannel = SoundPlayer.PlaySound(selectedSound.Sound, worldPosition, selectedSound.Volume, selectedSound.Range, hullGuess: hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } else { soundChannel.Position = new Vector3(worldPosition, 0.0f); } if (soundChannel != null && soundChannel.Looping) { ActiveLoopingSounds.Add(this); soundEmitter = entity; loopStartTime = Timing.TotalTime; } } foreach (ParticleEmitter emitter in particleEmitters) { float angle = 0.0f; float particleRotation = 0.0f; if (emitter.Prefab.CopyEntityAngle) { Limb targetLimb = null; if (entity is Item item && item.body != null) { angle = item.body.Rotation + ((item.body.Dir > 0.0f) ? 0.0f : MathHelper.Pi); particleRotation = -item.body.Rotation; if (item.body.Dir < 0.0f) { particleRotation += MathHelper.Pi; } } else if (entity is Character c && targetLimbs?.FirstOrDefault(l => l != LimbType.None) is LimbType l) { targetLimb = c.AnimController.GetLimb(l); }
protected void Apply(float deltaTime, Entity entity, List <ISerializableEntity> targets) { Hull hull = null; if (entity is Character) { hull = ((Character)entity).AnimController.CurrentHull; } else if (entity is Item) { hull = ((Item)entity).CurrentHull; } #if CLIENT if (entity != null && sounds.Count > 0) { if (soundChannel == null || !soundChannel.IsPlaying) { if (soundSelectionMode == SoundSelectionMode.All) { foreach (RoundSound sound in sounds) { soundChannel = SoundPlayer.PlaySound(sound.Sound, sound.Volume, sound.Range, entity.WorldPosition, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } else { int selectedSoundIndex = 0; if (soundSelectionMode == SoundSelectionMode.ItemSpecific && entity is Item item) { selectedSoundIndex = item.ID % sounds.Count; } else if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && entity is Character user) { selectedSoundIndex = user.ID % sounds.Count; } else { selectedSoundIndex = Rand.Int(sounds.Count); } var selectedSound = sounds[selectedSoundIndex]; soundChannel = SoundPlayer.PlaySound(selectedSound.Sound, selectedSound.Volume, selectedSound.Range, entity.WorldPosition, hull); if (soundChannel != null) { soundChannel.Looping = loopSound; } } } } #endif foreach (ISerializableEntity serializableEntity in targets) { Item item = serializableEntity as Item; if (item == null) { continue; } Character targetCharacter = targets.FirstOrDefault(t => t is Character character && !character.Removed) as Character; if (targetCharacter == null) { foreach (var target in targets) { if (target is Limb limb && limb.character != null && !limb.character.Removed) { targetCharacter = ((Limb)target).character; } } } for (int i = 0; i < useItemCount; i++) { if (item.Removed) { continue; } item.Use(deltaTime, targetCharacter, targets.FirstOrDefault(t => t is Limb) as Limb); } } if (removeItem) { foreach (Item item in targets.Where(t => t is Item).Cast <Item>()) { Entity.Spawner?.AddToRemoveQueue(item); } } if (duration > 0.0f) { DurationListElement element = new DurationListElement { Parent = this, Timer = duration, Entity = entity, Targets = targets }; DurationList.Add(element); } else { foreach (ISerializableEntity target in targets) { if (target is Entity targetEntity) { if (targetEntity.Removed) { continue; } } for (int i = 0; i < propertyNames.Length; i++) { if (target == null || target.SerializableProperties == null || !target.SerializableProperties.TryGetValue(propertyNames[i], out SerializableProperty property)) { continue; } ApplyToProperty(target, property, propertyEffects[i], deltaTime); } } } if (explosion != null && entity != null) { explosion.Explode(entity.WorldPosition, entity); } foreach (ISerializableEntity target in targets) { foreach (Affliction affliction in Afflictions) { Affliction multipliedAffliction = affliction; if (!disableDeltaTime) { multipliedAffliction = affliction.CreateMultiplied(deltaTime); } if (target is Character character) { character.LastDamageSource = entity; foreach (Limb limb in character.AnimController.Limbs) { limb.character.DamageLimb(entity.WorldPosition, limb, new List <Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attackImpulse: 0.0f); //only apply non-limb-specific afflictions to the first limb if (!affliction.Prefab.LimbSpecific) { break; } } } else if (target is Limb limb) { limb.character.DamageLimb(entity.WorldPosition, limb, new List <Affliction>() { multipliedAffliction }, stun: 0.0f, playSound: false, attackImpulse: 0.0f); } } foreach (Pair <string, float> reduceAffliction in ReduceAffliction) { float reduceAmount = disableDeltaTime ? reduceAffliction.Second : reduceAffliction.Second * deltaTime; if (target is Character character) { character.CharacterHealth.ReduceAffliction(null, reduceAffliction.First, reduceAmount); } else if (target is Limb limb) { limb.character.CharacterHealth.ReduceAffliction(limb, reduceAffliction.First, reduceAmount); } } } if (FireSize > 0.0f && entity != null) { var fire = new FireSource(entity.WorldPosition, hull); fire.Size = new Vector2(FireSize, fire.Size.Y); } bool isNotClient = true; #if CLIENT isNotClient = GameMain.Client == null; #endif if (isNotClient && entity != null && Entity.Spawner != null) //clients are not allowed to spawn items { foreach (ItemSpawnInfo itemSpawnInfo in spawnItems) { switch (itemSpawnInfo.SpawnPosition) { case ItemSpawnInfo.SpawnPositionType.This: Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, entity.WorldPosition); break; case ItemSpawnInfo.SpawnPositionType.ThisInventory: { if (entity is Character character) { if (character.Inventory != null && character.Inventory.Items.Any(it => it == null)) { Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, character.Inventory); } } else if (entity is Item item) { var inventory = item?.GetComponent <ItemContainer>()?.Inventory; if (inventory != null && inventory.Items.Any(it => it == null)) { Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, inventory); } } } break; case ItemSpawnInfo.SpawnPositionType.ContainedInventory: { Inventory thisInventory = null; if (entity is Character character) { thisInventory = character.Inventory; } else if (entity is Item item) { thisInventory = item?.GetComponent <ItemContainer>()?.Inventory; } if (thisInventory != null) { foreach (Item item in thisInventory.Items) { if (item == null) { continue; } Inventory containedInventory = item.GetComponent <ItemContainer>()?.Inventory; if (containedInventory == null || !containedInventory.Items.Any(i => i == null)) { continue; } Entity.Spawner.AddToSpawnQueue(itemSpawnInfo.ItemPrefab, containedInventory); break; } } } break; } } } #if CLIENT if (entity != null) { foreach (ParticleEmitter emitter in particleEmitters) { float angle = 0.0f; if (emitter.Prefab.CopyEntityAngle) { if (entity is Item it) { angle = it.body == null ? 0.0f : it.body.Rotation; } } emitter.Emit(deltaTime, entity.WorldPosition, hull, angle); } } #endif }
protected override void RemoveComponentSpecific() { base.RemoveComponentSpecific(); repairSoundChannel?.FadeOutAndDispose(); repairSoundChannel = null; }
public static Channel PlaySound(AudioClip audio, SoundChannel volumeControl, MODE mode = MODE.DEFAULT) { return(PlaySound(CreateSound(audio, mode), volumeControl)); }
private static void PrivateOpen( int frequency, AudioFormat format, SoundChannel soundChannels, int chunksize) { if (!isOpen) { SdlMixer.Mix_OpenAudio(frequency, (short)format, (int)soundChannels, chunksize); isOpen = true; } }
public override bool Configure(NES.EDetectionOrigin origin) { switch (Cart.board_type) { case "UNIF_UNL-DRIPGAME": break; default: return false; } Cart.wram_size = 8; Cart.wram_battery = false; AssertPrg(16, 32, 64, 128, 256); // 4 bits x 16 AssertChr(8, 16, 32); // 4 bits x 2 AutoMapperProps.Apply(this); prgmask = Cart.prg_size / 16 - 1; chrmask = Cart.prg_size / 2 - 1; prg[1] = prgmask; SetMirror(0); if (NES.apu != null) // don't start up sound when in configurator { sound0 = new SoundChannel(NES.apu.ExternalQueue); sound1 = new SoundChannel(NES.apu.ExternalQueue); } return true; }