diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs index 06532ad..9e19cf3 100644 --- a/Scripts/Game/Game.cs +++ b/Scripts/Game/Game.cs @@ -28,6 +28,8 @@ public class Game : MonoBehaviour List activeNotes = new(); + public int Score { get; set; } = 0; + void Awake() { menu = GetComponent(); @@ -54,8 +56,7 @@ public class Game : MonoBehaviour foreach (Note note in newNotes) { - Debug.Log("Removing note"); - Debug.Log(allNotes.Remove(note)); + allNotes.Remove(note); } menu.GameElem.UpdateNotes(newNotes); diff --git a/Scripts/UI Types/GameElement.cs b/Scripts/UI Types/GameElement.cs index d6a868e..5db0537 100644 --- a/Scripts/UI Types/GameElement.cs +++ b/Scripts/UI Types/GameElement.cs @@ -8,6 +8,7 @@ using UnityEngine; using UnityEngine.UIElements; using BangerTypes; +using TagLib.Ape; namespace UITypes { @@ -120,7 +121,7 @@ namespace UITypes foreach (var note in notes) { NoteElement el = new(); - el.Init(note, leftUpcomingColumn.resolvedStyle.height); + el.Init(note); activeNoteElements.Add(el); if (note.a == "left") @@ -146,7 +147,7 @@ namespace UITypes { foreach (var note in activeNoteElements) { - note.UpdateMargin(timestamp); + note.UpdateMargin(timestamp, leftUpcomingColumn.resolvedStyle.height); } } @@ -157,6 +158,29 @@ namespace UITypes if (note.CheckSelf(timestamp)) { activeNoteElements.Remove(note); + + if (note.note.a == "left") + { + leftUpcomingColumn.Remove(note); + } + else if (note.note.a == "right") + { + rightUpcomingColumn.Remove(note); + } + else if (note.note.a == "up") + { + upUpcomingColumn.Remove(note); + } + else if (note.note.a == "down") + { + downUpcomingColumn.Remove(note); + } + else + { + continue; + } + + AddScore(-1); } } } @@ -174,6 +198,58 @@ namespace UITypes if (button == null) return; button.AddToClassList("GameButtonClicked"); + + CheckNotesOnClick(ev.keyCode); + } + + void CheckNotesOnClick(KeyCode keyCode) + { + List activeNotesInCurrentColumn = activeNoteElements + .Where(note => note.note.a + "arrow" == keyCode.ToString().ToLower()) + .OrderBy(note => note.note.t) + .ToList(); + + foreach (NoteElement note in activeNotesInCurrentColumn) + { + float scoreTime = note.note.t - game.manager.source.time; + if (scoreTime < 0.1f) + { + AddScore(scoreTime); + activeNoteElements.Remove(note); + + if (note.note.a == "left") + { + leftUpcomingColumn.Remove(note); + } + else if (note.note.a == "right") + { + rightUpcomingColumn.Remove(note); + } + else if (note.note.a == "up") + { + upUpcomingColumn.Remove(note); + } + else if (note.note.a == "down") + { + downUpcomingColumn.Remove(note); + } + return; + } + } + AddScore(-1); + } + + void AddScore(float accuracy) + { + if (accuracy == -1) + { + game.Score -= 10; + } + else + { + game.Score += 100 - (int) (accuracy * 1000); + } + score.text = "SCORE: " + game.Score.ToString(); } void OnKeyUp(KeyUpEvent ev) diff --git a/Scripts/UI Types/NoteElement.cs b/Scripts/UI Types/NoteElement.cs index 1e6b4de..dc419dc 100644 --- a/Scripts/UI Types/NoteElement.cs +++ b/Scripts/UI Types/NoteElement.cs @@ -16,9 +16,8 @@ namespace UITypes public Note note; public float ColumnHeight; - public void Init(Note note, float columnHeight) + public void Init(Note note) { - this.ColumnHeight = columnHeight; AddToClassList("NoteElement"); AddToClassList(note.a[..1].ToUpper() + note.a[1..] + "Note"); @@ -26,9 +25,9 @@ namespace UITypes this.note = note; } - public void UpdateMargin(float timestamp) + public void UpdateMargin(float timestamp, float ColumnHeight) { - style.marginTop = new(ColumnHeight - (note.t - timestamp) * 1000 - resolvedStyle.height); + style.marginTop = new(((note.t - timestamp) * -1000) - resolvedStyle.height + ColumnHeight); } public bool CheckSelf(float timestamp) diff --git a/UI/Game.uss b/UI/Game.uss index cd64584..ca50be9 100644 --- a/UI/Game.uss +++ b/UI/Game.uss @@ -22,7 +22,7 @@ } .GameButtonClicked { - background-color: red; + background-color: gray; scale: 1.1; }