示例#1
0
    public void OnLevelLoaded()
    {
        // checks for failfast with explicit messages
        if (LevelController.INSTANCE == null)
        {
            throw new UnityException("LevelController is missing");
        }
        if (EndBase.INSTANCE == null)
        {
            throw new UnityException("EndBase is missing");
        }

        WaveType waveType = WaveType.SINE;

        if (LevelController.INSTANCE.firstBase != null)
        {
            waveType = LevelController.INSTANCE.firstBase.WaveType;
        }

        // change base type
        StartBase.INSTANCE.playerBase.WaveType = waveType;

        // change door-wall type
        doorWallWaveEmitter.enabled = true;
        doorWallWaveEmitter.ChangeWaveType(waveType);
    }
示例#2
0
 /// <summary>
 /// Create the command
 /// </summary>
 /// <param name="type">Specify how the wave is formed</param>
 /// <param name="color">Specify the color to which leds should be switched</param>
 /// <param name="speed">Abstract duration for the wave effect. The higher, the longer each wave will take.</param>
 /// <param name="repeatCount">Number of time the wave should be repeated, ie. the number of times the wave should pass each led</param>
 public WaveCommand(WaveType type, Color color, byte speed, byte repeatCount)
     : base(color)
 {
     this.Type        = type;
     this.Speed       = speed;
     this.RepeatCount = repeatCount;
 }
    void CreateTargetShape(WaveType shapeType)
    {
        GameObject shapeObject;

        timer = 0;
        wavesSpawned += 1;

        //GameObject targetShape = (GameObject)Resources.Load("Prefaps/TargetShape");

        Vector3 tempScaleVec = new Vector3 (Random.Range (player._minSize.x,  player._maxSize.x), Random.Range (player._minSize.y, player._maxSize.y), 1);
        //print (player._minSize + "max " + player._maxSize);

        Vector3 spawnPoint = new Vector3 (0,0,10);

        if (Random.Range (0, 2) > 0) {

            spawnPoint.x = Random.Range(1,Camera.main.pixelWidth);
            spawnPoint.y = Camera.main.pixelHeight * Random.Range(0,2);

        } else {
            spawnPoint.x = Camera.main.pixelWidth * Random.Range(0,2);
            spawnPoint.y = Random.Range(1,Camera.main.pixelHeight);
        }
        //targetShape.GetComponent<TargetForm> ().speed = 0.2f;

        shapeObject = Instantiate ((GameObject)Resources.Load("Prefaps/TargetShape"),Camera.main.ScreenToWorldPoint(spawnPoint),Quaternion.identity) as GameObject;

        shapeObject.transform.localScale = tempScaleVec;

        if (shapeType.type == WaveType.BLACK_SHAPE) {
            shapeObject.AddComponent<HiddenObject>();
        }
        shapeObject.GetComponent<TargetForm> ().speed = shapeType.speed;
        shapeObject.GetComponent<TargetForm> ().maxCheckTime = checkTimeForLevel;
    }
示例#4
0
        public Wave(Vector3 pos, WaveType type, EnemyType enemytype, int enemycount, PropertyCollection props)
        {
            Position   = pos;
            Type       = type;
            EnemyType  = enemytype;
            EnemyCount = enemycount;
            Props      = props;

            if (Type == WaveType.Line)
            {
                lineEnd = new Vector3(float.Parse(props["EndX"]), float.Parse(props["EndY"]), 0f);
            }

            radius = 20f;

            Enemy e = null;

            if (Type == WaveType.Circle)
            {
                e = EnemyController.Instance.Spawn(EnemyType, Position + new Vector3(0, 0, 200f), props);
            }
            if (Type == WaveType.Line)
            {
                e = EnemyController.Instance.Spawn(EnemyType, (Position - (lineEnd / 2f)) + new Vector3(0, 0, 200f), props);
            }
            e.Scale = 0f;
            Members.Add(e);
            EnemiesSpawned++;
        }
示例#5
0
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            RadioButton rb = (RadioButton)sender;
            string      s  = rb.Content.ToString();

            switch (s)
            {
            case "Off":
                _type = WaveType.None;
                break;

            case "Sinus":
                _type = WaveType.Sinus;
                break;

            case "Square":
                _type = WaveType.Square;
                break;

            case "Saw":
                _type = WaveType.Saw;
                break;

            case "Noise":
                _type = WaveType.Noise;
                break;
            }
        }
示例#6
0
    void Update()
    {
        if (PlayerHealth.instance == null)
        {
            return;
        }

        if (mode == WaveType.Spawning || mode == WaveType.Waiting)
        {
            if (EnemyHealth.enemies.Count == 0)
            {
                mode = WaveType.Counting;
            }

            return;
        }

        if (countdown <= 0)
        {
            StartCoroutine(SpawnWave());
            mode = WaveType.Waiting;

            countdown = waveDelay;
        }
        else
        {
            countdown -= Time.deltaTime;

            mode = WaveType.Counting;
        }
    }
