Score now works
This commit is contained in:
parent
27082a717c
commit
40d5446e81
@ -28,6 +28,8 @@ public class Game : MonoBehaviour
|
||||
|
||||
List<Note> activeNotes = new();
|
||||
|
||||
public int Score { get; set; } = 0;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
menu = GetComponent<MainMenu>();
|
||||
@ -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);
|
||||
|
@ -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<NoteElement> 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)
|
||||
|
@ -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)
|
||||
|
@ -22,7 +22,7 @@
|
||||
}
|
||||
|
||||
.GameButtonClicked {
|
||||
background-color: red;
|
||||
background-color: gray;
|
||||
scale: 1.1;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user