public Note(float t, int d, float lb, float bpm) { time = t; dir = (NoteDir)d; leadBeats = lb; beatsPerMinute = bpm; }
// Start is called before the first frame update void Start() { updateRate = beatsPerMinute / 60f; var noteLines = noteFile.text.Split("\n"[0]); songNotes = new List <Note>(); int i = 0; foreach (var noteLine in noteLines) { var noteData = (noteLine.Trim()).Split(","[0]); float t = 0, b = 0, lb = leadBeatsDefault, bpm = beatsPerMinute; NoteDir d = NoteDir.Up; switch (noteData.Length) { case 4: bpm = float.Parse(noteData[3]); goto case 3; case 3: lb = float.Parse(noteData[2]); goto case 2; case 2: b = float.Parse(noteData[0]); d = (NoteDir)int.Parse(noteData[1]); break; default: Debug.Log($"Bad line in notes CSV [{i}]: {noteLine}"); continue; } float bps = 60f / bpm; t = bps * (b - lb); var note = new Note(t, d, lb, bpm); songNotes.Add(note); i++; } totalNotes = songNotes.Count; Debug.Log("Total Song notes: " + totalNotes); Debug.Log("Song notes (presort): " + string.Join("\n ", songNotes)); songNotes.Sort((n1, n2) => n1.time.CompareTo(n2.time)); timeInSong = 0; Debug.Log("Song notes: " + string.Join("\n ", songNotes)); popNextNote(); Debug.Log("Next note: " + nextNote); }
public void PlaceNote(Conductor gameConductor, float noteBeat, float zStart, float zEnd, float xPos, float yPos, NoteType ntype, NoteDir direction) { conductor = gameConductor; beat = noteBeat; type = ntype; dir = direction; spawnPos = new Vector3(xPos, yPos, zStart); endPos = new Vector3(xPos, yPos, zEnd); transform.position = new Vector3(xPos, yPos, zStart); switch (type) { case NoteType.GroundLeft: { indicator = new Vector3(-375, -150, 0); GetComponent <MeshRenderer>().material = leftMaterial; break; } case NoteType.GroundRight: { indicator = new Vector3(375, -150, 0); GetComponent <MeshRenderer>().material = rightMaterial; break; } case NoteType.SkyLeft: { indicator = new Vector3(-375, 200, 0); break; } case NoteType.SkyRight: { indicator = new Vector3(375, 200, 0); break; } default: { break; } } }
void PlayerInputted(NoteType type, NoteDir dir) { //Map Maker Timer //Debug.Log("Hit:" + songCurrentPosInBeats.ToString("F2")); //mark the song position where the player hit float hit = songCurrentPosInBeats; //are there any notes to be hit if (notesOnScreen.Count > 0) { // Get the current note Note currentNote = notesOnScreen.Peek(); // calculate the timing between the player hit and the note's beat float hitTiming = currentNote.beat - hit; bool playerHit = false; bool dirNote = false; if (currentNote.dir != NoteDir.None) { dirNote = true; } if (dirNote) { if (currentNote.type == type && currentNote.dir == dir) { playerHit = true; } } else { if (currentNote.type == type) { playerHit = true; } } //if the note type of the current note is equal to button hit if (playerHit) { //if the hit timing is within the positive and negative bounds of the hit offset if (hitTiming <= hitOffset && hitTiming >= -hitOffset) { //player hit the note currentNote.gameObject.SetActive(false); playerScore += hitScore; playerCombo++; StartCoroutine(IndicatorSlow(comboIndicator)); StartCoroutine(IndicatorPosition(hitIndicator, currentNote.indicator)); notesOnScreen.Dequeue(); AddHealth(hitHP); hitCount++; } //else if the hit timing is within the positive and negative bounds of the near offset else if (hitTiming <= nearOffset && hitTiming >= -nearOffset) { //player neared the note currentNote.gameObject.SetActive(false); playerScore += nearScore; playerCombo++; StartCoroutine(IndicatorSlow(comboIndicator)); notesOnScreen.Dequeue(); //if the hit timing was positive if (hitTiming > 0) { //player hit the note early earlyCount++; StartCoroutine(IndicatorFast(earlyIndicator)); } else { //player hit the note late lateCount++; StartCoroutine(IndicatorFast(lateIndicator)); } } } //else if the hit timing is less than the near off set- they were going for that note but didnt hit the right button else if (hitTiming < nearOffset) { //didnt hit the right button currentNote.gameObject.SetActive(false); AddHealth(missHP); missCount++; playerCombo = 0; StartCoroutine(IndicatorPosition(wrongIndicator, currentNote.indicator)); notesOnScreen.Dequeue(); } } }