示例#7
0
        public static int SpawnWave(this GameScene scene, WaveType type, Rectangle zone)
        {
            int numberOfPlayers = scene.Game.CurrentGameMode.PlayerInfos.Count;

            int numberOfBoars;
            int numberOfChicken;

            switch (type)
            {
            case WaveType.Fighting:

                if (RandomExt.GetRandomFloat(0, 1) >= 0.5f)
                {
                    numberOfBoars   = numberOfPlayers - 1;
                    numberOfChicken = 0;
                }
                else
                {
                    numberOfBoars   = 0;
                    numberOfChicken = RandomExt.GetRandomInt(5 + numberOfPlayers, 12 + numberOfPlayers);
                }
                break;

            default:
            case WaveType.Collecting:
                numberOfBoars   = RandomExt.GetRandomInt(numberOfPlayers, numberOfPlayers * 2);
                numberOfChicken = RandomExt.GetRandomInt(numberOfPlayers * 3, numberOfPlayers * 5);
                break;
            }

            scene.SpawnCattleInZone(zone, numberOfBoars, numberOfChicken);

            return(numberOfBoars + numberOfChicken);
        }
示例#8
0
        private void InitializeWaveType()
        {
            WaveType waveType = (WaveType)Enum.Parse(typeof(WaveType), Properties.Settings.Default.LastWaveType);

            switch (waveType)
            {
            case WaveType.Sine:
            {
                radioButton_SineWave.Checked = true;
                break;
            }

            case WaveType.Square:
            {
                radioButton_SquareWave.Checked = true;
                break;
            }

            case WaveType.Triangle:
            {
                radioButton_TriangleWave.Checked = true;
                break;
            }

            default:
            {
                radioButton_Gaussian.Checked = true;
                break;
            }
            }
        }
    //Method to spawn a new wave of enemies
    //https://docs.unity3d.com/ScriptReference/WaitForSeconds.html
    //Enumerator is used to pause function for a set amount of time
    IEnumerator SpawnWave()
    {
        if (waveNumber >= waveInfo.Length) //Have we gone through all the waves in the game?
        {
            //TODO declare a victory
        }
        else
        {
            waveNumber++; //Increment the wave number by one at the start of each wave.
        }

        WaveType currentWaveType = waveInfo[waveNumber - 1];

        //Calculate enemy count for this wave.
        int enemyCount = (int)Mathf.Floor((3 * waveNumber + 2) * currentWaveType.wavePercentage);

        Debug.Log("Wave #" + waveNumber + " has begun."); //Debug log to show wave info.

        //Spawn number of enemies based off of the count above
        for (int i = 0; i < enemyCount; i++)
        {
            SpawnEnemy(currentWaveType.enemyTypeForThisWave);
            yield return(new WaitForSeconds(currentWaveType.delayBetweenSpawns)); //Wait half a second between each enemy spawn
        }
    }
示例#10
0
 // Update is called once per frame
 void Update()
 {
     if (IsListening)
     {
         midiNote = VoiceInput.Instance.midi;
         if (GetWaveType() != WaveType.None)
         {
             if (currentWave != GetWaveType())
             {
                 if (debug_log)
                 {
                     Debug.Log("CAMBIO DE WAVE!!!!!! ");
                     Debug.Log("WAVE ANTERIOR = " + currentWave.ToString());
                 }
                 currentWave = GetWaveType();
                 WaveChanged();
                 if (debug_log)
                 {
                     Debug.Log("WAVE NUEVA = " + currentWave.ToString());
                 }
             }
         }
         else
         {
             if (OnWaveStoppedCallback != null)
             {
                 OnWaveStoppedCallback();
             }
         }
     }
 }
示例#11
0
    private void OnRoundStarted(WaveType waveType)
    {
        Debug.Log("OnRoundStarted");

        currWaveType = waveType;

        switch (waveType)
        {
        case WaveType.normal:
            currTheme = theme_normal[Random.Range(0, theme_normal.Length)];
            break;

        case WaveType.hunter:
            currTheme = theme_hunter[Random.Range(0, theme_hunter.Length)];
            break;
        }

        if (ambient != null)
        {
            StopCoroutine(ambient);
        }
        ambient = StartCoroutine(StopAmbient());

        if (action != null)
        {
            StopCoroutine(action);
        }
        action = StartCoroutine(StartAction(true));
    }
示例#12
0
    void Start()
    {
        baseLocalPos     = waveFront.transform.localPosition;
        lastBaseLocalPos = waveFront.transform.localPosition;

        trailPoints = new Vector3[trailMaxPoints];
        trailRenderer.numPositions = trailMaxPoints;
        trailRenderer.enabled      = false;

        if ((waveType & WaveType.TRIANGLE) != 0)
        {
            visualWaveType = WaveType.TRIANGLE;
        }
        else if ((waveType & WaveType.SQUARE) != 0)
        {
            visualWaveType = WaveType.SQUARE;
        }
        else if ((waveType & WaveType.SINE) != 0)
        {
            visualWaveType = WaveType.SINE;
        }

        if (visualWaveType == WaveType.TRIANGLE)
        {
            trailRenderer.numCornerVertices = 0;
        }
        if (visualWaveType == WaveType.SQUARE)
        {
            trailRenderer.numCornerVertices = 0;
        }
        if (visualWaveType == WaveType.SINE)
        {
            trailRenderer.numCornerVertices = 3;
        }
    }
