1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-27 23:46:45 +00:00

less note stutter

This commit is contained in:
Cameron Taylor 2020-10-24 02:19:13 -07:00
parent 99b51a3f03
commit dc6686e095
6 changed files with 89 additions and 39 deletions

View file

@ -1,5 +1,6 @@
package;
import Song.SwagSong;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.addons.display.FlxGridOverlay;
@ -59,7 +60,7 @@ class ChartingState extends MusicBeatState
var gridBG:FlxSprite;
var _song:Song;
var _song:SwagSong;
var typingShit:FlxInputText;
/*
@ -79,7 +80,7 @@ class ChartingState extends MusicBeatState
_song = PlayState.SONG;
else
{
_song = new Song(curSong, [], Conductor.bpm, 0);
_song = Song.loadFromJson('tutorial');
}
addSection();

View file

@ -10,6 +10,7 @@ class Conductor
public static var crochet:Float = ((60 / bpm) * 1000); // beats in milliseconds
public static var stepCrochet:Float = crochet / 4; // steps in milliseconds
public static var songPosition:Float;
public static var lastSongPos:Float;
public static var offset:Float = 0;
public static var safeFrames:Int = 10;

View file

@ -3,6 +3,7 @@ package;
import flixel.FlxG;
import flixel.addons.transition.FlxTransitionableState;
import flixel.addons.ui.FlxUIState;
import flixel.util.FlxTimer;
class MusicBeatState extends FlxUIState
{
@ -17,6 +18,10 @@ class MusicBeatState extends FlxUIState
override function create()
{
#if (!web)
TitleState.soundExt = '.ogg';
#end
super.create();
}

View file

@ -1,6 +1,9 @@
package;
import Section.SwagSection;
import Song.SwagSong;
import flixel.FlxG;
import flixel.FlxGame;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.FlxState;
@ -29,7 +32,7 @@ using StringTools;
class PlayState extends MusicBeatState
{
public static var curLevel:String = 'Bopeebo';
public static var SONG:Song;
public static var SONG:SwagSong;
private var vocals:FlxSound;
@ -239,8 +242,15 @@ class PlayState extends MusicBeatState
}, 5);
}
var previousFrameTime:Int = 0;
var lastReportedPlayheadPosition:Int = 0;
var songTime:Float = 0;
function startSong():Void
{
previousFrameTime = FlxG.game.ticks;
lastReportedPlayheadPosition = 0;
startingSong = false;
FlxG.sound.playMusic("assets/music/" + SONG.song + "_Inst" + TitleState.soundExt);
vocals.play();
@ -270,7 +280,7 @@ class PlayState extends MusicBeatState
notes = new FlxTypedGroup<Note>();
add(notes);
var noteData:Array<Section> = [];
var noteData:Array<SwagSection>;
// NEW SHIT
noteData = songData.notes;
@ -378,8 +388,6 @@ class PlayState extends MusicBeatState
return FlxSort.byValues(FlxSort.ASCENDING, Obj1.strumTime, Obj2.strumTime);
}
var sortedNotes:Bool = false;
private function generateStaticArrows(player:Int):Void
{
for (i in 0...4)
@ -475,6 +483,9 @@ class PlayState extends MusicBeatState
{
super.update(elapsed);
// trace("SONG POS: " + Conductor.songPosition);
// FlxG.sound.music.pitch = 2;
if (FlxG.keys.justPressed.ENTER)
{
persistentUpdate = false;
@ -495,7 +506,7 @@ class PlayState extends MusicBeatState
healthHeads.setGraphicSize(Std.int(FlxMath.lerp(100, healthHeads.width, 0.98)));
healthHeads.x = healthBar.x + (healthBar.width * (FlxMath.remapToRange(healthBar.percent, 0, 100, 100, 0) * 0.01)) - (healthHeads.width / 2);
if (healthBar.percent < 10)
if (healthBar.percent < 20)
healthHeads.animation.play('unhealthy');
else
healthHeads.animation.play('healthy');
@ -515,8 +526,24 @@ class PlayState extends MusicBeatState
}
}
else
{
Conductor.songPosition = FlxG.sound.music.time;
songTime += FlxG.game.ticks - previousFrameTime;
previousFrameTime = FlxG.game.ticks;
// Interpolation type beat
if (Conductor.lastSongPos != Conductor.songPosition)
{
songTime = (songTime + Conductor.songPosition) / 2;
Conductor.lastSongPos = Conductor.songPosition;
// Conductor.songPosition += FlxG.elapsed * 1000;
// trace('MISSED FRAME');
}
// Conductor.lastSongPos = FlxG.sound.music.time;
}
var playerTurn:Int = 0;
if (sectionLengths.length > curSection)
playerTurn = totalBeats % (sectionLengths[curSection] * 8);
@ -531,7 +558,7 @@ class PlayState extends MusicBeatState
{
if (curBeat % 4 == 0)
{
trace(PlayState.SONG.notes[Std.int(curStep / 16)].mustHitSection);
// trace(PlayState.SONG.notes[Std.int(curStep / 16)].mustHitSection);
}
if (camFollow.x != dad.getMidpoint().x + 150 && !PlayState.SONG.notes[Std.int(curStep / 16)].mustHitSection)
@ -598,9 +625,6 @@ class PlayState extends MusicBeatState
if (unspawnNotes[0] != null)
{
FlxG.watch.addQuick('spsa', unspawnNotes[0].strumTime);
FlxG.watch.addQuick('weed', Conductor.songPosition);
if (unspawnNotes[0].strumTime - Conductor.songPosition < 1500)
{
var dunceNote:Note = unspawnNotes[0];
@ -645,7 +669,7 @@ class PlayState extends MusicBeatState
daNote.destroy();
}
daNote.y = (strumLine.y - (Conductor.songPosition - daNote.strumTime) * (0.45 * PlayState.SONG.speed));
daNote.y = (strumLine.y - (songTime - daNote.strumTime) * (0.45 * PlayState.SONG.speed));
if (daNote.y < -daNote.height)
{
@ -662,10 +686,6 @@ class PlayState extends MusicBeatState
notes.remove(daNote, true);
daNote.destroy();
}
// one time sort
if (!sortedNotes)
notes.sort(FlxSort.byY, FlxSort.DESCENDING);
});
}
@ -676,8 +696,6 @@ class PlayState extends MusicBeatState
{
var noteDiff:Float = Math.abs(strumtime - Conductor.songPosition);
trace(noteDiff);
// boyfriend.playAnim('hey');
// vocals.volume = 1;
@ -767,9 +785,10 @@ class PlayState extends MusicBeatState
daLoop++;
}
trace(combo);
trace(seperatedScore);
/*
trace(combo);
trace(seperatedScore);
*/
coolText.text = Std.string(seperatedScore);
// add(coolText);
@ -876,7 +895,7 @@ class PlayState extends MusicBeatState
}
*/
FlxG.watch.addQuick('asdfa', upP);
// FlxG.watch.addQuick('asdfa', upP);
if ((upP || rightP || downP || leftP) && !boyfriend.stunned && generatedMusic)
{
var possibleNotes:Array<Note> = [];
@ -894,11 +913,6 @@ class PlayState extends MusicBeatState
{
for (daNote in possibleNotes)
{
var purp:Int = Note.PURP_NOTE;
var green:Int = Note.GREEN_NOTE;
var red:Int = Note.RED_NOTE;
var blue:Int = Note.BLUE_NOTE;
switch (daNote.noteData)
{
case 2: // NOTES YOU JUST PRESSED
@ -931,7 +945,7 @@ class PlayState extends MusicBeatState
if ((up || right || down || left) && !boyfriend.stunned && generatedMusic)
{
notes.forEach(function(daNote:Note)
notes.forEachAlive(function(daNote:Note)
{
if (daNote.canBeHit && daNote.mustPress && daNote.isSustainNote)
{
@ -1144,6 +1158,14 @@ class PlayState extends MusicBeatState
{
super.beatHit();
if (generatedMusic)
{
notes.forEachAlive(function(daNote:Note)
{
notes.sort(FlxSort.byY, FlxSort.DESCENDING);
});
}
if (camZooming && FlxG.camera.zoom < 1.35 && totalBeats % 4 == 0)
FlxG.camera.zoom += 0.025;

View file

@ -1,5 +1,13 @@
package;
typedef SwagSection =
{
var sectionNotes:Array<Dynamic>;
var lengthInSteps:Int;
var typeOfSection:Int;
var mustHitSection:Bool;
}
class Section
{
public var sectionNotes:Array<Dynamic> = [];

View file

@ -1,14 +1,30 @@
package;
import Section.SwagSection;
import haxe.Json;
import haxe.format.JsonParser;
import lime.utils.Assets;
using StringTools;
typedef SwagSong =
{
var song:String;
var notes:Array<SwagSection>;
var bpm:Int;
var sections:Int;
var sectionLengths:Array<Dynamic>;
var needsVoices:Bool;
var speed:Float;
var player1:String;
var player2:String;
}
class Song
{
public var song:String;
public var notes:Array<Section>;
public var notes:Array<SwagSection>;
public var bpm:Int;
public var sections:Int;
public var sectionLengths:Array<Dynamic> = [];
@ -31,14 +47,8 @@ class Song
}
}
public static function loadFromJson(jsonInput:String):Song
public static function loadFromJson(jsonInput:String):SwagSong
{
var daNotes:Array<Section> = [];
var daBpm:Int = 0;
var daSections:Int = 0;
var daSong:String = '';
var daSectionLengths:Array<Int> = [];
var rawJson = Assets.getText('assets/data/' + jsonInput.toLowerCase() + '/' + jsonInput.toLowerCase() + '.json').trim();
while (!rawJson.endsWith("}"))
@ -47,9 +57,12 @@ class Song
// LOL GOING THROUGH THE BULLSHIT TO CLEAN IDK WHATS STRANGE
}
var swagShit:SwagSong = cast Json.parse(rawJson).song;
trace(swagShit.notes[0]);
// FIX THE CASTING ON WINDOWS/NATIVE
var songData:Song = Json.parse(rawJson).song; // Windows???
trace(songData);
// Windows???
// trace(songData);
// trace('LOADED FROM JSON: ' + songData.notes);
/*
@ -65,6 +78,6 @@ class Song
daBpm = songData.bpm;
daSectionLengths = songData.sectionLengths; */
return songData;
return swagShit;
}
}