private void Inst_OnBeatPressed(BeatBlock block) { if (block.BeatLength > 0) { buttonIsDown = true; } }
private void Awake() { audioM = GetComponent <AudioManager>(); if (audioM == null) { audioM = this.gameObject.AddComponent <AudioManager>(); } //Cria O ritmo dos blocos BeatBlock bloco0 = new BeatBlock(2, new float[] { }); BeatBlock bloco1 = new BeatBlock(2, new float[] { 0f }); BeatBlock bloco2 = new BeatBlock(2, new float[] { 0.5f, 1.5f }); BeatBlock bloco3 = new BeatBlock(2, new float[] { 0.66f, 1.13f, 1.60f }); //Ritmo para blocos rapidos BeatBlock bloco0Fast = new BeatBlock(2, new float[] { }); BeatBlock bloco1Fast = new BeatBlock(2, new float[] { 0f }); BeatBlock bloco2Fast = new BeatBlock(2, new float[] { 0f, 0.66f }); BeatBlock bloco3Fast = new BeatBlock(2, new float[] { 0f, 0.33f, 0.66f }); //normal beatBlockList[0] = bloco0; beatBlockList[1] = bloco1; beatBlockList[2] = bloco2; beatBlockList[3] = bloco3; //hard beatBlockListFast[0] = bloco0Fast; beatBlockListFast[1] = bloco1Fast; beatBlockListFast[2] = bloco2Fast; beatBlockListFast[3] = bloco3Fast; }
public float ScoreBeat(BeatBlock beat, float beatStartedPress, float beatEndedPress) { // maybe up to 4 for pressing and releasing at the right time, and 1 for each beat of long note // factor in pressTimeOffset here bool okay = IsOkay(beat.StartOnBeat, beatStartedPress); bool great = IsGreat(beat.StartOnBeat, beatStartedPress); bool perfect = IsPerfect(beat.StartOnBeat, beatStartedPress); bool endedOnTime = IsOkay(beat.EndOnBeat, beatEndedPress); float score = 0f; if (perfect) { score += 4f; } else if (great) { score += 2f; } else if (okay) { score += 1f; } // for long notes score += Mathf.Min(beat.BeatLength, beatEndedPress - beatStartedPress); if (!endedOnTime) { // dock points for finishing badly score /= 2f; } return(score); }
private void Inst_OnMissed(BeatBlock block) { if (null != block) { Debug.Log("Whiffed block " + block); } else { Debug.Log("Tried to hit something but missed"); } }
private void AdvanceBeatIndex() { lastInstantiatedBeat++; if (lastInstantiatedBeat < toPlay.Count) { var currentBeat = toPlay[lastInstantiatedBeat]; var lastBeat = (lastInstantiatedBeat > 0) ? toPlay[lastInstantiatedBeat - 1] : BeatBit.None; if (currentBeat != BeatBit.None) { if (lastBeat == BeatBit.Long) { // make the last block longer lastInstantiatedBlock.SetBeatLength(lastInstantiatedBlock.BeatLength + 1); } else { // make a new block lastInstantiatedBlock = Instantiate(beatBlockPrefab, beatTrack).GetComponent <BeatBlock>(); lastInstantiatedBlock.StartOnBeat = lastInstantiatedBeat; lastInstantiatedBlock.UpdatePosition(); lastInstantiatedBlock.transform.SetSiblingIndex(1); // draw order instantiatedBlocks.Add(lastInstantiatedBlock); } } else { lastInstantiatedBlock = null; } } else { lastInstantiatedBeat = toPlay.Count; // the end } if ((lastInstantiatedBeat % 8) == 0) { int wordIndex = lastInstantiatedBeat / 8; BeatText beatText = Instantiate(beatTextPrefab, beatTrack).GetComponent <BeatText>(); beatText.StartOnBeat = lastInstantiatedBeat; beatText.UpdatePosition(); beatText.transform.SetSiblingIndex(1); beatText.SetText(poem[wordIndex]); instantiatedBeatTexts.Add(beatText); } }
private void Inst_OnBeatScored(BeatBlock block, float score) { buttonIsDown = false; float adjustedScore = score - block.BeatLength; if (adjustedScore > 2.5f) { StartCoroutine(FlashImageCR(perfectEffect)); } else if (adjustedScore > 1.5f) { StartCoroutine(FlashImageCR(successEffect)); } else { StartCoroutine(FlashImageCR(okayEffect)); } }
private void Inst_OnBeatScored(BeatBlock block, float score) { if (score == 2f) { Hype += .05f; } else if (score > 2f) { Hype += .1f; } else { Hype -= .1f; } Hype = Mathf.Clamp(Hype, minHype, maxHype); //Hype = Mathf.Clamp01(Hype); }
public bool PlaceBlockOnTrack(BeatBlock block, float hitTime, GridPosition offset, float speed, int layer) { float key = hitTime - speed; // The way this class is designed, the key should never be less than the item at the front of the list, because Blocks with // those keys will have already been popped and placed into the game-world. // The front of the list will be indicated by the 'front' pointer, to avoid data-reshuffles. int i = frontOfList; if (frontOfList >= MAX_POSSIBLE_BLOCKS_PER_TRACK) { throw new ArgumentOutOfRangeException("Added too many BeatBlocks to the layout track! Either increase the hardcoded MAX_BLOCKS or add fewer blocks to this track"); } while (i < trackData.Count && key > trackData[i].SpawnTime) { /* Do nothing, we are just searching for the correct spot */ i++; } trackData.Insert(i, block); return(block.PlacedOnLayoutTrack(hitTime, offset, speed, layer)); }
private void Inst_OnMissed(BeatBlock block) { Hype -= .1f; Hype = Mathf.Clamp(Hype, minHype, maxHype); //Hype = Mathf.Clamp01(Hype); }
private void Inst_OnBeatPressed(BeatBlock block) { }
private void Inst_OnMissed(BeatBlock block) { StartCoroutine(FlashImageCR(failEffect)); }
// Callback to signal when an active beatblock has completed its in-game actions and can be returned to a pool for re-use! public void SignalCompletion(BeatBlock blockWhichFinished) { beatBlockPool.PoolObject(blockWhichFinished, blockWhichFinished.BeatBlockTypeId); }
private void Inst_OnBeatScored(BeatBlock block, float score) { totalScore += score; Debug.Log("Score " + score + " New total score " + totalScore); }
private void Inst_OnBeatPressed(BeatBlock block) { Debug.Log("Beat pressed " + block); }
private void Update() { // update input for the tracks if (null != pressingOnBlock) { if (Input.GetKeyUp(buttonToPress) || Jukebox.inst.CurrentBeat > pressingOnBlock.EndOnBeat + pressTimeOffset + pressButtonWithinTime * 2) { float score = ScoreBeat(pressingOnBlock, pressStartTime, Jukebox.inst.CurrentBeat); OnBeatScored(pressingOnBlock, score); alreadyScoredBlocks.Add(pressingOnBlock); pressingOnBlock = null; correctBlocksInWord++; } } else { if (Input.GetKeyDown(buttonToPress)) { BeatBlock closest = null; float closestDelta = 0f; // look for a block I might be pressing on for (int i = 0; i < instantiatedBlocks.Count; i++) { var block = instantiatedBlocks[i]; float startDelta = Mathf.Abs(block.StartOnBeat + pressTimeOffset - Jukebox.inst.CurrentBeat); if (startDelta < pressButtonWithinTime && !alreadyScoredBlocks.Contains(block) && (null == closest || startDelta < closestDelta)) { closest = block; closestDelta = startDelta; break; } } if (null != closest) { pressingOnBlock = closest; pressStartTime = Jukebox.inst.CurrentBeat; OnBeatPressed(closest); } else { OnMissed(null); } } } // check for notes you may have whiffed for (int i = 0; i < instantiatedBlocks.Count; i++) { var block = instantiatedBlocks[i]; if (Jukebox.inst.CurrentBeat > block.StartOnBeat + pressTimeOffset + pressButtonWithinTime && block != pressingOnBlock && !alreadyScoredBlocks.Contains(block)) { OnMissed(block); alreadyScoredBlocks.Add(block); } } // Score current word if applicable float currentWordBeats = (1 + Jukebox.inst.CurrentBeat) % 8f; if (Mathf.Abs(currentWordBeats - wordBeats) > 6f) { int totalBlocksInWord = GetTotalBlocksForWord(wordsScored); string word = poem[wordsScored++]; Debug.Log("Total: " + totalBlocksInWord + ", Correct: " + correctBlocksInWord); if (totalBlocksInWord == correctBlocksInWord) { Debug.Log("Word correct!: " + word); finalWords.Add(word); } else { Debug.Log("Word incorrect!: " + word); finalWords.Add("XXX"); } correctBlocksInWord = 0; if (wordsScored >= poem.Count) { Debug.Log("Done scoring!"); SceneManager.LoadScene(endSceneName); } } wordBeats = currentWordBeats; // instantiation while (Jukebox.inst.CurrentBeat + beatLeadTime > lastInstantiatedBeat && lastInstantiatedBeat < toPlay.Count) { AdvanceBeatIndex(); } // cleanup for (int i = 0; i < instantiatedBlocks.Count; i++) { var block = instantiatedBlocks[i]; if (Jukebox.inst.CurrentBeat > block.EndOnBeat + deleteAfter) { Destroy(block.gameObject); instantiatedBlocks.RemoveAt(i); i--; } } for (int i = 0; i < alreadyScoredBlocks.Count; i++) { if (null == alreadyScoredBlocks[i]) { alreadyScoredBlocks.RemoveAt(i); i--; } } }