示例#13
0
        public void NextType()
        {
            const int count       = (int)WaveType.Count;
            int       currentType = (int)Type;

            Type = (WaveType)((currentType + 1) % count);
        }
示例#14
0
    public override void DrawWindow()
    {
        base.DrawWindow();
        Event e = Event.current;

        windowRect = new Rect(windowRect.x, windowRect.y, 200, 250);
        EditorGUI.BeginChangeCheck();

        type        = (WaveType)EditorGUILayout.EnumPopup("Wave Type : ", type);
        resolution  = EditorGUILayout.Vector2Field("Resolution", resolution);
        numberScale = EditorGUILayout.Vector2Field("Number Scale", numberScale);

        GUILayout.BeginHorizontal();
        minScale = (EditorGUILayout.FloatField(minScale, GUILayout.Width(40)));
        EditorGUILayout.MinMaxSlider(ref numberScale.x, ref numberScale.y, minScale, maxScale, GUILayout.Width(100));
        maxScale = (EditorGUILayout.FloatField(maxScale, GUILayout.Width(40)));
        GUILayout.EndHorizontal();
        GUILayout.Label("Frequency");
        frequency = EditorGUILayout.FloatField(frequency);
        Phase     = EditorGUILayout.Vector2Field("Phase :", Phase);
        if (EditorGUI.EndChangeCheck())
        {
            outputIsCalculated = false;
            iHaveBeenRecalculated();
            EditorUtility.SetDirty(this);
        }
    }
示例#15
0
 public void castWave(WaveType waveType)
 {
     mWaveType     = waveType;
     waveCastTimer = waveCastCoolDown;
     if (waveType == WaveType.Long)
     {
         waveSpeed     = LongWaveSpeed;
         waveMaxRadius = LongWaveMaximumRadius;
     }
     else if (waveType == WaveType.Mid)
     {
         waveSpeed     = MidWaveSpeed;
         waveMaxRadius = MidWaveMaximumRadius;
     }
     else if (waveType == WaveType.Short)
     {
         waveSpeed     = ShortWaveSpeed;
         waveMaxRadius = ShortWaveMaximumRadius;
     }
     // Debug.Log("waveSpeed: " + waveSpeed + ", waveRadius" + waveMaxRadius);
     mCircleCollider.enabled = true;
     mCircleCollider.radius  = waveInitialRadius;
     castPosition            = mPlayer.transform.position;
     //StartCoroutine(waveStart(waveType));
     waveStart(waveType);
 }
示例#16
0
 public Wave(WaveType WaveType, double Frequency, double Magnitude, double Phase)
 {
     _waveType  = WaveType;
     _frequency = Frequency;
     _magnitude = Magnitude;
     _phase     = Phase;
 }
 /// <summary>
 /// Set settings of voice.
 /// </summary>
 /// <param name="waveType">Type of wave.</param>
 private Voice(WaveType waveType)
 {
     this.waveType = waveType;
     noteNumber    = -1;
     velocity      = 0;
     isActive      = false;
 }
示例#18
0
 private void AddSignal(WaveType waveType) => CommandCon.AppendSignal(new Signal
 {
     Name = NameSource.Names.First(
         name => Scene.Signals.FirstOrDefault(
             signal => signal.Name == name) == null),
     WaveType = waveType
 });
示例#19
0
    private GameObject GetNearestEnemy(WaveType type)
    {
        GameObject leftEnemy  = leftSpawner.GetNearestEnemy(type);
        GameObject rightEnemy = rightSpawner.GetNearestEnemy(type);

        if (leftEnemy == null)
        {
            nearestEnemyOrigin = rightSpawner;
            return(rightEnemy);
        }
        else if (rightEnemy == null)
        {
            nearestEnemyOrigin = leftSpawner;
            return(leftEnemy);
        }
        else
        {
            if (leftEnemy.GetComponent <Enemy> ().GetDistanceToDeath() < rightEnemy.GetComponent <Enemy> ().GetDistanceToDeath())
            {
                nearestEnemyOrigin = leftSpawner;
                return(leftEnemy);
            }
            else
            {
                nearestEnemyOrigin = rightSpawner;
                return(rightEnemy);
            }
        }
    }
        // Wave
        public static GameObject CreateWave(WaveType waveType, Sprite sprite, Font font)
        {
            // UI hierarchy
            Vector2 size = Vector2.one;

            size.x *= wWidth;
            size.y *= wHeight;
            var root    = CreateUIElementRoot(waveType.ToString() + " Wave", size);
            var graphic = CreateUIObject("Graphic", root);

            // Stretch settings
            FitToParent(graphic, Vector2.zero);

            // Graphic
            var image = graphic.AddComponent <Image>();

            image.material = new Material(Shader.Find("UI/Unlit/Wave"));
            image.sprite   = sprite;
            image.color    = Color.white;

            // Wave
            var wave = root.AddComponent <MidiWave>();

            wave.graphic  = image;
            wave.waveType = waveType;

            return(root);
        }
示例#21
0
 protected void StartWave()
 {
     currentWave++;
     currentWaveType = GetWaveType();
     Debug.Log("currentWave: " + currentWave + " wave type: " + currentWaveType);
     enemiesSpawnManager.StartNewWave(currentWaveType);
 }
