1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-11-10 08:44:47 +00:00
Funkin/source/funkin/LatencyState.hx

152 lines
3.3 KiB
Haxe
Raw Normal View History

package funkin;
2020-10-07 01:56:14 +00:00
import flixel.FlxSprite;
2022-07-05 18:24:02 +00:00
import flixel.FlxSubState;
2020-10-07 01:56:14 +00:00
import flixel.group.FlxGroup.FlxTypedGroup;
2022-07-06 19:27:45 +00:00
import flixel.group.FlxGroup;
import flixel.math.FlxMath;
2020-10-07 01:56:14 +00:00
import flixel.text.FlxText;
2022-07-05 18:34:08 +00:00
import flixel.util.FlxColor;
import funkin.audiovis.PolygonSpectogram;
2020-10-07 01:56:14 +00:00
2022-07-05 18:24:02 +00:00
class LatencyState extends MusicBeatSubstate
2020-10-07 01:56:14 +00:00
{
var offsetText:FlxText;
var noteGrp:FlxTypedGroup<Note>;
var strumLine:FlxSprite;
2022-07-06 19:27:45 +00:00
var blocks:FlxGroup;
var songPosVis:FlxSprite;
var beatTrail:FlxSprite;
2022-07-05 18:24:02 +00:00
2020-10-07 01:56:14 +00:00
override function create()
{
2021-02-08 21:34:48 +00:00
FlxG.sound.playMusic(Paths.sound('soundTest'));
2022-07-06 19:27:45 +00:00
Conductor.bpm = 120;
2020-10-07 01:56:14 +00:00
noteGrp = new FlxTypedGroup<Note>();
add(noteGrp);
2022-07-06 19:27:45 +00:00
// var musSpec:PolygonSpectogram = new PolygonSpectogram(FlxG.sound.music, FlxColor.RED, FlxG.height, Math.floor(FlxG.height / 2));
// musSpec.x += 170;
// musSpec.scrollFactor.set();
// musSpec.waveAmplitude = 100;
// musSpec.realtimeVisLenght = 0.45;
// // musSpec.visType = FREQUENCIES;
// add(musSpec);
for (beat in 0...Math.floor(FlxG.sound.music.length / Conductor.crochet))
{
var beatTick:FlxSprite = new FlxSprite(songPosToX(beat * Conductor.crochet), FlxG.height - 15);
beatTick.makeGraphic(2, 15);
beatTick.alpha = 0.3;
add(beatTick);
}
songPosVis = new FlxSprite(0, FlxG.height - 20).makeGraphic(2, 20, FlxColor.RED);
add(songPosVis);
2022-07-05 18:34:08 +00:00
2022-07-06 19:27:45 +00:00
beatTrail = new FlxSprite(0, songPosVis.y).makeGraphic(2, 20, FlxColor.PURPLE);
beatTrail.alpha = 0.7;
add(beatTrail);
blocks = new FlxGroup();
add(blocks);
for (i in 0...8)
{
var block = new FlxSprite(2, 50 * i).makeGraphic(48, 48);
block.visible = false;
blocks.add(block);
}
2022-07-05 18:24:02 +00:00
2020-10-07 01:56:14 +00:00
for (i in 0...32)
{
var note:Note = new Note(Conductor.crochet * i, 1);
noteGrp.add(note);
}
offsetText = new FlxText();
offsetText.screenCenter();
add(offsetText);
strumLine = new FlxSprite(FlxG.width / 2, 100).makeGraphic(FlxG.width, 5);
add(strumLine);
super.create();
}
2022-07-05 18:24:02 +00:00
override function beatHit()
{
2022-07-06 19:27:45 +00:00
beatTrail.x = songPosVis.x;
if (curBeat % 8 == 0)
blocks.forEach(blok ->
{
blok.visible = false;
});
blocks.members[curBeat % 8].visible = true;
// block.visible = !block.visible;
2022-07-05 18:24:02 +00:00
super.beatHit();
}
2020-10-07 01:56:14 +00:00
override function update(elapsed:Float)
{
2022-07-06 19:27:45 +00:00
songPosVis.x = songPosToX(Conductor.songPosition);
offsetText.text = "Offset: " + Conductor.visualOffset + "ms";
offsetText.text += "\ncurStep: " + curStep;
offsetText.text += "\ncurBeat: " + curBeat;
2020-10-07 01:56:14 +00:00
Conductor.songPosition = FlxG.sound.music.time - Conductor.offset;
2022-07-06 19:27:45 +00:00
var multiply:Float = 10;
2020-10-07 01:56:14 +00:00
if (FlxG.keys.pressed.SHIFT)
2022-07-06 19:27:45 +00:00
multiply = 1;
2020-10-07 01:56:14 +00:00
if (FlxG.keys.justPressed.RIGHT)
2022-07-06 19:27:45 +00:00
{
Conductor.visualOffset += 1 * multiply;
}
2020-10-07 01:56:14 +00:00
if (FlxG.keys.justPressed.LEFT)
2022-07-06 19:27:45 +00:00
{
Conductor.visualOffset -= 1 * multiply;
}
2020-10-07 01:56:14 +00:00
if (FlxG.keys.justPressed.SPACE)
{
FlxG.sound.music.stop();
FlxG.resetState();
}
noteGrp.forEach(function(daNote:Note)
{
2022-01-22 21:53:38 +00:00
daNote.y = (strumLine.y - (Conductor.songPosition - daNote.data.strumTime) * 0.45);
2020-10-07 01:56:14 +00:00
daNote.x = strumLine.x + 30;
if (daNote.y < strumLine.y)
2022-07-05 18:24:02 +00:00
daNote.alpha = 0.5;
if (daNote.y < 0 - daNote.height)
{
daNote.alpha = 1;
// daNote.data.strumTime += Conductor.crochet * 8;
}
2020-10-07 01:56:14 +00:00
});
super.update(elapsed);
}
2022-07-06 19:27:45 +00:00
function songPosToX(pos:Float):Float
{
return FlxMath.remapToRange(pos, 0, FlxG.sound.music.length, 0, FlxG.width);
}
2020-10-07 01:56:14 +00:00
}