Exemplo n.º 1
0
    private void pushAndMatchSequence(Note note)
    {
        // update sequence
        currentSequence.Add(note);
        while (currentSequence.Count() > SEQUENCE_LENGTH)
        {
            currentSequence.RemoveAt(0);
        }

        if (currentSequence.Count() < SEQUENCE_LENGTH)
        {
            return; // do nothing if sequence is not long enough
        }
        foreach (var n in currentSequence)
        {
            if (n.NoteName == Note.Name.Undefined)
            {
                return; // do nothing if one of the notes is undefined
            }
        }

        // sequence was matched
        var seq = new NoteSequence(currentSequence[0], currentSequence[1], currentSequence[2]);

        NoteSequenceDetected?.Invoke(seq);
        Debug.Log(seq);

        // clear the sequence
        currentSequence.Clear();
    }
Exemplo n.º 2
0
    protected override void Customize(NoteSequence notes)
    {
        if (!targetSprite)
        {
            targetSprite = GetComponent <SpriteRenderer>();
        }

        switch (notes.note3.NoteName)
        {
        case Note.Name.Animals:
            targetSprite.color = animal;
            break;

        case Note.Name.Earth:
            targetSprite.color = earth;
            break;

        case Note.Name.Weather:
            targetSprite.color = weather;
            break;

        case Note.Name.Building:
            targetSprite.color = building;
            break;

        case Note.Name.Plants:
            targetSprite.color = plant;
            break;
        }
    }
    protected override void Customize(NoteSequence notes)
    {
        switch (notes.note3.NoteName)
        {
        case Note.Name.Animals:
            transform.localScale = Vector3.one * animal;
            break;

        case Note.Name.Earth:
            transform.localScale = Vector3.one * earth;
            break;

        case Note.Name.Weather:
            transform.localScale = Vector3.one * weather;
            break;

        case Note.Name.Building:
            transform.localScale = Vector3.one * building;
            break;

        case Note.Name.Plants:
            transform.localScale = Vector3.one * plant;
            break;
        }
    }
Exemplo n.º 4
0
    void NoteSequenceDetected(NoteSequence _)
    {
        var noteImage1     = noteBlocks[0].GetComponent <Image>();
        var noteImage2     = noteBlocks[1].GetComponent <Image>();
        var noteImage3     = noteBlocks[2].GetComponent <Image>();
        var sequenceBlocks = noteBlocks.GetRange(0, 3);

        var scaleTween = LeanTween.value(gameObject, 1, 1, 0.45f);

        scaleTween.setEasePunch();
        scaleTween.setOnUpdate(value =>
        {
            noteImage1.transform.localScale = Vector3.one * value;
            noteImage2.transform.localScale = Vector3.one * value;
            noteImage3.transform.localScale = Vector3.one * value;
        });

        successColor.a   = 1f;
        noteImage1.color = successColor;
        noteImage2.color = successColor;
        noteImage3.color = successColor;

        //var colorTween = LeanTween.value(gameObject, 0, 1, 0.25f);
        //colorTween.setEaseOutElastic();

        //colorTween.setOnUpdate(value =>
        //{
        //    noteImage1.color = Color.Lerp(mainColor, successColor, value);
        //    noteImage2.color = Color.Lerp(mainColor, successColor, value);
        //    noteImage3.color = Color.Lerp(mainColor, successColor, value);
        //});
    }
