get background (hit area) animations working
This commit is contained in:
@@ -18,7 +18,7 @@ namespace WacK.Data.Chart
|
||||
public SortedList<float, List<NotePlay>> playNotes { get; private set; }
|
||||
public SortedList<float, NoteEvent<(int, int)>> timeSigChgs { get; private set; }
|
||||
public SortedList<float, NoteEvent<float>> tempoChgs { get; private set; }
|
||||
public SortedList<float, NoteEvent<int>> events { get; private set; }
|
||||
public SortedList<float, List<NoteEvent<int>>> events { get; private set; }
|
||||
|
||||
public Chart(string chartPath)
|
||||
{
|
||||
@@ -244,7 +244,6 @@ namespace WacK.Data.Chart
|
||||
}
|
||||
else
|
||||
{
|
||||
// only add notes that aren't part of the hold
|
||||
if (!playNotes.ContainsKey(curTime))
|
||||
{
|
||||
playNotes[curTime] = new List<NotePlay>();
|
||||
@@ -270,11 +269,15 @@ namespace WacK.Data.Chart
|
||||
this.timeSigChgs[curTime] = neii;
|
||||
}
|
||||
|
||||
// NoteEvent<int>
|
||||
// NoteEvent<int> -- BG Change
|
||||
var nei = curNote as NoteEvent<int>;
|
||||
if (nei != null)
|
||||
{
|
||||
this.events[curTime] = nei;
|
||||
if (!events.ContainsKey(curTime))
|
||||
{
|
||||
events[curTime] = new List<NoteEvent<int>>();
|
||||
}
|
||||
events[curTime].Add(nei);
|
||||
}
|
||||
|
||||
// update previous states
|
||||
|
||||
@@ -63,10 +63,14 @@ namespace WacK.Scenes
|
||||
public Viewport rightViewport;
|
||||
|
||||
private Chart chart;
|
||||
// Indices point to the NEXT thing to look for. We process that thing once
|
||||
// the song time is at or later than the thing's time.
|
||||
private int chordNextIdx = 0;
|
||||
private int eventNextIdx = 0;
|
||||
|
||||
// base scroll speed, which we can apply multipliers on
|
||||
public static readonly float BASE_PIXELS_PER_SECOND = 800;
|
||||
public static float scrollPxPerSec
|
||||
public static float ScrollPxPerSec
|
||||
{
|
||||
get
|
||||
{
|
||||
@@ -82,17 +86,19 @@ namespace WacK.Scenes
|
||||
|
||||
// parse mer and create chart for current play
|
||||
chart = new(playParams.chartPath);
|
||||
RealizeChart();
|
||||
InstantiateChartVisuals();
|
||||
|
||||
// audio setup
|
||||
// // audio setup
|
||||
bgmController.LoadFromUser(playParams.soundPath);
|
||||
bgmController.Play();
|
||||
|
||||
// TestBGAnim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates necessary notes onto noteDisplay for the player to see.
|
||||
/// </summary>
|
||||
private void RealizeChart()
|
||||
private void InstantiateChartVisuals()
|
||||
{
|
||||
foreach (var msNote in chart.playNotes)
|
||||
{
|
||||
@@ -128,21 +134,76 @@ namespace WacK.Scenes
|
||||
}
|
||||
nNote.Init(note);
|
||||
var nPos = nNote.Position;
|
||||
nPos.Y = msNote.Key * -scrollPxPerSec;
|
||||
nPos.Y = msNote.Key * -ScrollPxPerSec;
|
||||
nNote.Position = nPos;
|
||||
noteDisplay.AddChild(nNote);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
double time = bgmController.GetPlaybackPosition() + AudioServer.GetTimeSinceLastMix() - AudioServer.GetOutputLatency();
|
||||
/// <summary>
|
||||
/// Process current game state. Should only run if playing a chart and unpaused.
|
||||
/// </summary>
|
||||
private void PlayLoop()
|
||||
{
|
||||
float time = bgmController.CurTime;
|
||||
|
||||
// check next event
|
||||
while (eventNextIdx < chart.events.Count && time >= chart.events.Keys[eventNextIdx])
|
||||
{
|
||||
var t = chart.events.Keys[eventNextIdx];
|
||||
var l = chart.events[t];
|
||||
|
||||
foreach (var e in l)
|
||||
{
|
||||
GD.Print($"Passed event {e.type}(pos={e.pos},size={e.size}) at {t}");
|
||||
switch (e.type)
|
||||
{
|
||||
case NoteEventType.BGAdd:
|
||||
background.SetSegments((int)e.pos, (int)e.size, true, (DrawDirection)e.value);
|
||||
break;
|
||||
case NoteEventType.BGRem:
|
||||
background.SetSegments((int)e.pos, (int)e.size, false, (DrawDirection)e.value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
eventNextIdx++;
|
||||
}
|
||||
|
||||
// set scroll
|
||||
var nPos = noteDisplay.Position;
|
||||
nPos.Y = bgmController.CurTime * scrollPxPerSec;
|
||||
nPos.Y = time * ScrollPxPerSec;
|
||||
noteDisplay.Position = nPos;
|
||||
scrollDisplay.Position = nPos;
|
||||
}
|
||||
|
||||
private async void TestBGAnim()
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
|
||||
// clockwise all
|
||||
background.SetSegments(0, 60, true, DrawDirection.Clockwise);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
background.SetSegments(0, 60, false, DrawDirection.Clockwise);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
|
||||
// counterclockwise all
|
||||
background.SetSegments(0, 60, true, DrawDirection.CounterClockwise);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
background.SetSegments(0, 60, false, DrawDirection.CounterClockwise);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
|
||||
// center all
|
||||
background.SetSegments(0, 60, true, DrawDirection.Center);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
background.SetSegments(0, 60, false, DrawDirection.Center);
|
||||
await ToSignal(GetTree().CreateTimer(1.5), SceneTreeTimer.SignalName.Timeout);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
PlayLoop();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
||||
@@ -18,21 +18,22 @@ namespace WacK.Things.TunnelObjects
|
||||
public partial class Background : Node
|
||||
{
|
||||
[Export]
|
||||
private ColorRect firstSegment;
|
||||
private List<ColorRect> segments = new(60);
|
||||
private TextureRect firstSegment;
|
||||
private List<TextureRect> segments = new(60);
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
var segmentsNode = FindChild("Segment Masks");
|
||||
firstSegment.Visible = false;
|
||||
segments.Add(firstSegment);
|
||||
for (int i = 1; i < 60; ++i)
|
||||
{
|
||||
var n = (ColorRect)firstSegment.Duplicate();
|
||||
var n = (TextureRect)firstSegment.Duplicate();
|
||||
segmentsNode.AddChild(n);
|
||||
segments.Add(n);
|
||||
n.Name = i.ToString();
|
||||
n.SetPosition(new Vector2(i * Constants.BASE_2D_RESOLUTION / 60, 0));
|
||||
n.SetPosition(new Vector2(i * Constants.BASE_2D_RESOLUTION / 60, Constants.BASE_2D_RESOLUTION));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ namespace WacK.Things.TunnelObjects
|
||||
// GD.Print($"{direction} = {state}. Even? {size % 2 == 0}");
|
||||
|
||||
double timer = 0;
|
||||
double time = .5f;
|
||||
double time = .1f;
|
||||
|
||||
int centerSeg = pos + size/2;
|
||||
while (timer < time)
|
||||
@@ -79,6 +80,7 @@ namespace WacK.Things.TunnelObjects
|
||||
}
|
||||
await ToSignal(GetTree(), "process_frame");
|
||||
}
|
||||
GD.Print("Finished BG anim!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace WacK.Things.TunnelObjects
|
||||
{
|
||||
longThing = new Node2D();
|
||||
holdScroll.AddChild(longThing);
|
||||
longThing.Position = new Vector2(0, (float)-holdNoteData.time * Play.scrollPxPerSec);
|
||||
longThing.Position = new Vector2(0, (float)-holdNoteData.time * Play.ScrollPxPerSec);
|
||||
|
||||
if (holdNoteData.points.Count > 0)
|
||||
{
|
||||
@@ -31,7 +31,7 @@ namespace WacK.Things.TunnelObjects
|
||||
float segmentPos = 0;
|
||||
foreach (var (_, curNote) in holdNoteData.points)
|
||||
{
|
||||
var curLength = Play.scrollPxPerSec * (float)(curNote.time - lastHold.time);
|
||||
var curLength = Play.ScrollPxPerSec * (float)(curNote.time - lastHold.time);
|
||||
var segment = CreateSegment(lastHold, curNote);
|
||||
longThing.AddChild(segment);
|
||||
segment.Position = new Vector2(0, segmentPos);
|
||||
@@ -50,7 +50,7 @@ namespace WacK.Things.TunnelObjects
|
||||
{
|
||||
float minuteSize = Constants.BASE_2D_RESOLUTION / 60;
|
||||
|
||||
var length = Play.scrollPxPerSec * (float)(destination.time - origin.time);
|
||||
var length = Play.ScrollPxPerSec * (float)(destination.time - origin.time);
|
||||
var verts = new Vector2[4];
|
||||
|
||||
int originPos;
|
||||
|
||||
Reference in New Issue
Block a user