diff --git a/source/funkin/objects/NotesGroup.hx b/source/funkin/objects/NotesGroup.hx index 9f1688fa..f3676561 100644 --- a/source/funkin/objects/NotesGroup.hx +++ b/source/funkin/objects/NotesGroup.hx @@ -113,6 +113,8 @@ class NotesGroup extends Group boyfriend = game.boyfriend; dad = game.dad; } + + initStrumline(); Conductor.mapBPMChanges(SONG); Conductor.bpm = SONG.bpm; @@ -205,19 +207,21 @@ class NotesGroup extends Group }); } - public function init(startPos:Float = -5000) { + function initStrumline() { StrumLineGroup.strumLineY = getPref('downscroll') ? FlxG.height - 150 : 50; - opponentStrums = new StrumLineGroup(0, skipStrumIntro); + opponentStrums = new StrumLineGroup(0); add(opponentStrums); - playerStrums = new StrumLineGroup(1, skipStrumIntro); + playerStrums = new StrumLineGroup(1); add(playerStrums); grpNoteSplashes = new SplashGroup(); add(grpNoteSplashes); + } - //Make Song + // Make the song + public function init(startPos:Float = -5000) { Conductor.songPosition = startPos; generateSong(); } diff --git a/source/funkin/objects/note/StrumLineGroup.hx b/source/funkin/objects/note/StrumLineGroup.hx index 7404a780..462ead86 100644 --- a/source/funkin/objects/note/StrumLineGroup.hx +++ b/source/funkin/objects/note/StrumLineGroup.hx @@ -7,28 +7,28 @@ class StrumLineGroup extends TypedSpriteGroup { var startX:Float = 0; var offsetY:Float = 0; - public function new(p:Int = 0, skipIntro:Bool = false, lanes:Int = Conductor.NOTE_DATA_LENGTH) { + public function new(p:Int = 0, lanes:Int = Conductor.NOTE_DATA_LENGTH) { super(9); startX = NoteUtil.noteWidth * 0.666 + (FlxG.width * 0.5) * p; offsetY = Preferences.getPref('downscroll') ? 10 : -10; final isPlayer:Bool = p == 1; for (i in 0...lanes) { - final strumNote = addStrum(i, skipIntro); + final strumNote = addStrum(i); ModdingUtil.addCall('generateStrum', [strumNote, isPlayer]); } } public static final DEFAULT_CONTROL_CHECKS:ArrayBool> = [ - function (t:InputType) return Controls.getKey('NOTE_LEFT', t), - function (t:InputType) return Controls.getKey('NOTE_DOWN', t), - function (t:InputType) return Controls.getKey('NOTE_UP', t), - function (t:InputType) return Controls.getKey('NOTE_RIGHT', t), + (t:InputType) -> return Controls.getKey('NOTE_LEFT', t), + (t:InputType) -> return Controls.getKey('NOTE_DOWN', t), + (t:InputType) -> return Controls.getKey('NOTE_UP', t), + (t:InputType) -> return Controls.getKey('NOTE_RIGHT', t) ]; static inline var seperateWidth:Int = NoteUtil.noteWidth + 5; - public function insertStrum(position:Int = 0, skipIntro:Bool = true) { + public function insertStrum(position:Int = 0) { if (members.length >= 9) return null; // STOP for (i in position...members.length) { final strum = members[i]; @@ -36,10 +36,18 @@ class StrumLineGroup extends TypedSpriteGroup { strum.x += seperateWidth; strum.ID++; } - return addStrum(position, skipIntro); + return addStrum(position); } - public function addStrum(noteData:Int = 0, skipIntro:Bool = true) { + public function introStrums() { + members.fastForEach((strum, i) -> { + strum.alpha = 0; + strum.y += offsetY; + FlxTween.tween(strum, {y: strum.y - offsetY, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * strum.noteData)}); + }); + } + + public function addStrum(noteData:Int = 0) { if (members.length >= 9) return null; // STOP final strumX:Float = startX + seperateWidth * noteData; final strumNote:NoteStrum = new NoteStrum(strumX, strumLineY, noteData); @@ -48,11 +56,6 @@ class StrumLineGroup extends TypedSpriteGroup { strumNote.scrollFactor.set(); add(strumNote); initPos.push(strumNote.getPosition()); - - if (!skipIntro) { - strumNote.alpha = 0; - strumNote.y += offsetY; - } if (noteData < DEFAULT_CONTROL_CHECKS.length) { strumNote.controlFunction = DEFAULT_CONTROL_CHECKS[noteData]; diff --git a/source/funkin/states/PlayState.hx b/source/funkin/states/PlayState.hx index 6f93cf89..76db52a8 100644 --- a/source/funkin/states/PlayState.hx +++ b/source/funkin/states/PlayState.hx @@ -388,8 +388,8 @@ class PlayState extends MusicBeatState startedCountdown = seenCutscene = true; if (!notesGroup.skipStrumIntro) { - notesGroup.strumLineNotes.fastForEach((strum, i) -> - FlxTween.tween(strum, {y: StrumLineGroup.strumLineY, alpha: 1}, 1, {ease: FlxEase.circOut, startDelay: 0.5 + (0.2 * strum.noteData)})); + notesGroup.opponentStrums.introStrums(); + notesGroup.playerStrums.introStrums(); } Conductor.songPosition = -Conductor.crochet * 5; diff --git a/source/funkin/util/frontend/CutsceneManager.hx b/source/funkin/util/frontend/CutsceneManager.hx index c972583a..3c0711e1 100644 --- a/source/funkin/util/frontend/CutsceneManager.hx +++ b/source/funkin/util/frontend/CutsceneManager.hx @@ -18,15 +18,15 @@ abstract class EventHandler extends flixel.FlxBasic events.sort((a, b) -> Std.int(a.time - b.time)); } - public function pushStep(step:Int = 0, callback:()->Void) { + public function pushStep(step:Float = 0, callback:()->Void) { pushEvent(step * Conductor.stepCrochetMills, callback); } - public function pushBeat(beat:Int = 0, callback:()->Void) { + public function pushBeat(beat:Float = 0, callback:()->Void) { pushEvent(beat * Conductor.crochetMills, callback); } - public function pushSection(section:Int = 0, callback:()->Void) { + public function pushSection(section:Float = 0, callback:()->Void) { pushEvent(section * Conductor.sectionCrochetMills, callback); //Song.getSectionTime(PlayState.SONG, section) TODO: maybe?? } @@ -54,12 +54,16 @@ abstract class EventHandler extends flixel.FlxBasic active = true; } - override function update(elapsed:Float) { - super.update(elapsed); - position += elapsed * 1000; + override function update(elapsed:Float) + { + updatePosition(); callEvents(); } + function updatePosition() { + position += (FlxG.elapsed * 1000); + } + public var destroyOnComplete:Bool = true; function callEvents():Void { diff --git a/source/funkin/util/frontend/ModchartManager.hx b/source/funkin/util/frontend/ModchartManager.hx index 72589fe1..fd55f076 100644 --- a/source/funkin/util/frontend/ModchartManager.hx +++ b/source/funkin/util/frontend/ModchartManager.hx @@ -2,7 +2,8 @@ package funkin.util.frontend; import funkin.objects.note.StrumLineGroup; import funkin.util.frontend.CutsceneManager; -class ModchartManager extends EventHandler { +class ModchartManager extends EventHandler +{ private var strumLines:Map = []; public function new():Void { @@ -19,6 +20,10 @@ class ModchartManager extends EventHandler { return new ModchartManager(); } + /** + * GETTING / SETTING STRUMS + **/ + inline public function setStrumLine(id:Int = 0, strumline:StrumLineGroup):Void { strumLines.set(id, strumline); } @@ -31,10 +36,24 @@ class ModchartManager extends EventHandler { return getStrumLine(strumlineID)?.members[strumID] ?? null; } + /** + * STRUM MOVEMENT + **/ + inline public function setStrumPos(l:Int = 0, s:Int = 0, ?X:Float, ?Y:Float):Void { getStrum(l,s).setPosition(X,Y); } + inline public function moveStrum(l:Int = 0, s:Int = 0, X:Float = 0, Y:Float = 0):Void { + var strum = getStrum(l, s); + strum.x += X; + strum.y += Y; + } + + inline public function offsetStrum(l:Int = 0, s:Int = 0, X:Float = 0, Y:Float = 0):Void { + moveStrum(l, s, -X, -Y); + } + inline public function tweenStrum(l:Int = 0, s:Int = 0, ?values:Dynamic, time:Float = 1.0, ?settings:Dynamic) { return FlxTween.tween(getStrum(l, s), values, time, settings); } @@ -43,18 +62,22 @@ class ModchartManager extends EventHandler { return tweenStrum(l,s, {x: X, y:Y}, time, {ease: ease ?? FlxEase.linear}); } + /** + * STRUM EFFECTS + **/ + + // TODO: add the typical modchart effects like drunk, wavy n all that shit + inline public function setStrumLineSin(l:Int = 0, offPerNote:Float = 0.0, size:Float = 50.0, ?startY:Float) { - for (i in 0... getStrumLine(l).members.length) + for (i in 0...getStrumLine(l).members.length) setStrumSin(l, i, offPerNote * i, size, startY); } inline public function setStrumLineCos(l:Int = 0, offPerNote:Float = 0.0, size:Float = 50.0, ?startX:Float) { - for (i in 0... getStrumLine(l).members.length) + for (i in 0...getStrumLine(l).members.length) setStrumCos(l, i, offPerNote * i, size, startX); } - // Requires the manager to be added to the state to work - inline public function setStrumSin(l:Int = 0, s:Int = 0, off:Float = 0.0, size:Float = 50.0, ?startY:Float) { final strum = getStrum(l, s); sinStrums.remove(strum); @@ -77,15 +100,20 @@ class ModchartManager extends EventHandler { var sinStrums:Array = []; var cosStrums:Array = []; - - var timeElapsed:Float = 0.0; - var speed:Float = 1.0; + + public var speed:Float = 1.0; + var startTick:Float = 0; // Game tick the modchart started at, for cosine stuff + + override function start() { + startTick = FlxG.game.ticks; + super.start(); + } override function update(elapsed:Float) { super.update(elapsed); - timeElapsed = timeElapsed + (elapsed * speed); - timeElapsed = timeElapsed % FunkMath.DOUBLE_PI; + + final timeElapsed = ((FlxG.game.ticks - startTick) * speed * 0.0001) % FunkMath.DOUBLE_PI; if (cosStrums.length > 0) { cosStrums.fastForEach((strum, i) -> { @@ -99,4 +127,8 @@ class ModchartManager extends EventHandler { }); } } + + override function updatePosition() { + position = Conductor.songPosition; + } } \ No newline at end of file