示例#22
0
        public override void Update(float elapsedSeconds, float totalSeconds)
        {
            base.Update(elapsedSeconds, totalSeconds);

            nextWaveCanRespawn = nextWaveCanRespawn || minimumTimeBetweenWaves.Tick(elapsedSeconds);
            spawnNextWave      = nextWaveCanRespawn && (currentAnimalCount <= animalThresholdForNextWave || maxiumumTimeBetweenWaves.Tick(elapsedSeconds));

            // if the next
            if ((spawnNextWave && remainingWaves > 0) || (currentAnimalCount == 0 && nextWaveCanRespawn))
            {
                nextWaveCanRespawn = false;
                spawnNextWave      = false;
                minimumTimeBetweenWaves.Reset();
                maxiumumTimeBetweenWaves.Reset();

                WaveType waveType = RandomExt.GetRandomFloat(0, 1) >= 0.5f ? WaveType.Collecting : WaveType.Fighting;
                currentAnimalCount += this.SpawnWave(waveType, new Rectangle((int)(0.625f * centerX), (int)(-0.625f * centerY), 2, (int)screenHeight / 2));

                animalThresholdForNextWave = (int)Math.Ceiling(currentAnimalCount * 0.1f);

                remainingWaves--;

                if (remainingWaves == 0)
                {
                    base.StartCountown();
                }
            }
        }
        public void ApplyWave(int channel, WaveType function, double freq, double amplitude, double offset)
        {
            switch (function)
            {
                case WaveType.Sine:
                    WaveGen.SendCommand("SOUR"+channel.ToString() + ":APPL:SIN " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.Square:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:SQU " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.Ramp:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:RAMP " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.Pulse:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:PULS " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.Noise:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:NOIS " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.DC:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:DC " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

                case WaveType.User:
                    WaveGen.SendCommand("SOUR" + channel.ToString() + ":APPL:USER " + freq.ToString() + ", " + amplitude.ToString() + ", " + offset.ToString());
                    break;

            }
        }
示例#24
0
        private static Shader[] CreateShaders(WaveType type, bool clamping)
        {
            var fragmentShader = new StringBuilder(FragmentShaderHeader,
                                                   FragmentShaderHeader.Length + FragmentSinWave.Length + FragmentShaderFooter.Length);

            switch (type)
            {
            case WaveType.Sinusoidal:
                fragmentShader.Append(FragmentSinWave);
                break;

            case WaveType.CircleWave:
                fragmentShader.Append(FragmentCircleWave);
                break;
            }

            if (clamping)
            {
                fragmentShader.Append(FragmentClamping);
            }

            fragmentShader.Append(FragmentShaderFooter);
            return(new Shader[] {
                new VertexShader(VertexShader),
                new FragmentShader(fragmentShader.ToString())
            });
        }
 public static extern UInt32 SetCalibrationPins(
     short handle,
     PinStates pinStates,
     WaveType waveType,
     double frequency,
     uint amplitude,
     uint offset);
示例#26
0
 public Voltage(WaveType wf) : base()
 {
     waveform   = wf;
     maxVoltage = 5;
     frequency  = 40;
     reset();
 }
示例#27
0
 /// <summary>
 /// Creates a preset for generating mathematic audio wave.
 /// </summary>
 /// <param name="frequency">Determines the tone of the wave.</param>
 /// <param name="amplitude">The volume of the wave at its peak.</param>
 /// <param name="mode">One of available wave generation modes: sine, square, triangle or simple pulses.</param>
 /// <param name="samplerate">Amount of bytes in one second.</param>
 public Oscillation16(UInt32 frequency, Int16 amplitude = 127, WaveType mode = WaveType.Sine, UInt32 samplerate = 44100)
 {
     this.SampleRate = samplerate;
     this.Frequency  = frequency;
     this.Amplitude  = amplitude;
     this.WaveMode   = mode;
 }
示例#28
0
    private void Awake()
    {
        if (baseTubeCircle != null)
        {
            baseTubeCircle.gameObject.SetActive(false);
        }
        if (baseTubeSquare != null)
        {
            baseTubeSquare.gameObject.SetActive(false);
        }
        if (baseTubeTriangle != null)
        {
            baseTubeTriangle.gameObject.SetActive(false);
        }
        if (baseTubeCircleSquare != null)
        {
            baseTubeCircleSquare.gameObject.SetActive(false);
        }
        if (baseTubeCircleTriangle != null)
        {
            baseTubeCircleTriangle.gameObject.SetActive(false);
        }
        if (baseTubeSquareTriangle != null)
        {
            baseTubeSquareTriangle.gameObject.SetActive(false);
        }
        if (baseTubeCircleSquareTriangle != null)
        {
            baseTubeCircleSquareTriangle.gameObject.SetActive(false);
        }

        WaveType = defaultWaveType;
    }
示例#29
0
    public void Twinkle(int waveNum, WaveType type)
    {
        if (waveNums.Contains(waveNum))
        {
            return;
        }

        CancelInvoke("RestoreColor");
        waveNums.Add(waveNum);
        renderer.material.SetColor("_EmissionColor", GetRandomColor());

        switch (type)
        {
        case WaveType.Square:
            StartCoroutine(SquareWave(waveNum));
            break;

        case WaveType.Diamond:
            StartCoroutine(DiamondWave(waveNum));
            break;

        case WaveType.Cross:

            break;
        }
        Invoke("RestoreColor", 0.1f);
    }
示例#30
0
 public void SetGeneratorType(int channel, WaveType waveVal)
 {
     if (channel >= 0 && channel < genArr.Length)
     {
         genArr[channel].GeneratorType = waveVal;
     }
 }
示例#31
0
		public WavLoader(Stream s)
		{
			while (s.Position < s.Length)
			{
				if ((s.Position & 1) == 1)
					s.ReadByte(); // Alignment

				var type = s.ReadASCII(4);
				switch (type)
				{
					case "RIFF":
						FileSize = s.ReadInt32();
						Format = s.ReadASCII(4);
						if (Format != "WAVE")
							throw new NotSupportedException("Not a canonical WAVE file.");
						break;
					case "fmt ":
						FmtChunkSize = s.ReadInt32();
						AudioFormat = s.ReadInt16();
						Type = (WaveType)AudioFormat;
						if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
							throw new NotSupportedException("Compression type is not supported.");
						Channels = s.ReadInt16();
						SampleRate = s.ReadInt32();
						ByteRate = s.ReadInt32();
						BlockAlign = s.ReadInt16();
						BitsPerSample = s.ReadInt16();

						s.ReadBytes(FmtChunkSize - 16);
						break;
					case "fact":
						{
							var chunkSize = s.ReadInt32();
							UncompressedSize = s.ReadInt32();
							s.ReadBytes(chunkSize - 4);
						}

						break;
					case "data":
						DataSize = s.ReadInt32();
						RawOutput = s.ReadBytes(DataSize);
						break;
					default:
						// Ignore unknown chunks
						{
							var chunkSize = s.ReadInt32();
							s.ReadBytes(chunkSize);
						}

						break;
				}
			}

			if (Type == WaveType.ImaAdpcm)
			{
				RawOutput = DecodeImaAdpcmData();
				BitsPerSample = 16;
			}
		}
示例#32
0
        public static WaveShaderProgram GetInstance(WaveType type = WaveType.Sinusoidal, bool isClamped = false)
        {
            var key = GetInstanceKey(type, isClamped);

            return(instances.TryGetValue(key, out var shaderProgram)
                                ? shaderProgram
                                : (instances[key] = new WaveShaderProgram(type, isClamped)));
        }
示例#33
0
 public Voltage(WaveType wf)
     : base()
 {
     waveform = wf;
     maxVoltage = 5;
     frequency = 40;
     reset();
 }
        public static void PlayWave(
            double freq, short durMS,
            WaveType Wt, AudioSource Src,
            float Volume)
        {
            Src.DSEI.Stop();

            Src.BufferSize = Src.DSEI.GetSampleSizeInBytes(TimeSpan.FromMilliseconds(durMS));
            Src.Buffer     = new byte[Src.BufferSize];

            int size = Src.BufferSize - 1;

            for (int i = 0; i < size; i += 2)
            {
                double time = (double)Src.TotalTime / (double)Src.SampleRate;

                short currentSample = 0;
                switch (Wt)
                {
                case WaveType.Sin:
                {
                    currentSample = (short)(Math.Sin(2 * Math.PI * freq * time) * (double)short.MaxValue * Volume);
                    break;
                }

                case WaveType.Tan:
                {
                    currentSample = (short)(Math.Tan(2 * Math.PI * freq * time) * (double)short.MaxValue * Volume);
                    break;
                }

                case WaveType.Log:     //bit crushed kinda
                {
                    currentSample = (short)(Math.Log(Math.Sin(2 * Math.PI * freq * time)) * (double)short.MaxValue * Volume);
                    break;
                }

                case WaveType.Square:
                {
                    currentSample = (short)(Math.Sign(Math.Sin(2 * Math.PI * freq * time)) * (double)short.MaxValue * Volume);
                    break;
                }

                case WaveType.Noise:
                {
                    currentSample = (short)(Rand.Next(-short.MaxValue, short.MaxValue) * Volume);
                    break;
                }
                }

                Src.Buffer[i]     = (byte)(currentSample & 0xFF);
                Src.Buffer[i + 1] = (byte)(currentSample >> 8);
                Src.TotalTime    += 2;
            }

            Src.DSEI.SubmitBuffer(Src.Buffer);
            Src.DSEI.Play();
        }
    void CreateWave(string type, int amount,float speedWaveType)
    {
        WaveType targetUnit;
        for (int i = 0; i < amount; i++) {
            targetUnit = new WaveType(type,speedWaveType);

            _allWavesForLevel.Add(targetUnit);
        }
        _allWavesForLevel = RandomnizeGList (_allWavesForLevel);
    }
示例#36
0
        public Wave(Vector3 pos, WaveType type, EnemyType enemytype, int enemycount, PropertyCollection props)
        {
            Position = pos;
            Type = type;
            EnemyType = enemytype;
            EnemyCount = enemycount;
            Props = props;

            if (Type == WaveType.Line)
            {
                lineEnd = new Vector3(float.Parse(props["EndX"]), float.Parse(props["EndY"]), 0f);
            }

            radius = 20f;

            Enemy e = null;
            if(Type== WaveType.Circle) e = EnemyController.Instance.Spawn(EnemyType, Position + new Vector3(0, 0, 200f), props);
            if (Type == WaveType.Line) e = EnemyController.Instance.Spawn(EnemyType, (Position - (lineEnd/2f)) + new Vector3(0, 0, 200f), props);
            e.Scale = 0f;
            Members.Add(e);
            EnemiesSpawned++;
        }
示例#37
0
        private static bool isWaveTypeArg(string arg, out WaveType wavetype)
        {
            wavetype = 0;

            return Enum.TryParse(arg, true, out wavetype)
                && Enum.IsDefined(typeof(WaveType), wavetype);
        }
        public void SetOutputFunction(int channel, WaveType function)
        {
            string ch;

            if (channel == 2)
                ch = ":CH2 ";
            else
                ch = " ";

            switch (function)
            {
                case WaveType.Sine:
                    WaveGen.SendCommand("FUNC SIN" + ch);
                    break;
                case WaveType.Square:
                    WaveGen.SendCommand("FUNC SQU" + ch);
                    break;
                case WaveType.Ramp:
                    WaveGen.SendCommand("FUNC RAMP" + ch);
                    break;
                case WaveType.Pulse:
                    WaveGen.SendCommand("FUNC PULS" + ch);
                    break;
                case WaveType.Noise:
                    WaveGen.SendCommand("FUNC NOIS" + ch);
                    break;
                case WaveType.DC:
                    WaveGen.SendCommand("FUNC DC" + ch);
                    break;
                case WaveType.User:
                    WaveGen.SendCommand("FUNC USER" + ch);
                    break;
            }
        }
示例#39
0
文件: EnemyWave.cs 项目: Lyise/SARP
        public EnemyWave(WaveType thisWaveType, WeaponType thisWaveWeapon, int? EnemyCount, Texture2D EnemyTexture, Vector2 MidPoint, float? EnemySpeed, int? waveParameter1, int? waveParameter2)
        {
            // If no wave type is set, pick a random one
            if (thisWaveType == WaveType.NotSet)
            {
                WaveType[] values = (WaveType[])Enum.GetValues(typeof(WaveType));
                int randomType = randomiser.Next(0, values.Length - 1);
                thisWaveType = values[randomType];
            }

            // If no weapon type is set, pick a random one
            if (thisWaveWeapon == WeaponType.NotSet)
            {
                // TO DO:   Change this to a pre-defined list for each wave type,
                //          so the rotating cannon isn't available for non-bosses, for example
                WeaponType[] values = (WeaponType[])Enum.GetValues(typeof(WeaponType));
                int randomType = randomiser.Next(0, values.Length - 1);
                wtWeapon = values[randomType];
            }

            // Randomise other wave parameters
            if (EnemyCount == null)
                EnemyCount = randomiser.Next(iMinEnemies, iMaxEnemies + 1);

            if (EnemySpeed == null)
                EnemySpeed = randomiser.Next((int)(fMinSpeed * 100), (int)(fMaxSpeed * 100)) / 100f;

            if (waveParameter1 == null)
                waveParameter1 = randomiser.Next(iMinParameter1, iMaxParameter1);

            if (waveParameter2 == null)
                waveParameter2 = randomiser.Next(iMinParameter2, iMaxParameter2);

            waveType = thisWaveType;
            v2MidPoint = MidPoint;
            fSpeed = (float)EnemySpeed;

            iWaveParameter1 = (int)waveParameter1;
            iWaveParameter2 = (int)waveParameter2;

            // Create the enemies of the wave
            for (int i = 0; i < EnemyCount; i++)
            {
                Vector2 thisEnemyInitialLocaton = Vector2.Zero;
                Vector2 thisEnemyStartLocation = MidPoint;

                thisEnemyInitialLocaton.Y -= randomiser.Next(10, 100);
                thisEnemyInitialLocaton.X = MidPoint.X - (MidPoint.X / 2) + randomiser.Next(0, (int)MidPoint.X);

                switch (waveType)
                {
                    case WaveType.Static:
                        // waveParameter1 = spacing
                        thisEnemyStartLocation.X -= ((EnemyTexture.Width + (float)waveParameter1) * (float)EnemyCount) / 2f;
                        thisEnemyStartLocation.X += (EnemyTexture.Width + (float)waveParameter1) * (float)i;
                        break;
                    case WaveType.ClockwiseCircle:
                    case WaveType.AnticlockwiseCircle:
                        // waveParameter1 = radius
                        double angle = (i / (double)EnemyCount) * (2 * (double)Math.PI);
                        thisEnemyStartLocation.X += (float)(Math.Sin(angle) * waveParameter1);
                        thisEnemyStartLocation.Y += (float)(Math.Cos(angle) * waveParameter1);
                        break;
                }

                Enemies.Add(new Enemy(thisEnemyInitialLocaton, thisEnemyStartLocation, Vector2.Zero, (float)EnemySpeed, EnemyTexture, 10, wtWeapon));
            }
        }
示例#40
0
        public bool LoadSound(Stream s)
        {
            var type = s.ReadASCII(4);
            if (type != "RIFF")
                return false;

            FileSize = s.ReadInt32();
            Format = s.ReadASCII(4);
            if (Format != "WAVE")
                return false;
            while (s.Position < s.Length)
            {
                if ((s.Position & 1) == 1)
                    s.ReadByte(); // Alignment

                type = s.ReadASCII(4);
                switch (type)
                {
                    case "fmt ":
                        FmtChunkSize = s.ReadInt32();
                        AudioFormat = s.ReadInt16();
                        Type = (WaveType)AudioFormat;

                        if (!Enum.IsDefined(typeof(WaveType), Type))
                            throw new NotSupportedException("Compression type {0} is not supported.".F(AudioFormat));

                        Channels = s.ReadInt16();
                        SampleRate = s.ReadInt32();
                        ByteRate = s.ReadInt32();
                        BlockAlign = s.ReadInt16();
                        BitsPerSample = s.ReadInt16();

                        s.ReadBytes(FmtChunkSize - 16);
                        break;
                    case "fact":
                        var chunkSize = s.ReadInt32();
                        UncompressedSize = s.ReadInt32();
                        s.ReadBytes(chunkSize - 4);
                        break;
                    case "data":
                        DataSize = s.ReadInt32();
                        RawOutput = s.ReadBytes(DataSize);
                        break;
                    default:
                        var unknownChunkSize = s.ReadInt32();
                        s.ReadBytes(unknownChunkSize);
                        break;
                }
            }

            if (Type == WaveType.ImaAdpcm)
            {
                RawOutput = DecodeImaAdpcmData();
                BitsPerSample = 16;
            }

            return true;
        }
示例#41
0
        private void switchSpectrumAnalyzer()
        {
            if (AudioWaveType == WaveType.Normal)
                AudioWaveType = WaveType.FFT;
            else if (AudioWaveType == WaveType.FFT)
                AudioWaveType = WaveType.FFTWave;
            else
                AudioWaveType = WaveType.Normal;

            updateAudioWave();
            updateAudioGrid();
        }
示例#42
0
 public void SetGeneratorType(int channel, WaveType waveVal)
 {
     if (channel >= 0 && channel < genArr.Length)
     {
         genArr[channel].GeneratorType = waveVal;
     }
 }
示例#43
0
 public WaveGenerator(WaveType generatorType = WaveType.Square)
 {
     GeneratorType = generatorType;
     envelope = new Envelope(44100);
 }
示例#44
0
 public VoltageInput(WaveType wf)
     : base(wf)
 {
 }
示例#45
0
        private void karaokeTimerW_Load(object sender, EventArgs e)
        {
            if (mW.al.Count > 0)
                DisplayLine(0);

            zoomKaraokeTrackBar.Maximum = mW.zoomTrackBar.Maximum;
            zoomKaraokeTrackBar.Minimum = mW.zoomTrackBar.Minimum;
            zoomKaraokeTrackBar.LargeChange = mW.zoomTrackBar.LargeChange;
            zoomKaraokeTrackBar.SmallChange = mW.zoomTrackBar.SmallChange;
            zoomKaraokeTrackBar.Value = mW.zoomTrackBar.Value;
            this.Width = 800;
            WaveStyle = mW.AudioWaveType;
            FillPanelButtons();
        }
示例#46
0
 private void toolStripButton9_Click(object sender, EventArgs e)
 {
     switch (WaveStyle)
     {
         case WaveType.Normal:
             WaveStyle = WaveType.FFT;
             break;
         case WaveType.FFT:
             WaveStyle = WaveType.FFTWave;
             break;
         case WaveType.FFTWave:
             WaveStyle = WaveType.Normal;
             break;
     }
     DrawAudioWave();
 }
示例#47
0
        public void FromString(string s)
        {
            string[] splitStrings = s.Split(new char[] { ',' });

            for(int i = 0; i < splitStrings.Length; i++)
                if(splitStrings[i].Length == 0)
                    splitStrings[i] = "0";

            WaveType = splitStrings[0] == "0" ? WaveType.Square : splitStrings[0] == "1" ? WaveType.Saw : splitStrings[0] == "2" ? WaveType.Sin : WaveType.Noise;
            AttackTime = float.Parse(splitStrings[1]);
            SustainTime = float.Parse(splitStrings[2]);
            SustainPunch = float.Parse(splitStrings[3]);
            DecayTime = float.Parse(splitStrings[4]);
            StartFrequency = float.Parse(splitStrings[5]);
            MinFrequency = float.Parse(splitStrings[6]);
            Slide = float.Parse(splitStrings[7]);
            DeltaSlide = float.Parse(splitStrings[8]);
            VibratoDepth = float.Parse(splitStrings[9]);
            VibratoSpeed = float.Parse(splitStrings[10]);
            ChangeAmount = float.Parse(splitStrings[11]);
            ChangeSpeed = float.Parse(splitStrings[12]);
            SquareDuty = float.Parse(splitStrings[13]);
            DutySweep = float.Parse(splitStrings[14]);
            RepeatSpeed = float.Parse(splitStrings[15]);
            PhaserOffset = float.Parse(splitStrings[16]);
            PhaserSweep = float.Parse(splitStrings[17]);
            lpFilterCutoff = float.Parse(splitStrings[18]);
            lpFilterCutoffSweep = float.Parse(splitStrings[19]);
            lpFilterResonance = float.Parse(splitStrings[20]);
            hpFilterCutoff = float.Parse(splitStrings[21]);
            hpFilterCutoffSweep = float.Parse(splitStrings[22]);
            MasterVolume = float.Parse(splitStrings[23]);
        }
示例#48
0
        private void Reset(bool totalReset)
        {
            SfxrParams p = localParams;

            period = 100.0f / (p.StartFrequency * p.StartFrequency + 0.001f);
            maxPeriod = 100.0f / (p.MinFrequency * p.MinFrequency + 0.001f);

            slide = 1.0f - p.Slide * p.Slide * p.Slide * 0.01f;
            deltaSlide = -p.DeltaSlide * p.DeltaSlide * p.DeltaSlide * 0.000001f;

            if (p.WaveType == WaveType.Square)
            {
                squareDuty = 0.5f - p.SquareDuty * 0.5f;
                dutySweep = -p.DutySweep * 0.00005f;
            }

            if (p.ChangeAmount > 0.0f)
                changeAmount = 1.0f - p.ChangeAmount * p.ChangeAmount * 0.9f;
            else
                changeAmount = 1.0f + p.ChangeAmount * p.ChangeAmount * 10.0f;

            changeTime = 0;

            if(p.ChangeSpeed == 1.0)
                changeLimit = 0;
            else
                changeLimit = (int)((1.0f - p.ChangeSpeed) * (1.0f - p.ChangeSpeed) * 20000 + 32);

            if(totalReset)
            {
                masterVolume = p.MasterVolume * p.MasterVolume;

                waveType = p.WaveType;

                if (p.SustainTime < 0.01f)
                    p.SustainTime = 0.01f;

                double totalTime = p.AttackTime + p.SustainTime + p.DecayTime;
                if (totalTime < 0.18)
                {
                    double multiplier = 0.18 / totalTime;
                    p.AttackTime *= multiplier;
                    p.SustainTime *= multiplier;
                    p.DecayTime *= multiplier;
                }

                sustainPunch = p.SustainPunch;

                phase = 0;

                minFrequency = p.MinFrequency;

                filters = p.lpFilterCutoff != 1.0 || p.hpFilterCutoff != 0.0;

                lpFilterPos = 0.0f;
                lpFilterDeltaPos = 0.0f;
                lpFilterCutoff = p.lpFilterCutoff * p.lpFilterCutoff * p.lpFilterCutoff * 0.1f;
                lpFilterDeltaCutoff = 1.0f + p.lpFilterCutoffSweep * 0.0001f;
                lpFilterDamping = 5.0f / (1.0f + p.lpFilterResonance * p.lpFilterResonance * 20.0f) * (0.01f + lpFilterCutoff);
                if (lpFilterDamping > 0.8) lpFilterDamping = 0.8f;
                lpFilterDamping = 1.0f - lpFilterDamping;
                lpFilterOn = p.lpFilterCutoff != 1.0f;

                hpFilterPos = 0.0f;
                hpFilterCutoff = p.hpFilterCutoff * p.hpFilterCutoff * 0.1f;
                hpFilterDeltaCutoff = 1.0f + p.hpFilterCutoffSweep * 0.0003f;

                vibratoPhase = 0.0f;
                vibratoSpeed = p.VibratoSpeed * p.VibratoSpeed * 0.01f;
                vibratoAmplitude = p.VibratoDepth * 0.5f;

                envelopeVolume = 0.0f;
                envelopeStage = 0;
                envelopeTime = 0;
                envelopeLength0 = p.AttackTime * p.AttackTime * 100000.0f;
                envelopeLength1 = p.SustainTime * p.SustainTime * 100000.0f;
                envelopeLength2 = p.DecayTime * p.DecayTime * 100000.0f + 10;
                envelopeLength = envelopeLength0;
                envelopeFullLength = envelopeLength0 + envelopeLength1 + envelopeLength2;

                envelopeOverLength0 = 1.0f / envelopeLength0;
                envelopeOverLength1 = 1.0f / envelopeLength1;
                envelopeOverLength2 = 1.0f / envelopeLength2;

                phaser = p.PhaserOffset != 0.0f || p.PhaserSweep != 0.0f;

                phaserOffset = p.PhaserOffset * p.PhaserOffset * 1020.0f;
                if(p.PhaserOffset < 0.0)
                    phaserOffset = -phaserOffset;
                phaserDeltaOffset = p.PhaserSweep * p.PhaserSweep * p.PhaserSweep * 0.2f;
                phaserPos = 0;

                for(int i=0; i<1024; i++)
                    phaserBuffer[i] = 0;

                for(int i=0; i<32; i++)
                    noiseBuffer[i] = (float)random.NextDouble() * 2.0f - 1.0f;

                repeatTime = 0;

                if (p.RepeatSpeed == 0.0)
                    repeatLimit = 0;
                else
                    repeatLimit = (int)((1.0f - p.RepeatSpeed) * (1.0f - p.RepeatSpeed) * 20000) + 32;
            }
        }