Prep for main gameplay

This commit is contained in:
Thastertyn 2024-06-13 14:46:43 +02:00
parent 079c01b01c
commit e56da61974
3 changed files with 44 additions and 0 deletions

View File

@ -4,8 +4,10 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UIElements;
using System.Linq;
using UITypes;
using BangerTypes;
public class Game : MonoBehaviour
{
@ -19,6 +21,9 @@ public class Game : MonoBehaviour
string totalDuration;
bool repeatRoutine = true;
Song song = null;
Note[] activeNotes;
void Awake()
{
@ -35,6 +40,21 @@ public class Game : MonoBehaviour
menu.GameElem.UpdateVisualizers(specData, bassStrength);
UpdateTimestamp();
GetNotes();
}
public void GetNotes()
{
float timestamp = manager.source.time;
activeNotes = song.Notes.Where(note => note.t >= timestamp && timestamp + 1f <= note.t).ToArray();
if(activeNotes.Length > 0)
{
Debug.Log("Found some notes");
}
menu.GameElem.UpdateNotes(activeNotes);
}
IEnumerator GameLoop()
@ -48,6 +68,7 @@ public class Game : MonoBehaviour
public void LoadSong(SongEntry song)
{
this.song = song.Song;
totalDuration = song.Song.Duration;
manager.source.clip = song.Song.Clip;

View File

@ -7,6 +7,7 @@ using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UIElements;
using BangerTypes;
namespace UITypes
{
@ -30,6 +31,11 @@ namespace UITypes
private VisualElement upUpcomingColumn;
public VisualElement downUpcomingColumn;
private bool leftActive = false;
private bool rightActive = false;
private bool downActive = false;
private bool upActive = false;
private Label score;
private Label songTime;
@ -97,6 +103,19 @@ namespace UITypes
songTime.text = time;
}
public void UpdateNotes(Note[] notes)
{
leftActive = notes.Where(note => note.a == "left").Count() > 0;
rightActive = notes.Where(note => note.a == "right").Count() > 0;
upActive = notes.Where(note => note.a == "up").Count() > 0;
downActive = notes.Where(note => note.a == "down").Count() > 0;
leftUpcomingColumn.EnableInClassList("ColumnActive", leftActive);
rightUpcomingColumn.EnableInClassList("ColumnActive", rightActive);
downUpcomingColumn.EnableInClassList("ColumnActive", downActive);
upUpcomingColumn.EnableInClassList("ColumnActive", upActive);
}
void OnKeyDown(KeyDownEvent ev)
{
if (ev.keyCode == KeyCode.Escape)

View File

@ -78,3 +78,7 @@
background-image: url('project://database/Assets/Images/right.png');
margin-left: 35%;
}
.ColumnActive {
background-color: green;
}