Exemplo n.º 5
0
    public void OnNoteSequenceDetected(NoteSequence noteSequence)
    {
        TriggerAchivement(Achievement.LetThereBeLight);

        // check human
        if (noteSequence.note1.NoteName == Note.Name.Animals &&
            noteSequence.note2.NoteName == Note.Name.Animals)
        {
            TriggerAchivement(Achievement.ApexPredator);
        }

        // check swamp
        if (noteSequence.note1.NoteName == Note.Name.Earth &&
            noteSequence.note2.NoteName == Note.Name.Weather &&
            noteSequence.note3.NoteName == Note.Name.Weather)
        {
            TriggerAchivement(Achievement.Vainamoinen);
        }

        // check tornado
        if (noteSequence.note1.NoteName == Note.Name.Weather &&
            noteSequence.note2.NoteName == Note.Name.Weather &&
            (noteSequence.note3.NoteName == Note.Name.Plants || noteSequence.note3.NoteName == Note.Name.Earth))
        {
            TriggerAchivement(Achievement.Tornado);
        }

        // check seasons
        if (noteSequence.note1.NoteName == Note.Name.Weather &&
            noteSequence.note2.NoteName == Note.Name.Earth)
        {
            switch (noteSequence.note3.NoteName)
            {
            case Note.Name.Animals:
                // Summer
                summerSummoned = true;
                break;

            case Note.Name.Plants:
                // Spring
                springSummoned = true;
                break;

            case Note.Name.Earth:
                // Autumn
                autumnSummoned = true;
                break;

            case Note.Name.Weather:
                // Winter
                winterSummoned = true;
                break;
            }
            if (springSummoned && summerSummoned && autumnSummoned && winterSummoned)
            {
                TriggerAchivement(Achievement.FourSeasons);
            }
        }
    }
Exemplo n.º 6
0
 /// <summary>
 /// Loads a sequence of octave weighted, timed and instrument specific notes from a string into <see cref="NoteSequence"/>
 /// </summary>
 /// <param name="sequence"></param>
 public void LoadSequenceFromString(IEnumerable <string> sequence)
 {
     Song.SetNoteSequence(sequence.ToArray());
     PrepareSequence();
     PlayableSequenceEvent?.Invoke(this, new PlayableSequenceEvent()
     {
         EventType    = PlayableEventType.SequenceLoaded,
         EventDetails = $"{NoteSequence.Count()} Notes loaded."
     });
 }
Exemplo n.º 7
0
 private void Awake()
 {
     if (mInstance == null)
     {
         mInstance = this;
     }
     else if (mInstance != this)
     {
         Destroy(this);
     }
 }
Exemplo n.º 8
0
        public void Scale_ReverseScale_GSharp()
        {
            NoteSequence scale  = new NoteSequence(new NoteSharp[] { NoteSharp.GSharp, NoteSharp.ASharp, NoteSharp.C, NoteSharp.CSharp, NoteSharp.DSharp, NoteSharp.F, NoteSharp.G, NoteSharp.GSharp }),
                         result = _service.ReverseSequence(scale);

            Assert.AreEqual(scale.Length, result.Length);

            for (int i = 0; i < scale.Length; i++)
            {
                Assert.AreEqual(scale.Notes[i], result.Notes[(scale.Length - 1) - i], "Mismatch on index {0}", i);
            }
        }
Exemplo n.º 9
0
        public void Scale_Melodic_F()
        {
            NoteSharp starting = NoteSharp.F;

            NoteSequence scale  = new NoteSequence(new NoteSharp[] { NoteSharp.F, NoteSharp.G, NoteSharp.GSharp, NoteSharp.ASharp, NoteSharp.C, NoteSharp.D, NoteSharp.E, NoteSharp.F, NoteSharp.DSharp, NoteSharp.CSharp, NoteSharp.C, NoteSharp.ASharp, NoteSharp.GSharp, NoteSharp.G, NoteSharp.F }),
                         result = new NoteSequence(_service.BuildMelodicScale(starting).ScaleNotes);

            Assert.AreEqual(scale.Length, result.Length, "Result scale is the wrong length.");

            for (var i = 0; i < scale.Length; i++)
            {
                Assert.AreEqual(scale.Notes[i], result.Notes[i], "Mismatch at index {0}", i);
            }
        }
