コード例 #1
0
        /// <summary>
        /// (Private) Private method handling low-level OpenAL calls required to play a sound, used by PlaySound() and PlayLoopingSound().
        /// </summary>
        /// <param name="channel">The sound channel in which to play the sound</param>
        /// <param name="file">The sound file, as it appears in the file sourced used by FileSystem</param>
        /// <param name="volume">Volume at which the sound should be played, 1.0 means normal, 0.5 means half volume, 2.0 means twice as loud</param>
        /// <param name="pitch">Pitch at which the sound should be played. 1.0 means normal, 0.5 means 2x slower, 2.0 means 2x faster.</param>
        /// <param name="looping">Should the sound be looping?</param>
        /// <returns>True if everything went well, false otherwise</returns>
        private bool PlaySoundInChannel(int channel, string file, float volume, float pitch, bool looping)
        {
            if (!Enabled)
            {
                return(false);
            }
            if ((channel < 0) || (channel >= TOTAL_CHANNELS))
            {
                return(false);                                              // Channel index is out of bounds
            }
            if (!PrecacheSound(file))
            {
                return(false);                      // Failed to precache the sound (wrong data or file do not exist)
            }
            AudioPlayerSound sound = SoundCache[file];

            StopSound(channel);
            SoundChannels[channel] = AL.GenSource();
            AL.Source(SoundChannels[channel], ALSourcef.Gain, OneBitOfTools.Clamp(volume, 0f, 10f));
            AL.Source(SoundChannels[channel], ALSourcef.Pitch, OneBitOfTools.Clamp(pitch, 0.01f, 10f));
            AL.Source(SoundChannels[channel], ALSourcei.Buffer, sound.Buffer);
            AL.Source(SoundChannels[channel], ALSourceb.Looping, looping);
            AL.SourcePlay(SoundChannels[channel]);

            return(true);
        }
コード例 #2
0
ファイル: Position.cs プロジェクト: akaAgar/one-bit-of-engine
 /// <summary>
 /// Returns a copy of this position with X and Y coordinates clamped to the bounds of an area.
 /// </summary>
 /// <param name="area">The area in which the position must be contained</param>
 /// <returns>A copy of this position with X and Y coordinates clamped to the bounds of an area</returns>
 public Position Bound(Area area)
 {
     return(new Position(
                OneBitOfTools.Clamp(X, area.Left, area.Right - 1),
                OneBitOfTools.Clamp(Y, area.Top, area.Bottom - 1)));
 }
コード例 #3
0
 /// <summary>
 /// (Private) Makes sure an integer value is in the 0-255 range.
 /// </summary>
 /// <param name="value">An integer value</param>
 /// <returns>The value, bounded in the 0-255 range</returns>
 private static int BoundChannelValue(int value)
 {
     return(OneBitOfTools.Clamp(value, 0, 255));
 }