Exemplo n.º 10
0
        public NoteSequence ReverseSequence(Scale scale)
        {
            NoteSequence seq = scale.ScaleNotes;

            NoteSharp[] reversed = new NoteSharp[seq.Length];
            for (int i = 0; i < seq.Length / 2; i++)
            {
                int swapping = (seq.Length - 1) - i;

                reversed[i] = seq.Notes[swapping];

                reversed[swapping] = seq.Notes[i];
            }

            return(new NoteSequence(reversed));
        }
Exemplo n.º 11
0
    public Entity GetClosestInRange(Vector3 position, float range, NoteSequence self)
    {
        var    rangeSquared    = range * range;
        float  closestDistance = float.MaxValue;
        Entity closest         = null;

        for (int i = 0; i < entities.Count; i++)
        {
            if (!entities[i].recipe.Equals(self))
            {
                var dist = Vector3.SqrMagnitude(position - entities[i].Position);
                if (dist <= rangeSquared && dist < closestDistance)
                {
                    closest         = entities[i];
                    closestDistance = dist;
                }
            }
        }

        return(closest);
    }
Exemplo n.º 12
0
 protected abstract void Customize(NoteSequence notes);
Exemplo n.º 13
0
 public void ReverseSequence()
 {
     NoteSequence = NoteSequence.Reverse();
 }
Exemplo n.º 14
0
 void OnLightningStruck(NoteSequence _)
 {
     TriggerAchivement(Achievement.Zeus);
 }
Exemplo n.º 15
0
 public void InitializeWithNoteSequence(NoteSequence sequence)
 {
     NoteSequence = sequence;
 }
Exemplo n.º 16
0
    private void OnSequenceDetected(NoteSequence noteSequence)
    {
        if (noteSequence.note1.NoteName == Note.Name.Weather && noteSequence.note2.NoteName == Note.Name.Animals)
        {
            ChangeTimeOfDay(noteSequence.note3.NoteName);
            return;
        }

        // season change
        if (noteSequence.note1.NoteName == Note.Name.Weather && noteSequence.note2.NoteName == Note.Name.Earth)
        {
            ChangeSeason(noteSequence.note3.NoteName);
            return;
        }

        // lightning (destruction)
        if (noteSequence.note1.NoteName == Note.Name.Weather && noteSequence.note2.NoteName == Note.Name.Weather && noteSequence.note3.NoteName == Note.Name.Weather)
        {
            CallLightning();
            return;
        }

        List <Entity> prefabs = new List <Entity>();

        for (int i = 0; i < prefabLibrary.Count; i++)
        {
            if (prefabLibrary[i].recipe.Equals(noteSequence))
            {
                prefabs.Add(prefabLibrary[i]);
            }
        }

        if (prefabs.Count == 0)
        {
            // Loose matching to entities with last note of undefined
            for (int i = 0; i < prefabLibrary.Count; i++)
            {
                if (prefabLibrary[i].recipe.note3.NoteName == Note.Name.Undefined &&
                    prefabLibrary[i].recipe.note1.NoteName == noteSequence.note1.NoteName &&
                    prefabLibrary[i].recipe.note2.NoteName == noteSequence.note2.NoteName)
                {
                    prefabs.Add(prefabLibrary[i]);
                }
            }
        }

        if (prefabs.Count > 0)
        {
            var prefab = prefabs[Random.Range(0, prefabs.Count)];
            var entity = Instantiate(prefabs[0], prefab.JitteredPosition(WorldCursor.Instance.Cursor.position), Quaternion.identity);
            entity.transform.parent = entitiesRoot;
            entity.InitializeWithNoteSequence(noteSequence);

            impulseSource.GenerateImpulse(Vector3.one * impulseStrength);
            WorldCursor.Instance.Burst();
        }
        else
        {
            var entity = Instantiate(defaultPrefab, defaultPrefab.JitteredPosition(WorldCursor.Instance.Cursor.position), Quaternion.identity);
            entity.transform.parent = entitiesRoot;
            entity.InitializeWithNoteSequence(noteSequence);
        }
    }