From 4dcf17bec2b0b3405e24d1b0594543657c3ec97e Mon Sep 17 00:00:00 2001 From: Yoshman29 <81191621+YoshiCrafter29@users.noreply.github.com> Date: Sat, 24 Dec 2022 14:35:23 +0100 Subject: [PATCH] note angle finally fucking works --- buildnumber.txt | 2 +- source/funkin/game/Note.hx | 53 +++++++++++++++---------------------- source/funkin/game/Strum.hx | 52 +++++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 54 deletions(-) diff --git a/buildnumber.txt b/buildnumber.txt index 22dbbf06..6ff562f0 100644 --- a/buildnumber.txt +++ b/buildnumber.txt @@ -1 +1 @@ -1745 \ No newline at end of file +1758 \ No newline at end of file diff --git a/source/funkin/game/Note.hx b/source/funkin/game/Note.hx index caad6a45..af2257f4 100644 --- a/source/funkin/game/Note.hx +++ b/source/funkin/game/Note.hx @@ -66,6 +66,7 @@ class Note extends FlxSprite public var noteType(get, null):String; @:dox(hide) public var __strumCameras:Array = null; + @:dox(hide) public var __strum:Strum = null; @:dox(hide) public var __noteAngle:Float = 0; private function get_noteType() { @@ -159,6 +160,12 @@ class Note extends FlxSprite public var lastScrollSpeed:Null = null; public var angleOffsets:Bool = true; + /** + * Whenever the position of the note should be relative to the strum position or not. + * For example, if this is true, a note at the position 0; 0 will be on the strum, instead of at the top left of the screen. + */ + public var strumRelativePos:Bool = true; + override function draw() { @:privateAccess var oldDefaultCameras = FlxCamera._defaultCameras; @:privateAccess if (__strumCameras != null) FlxCamera._defaultCameras = __strumCameras; @@ -168,47 +175,29 @@ class Note extends FlxSprite rotOffset.y += 2; if (negativeScroll) offset.y *= -1; - if (angleOffsets && Std.int(__noteAngle % 360) != 0) { - // get default values - var oldOffset = FlxPoint.get(offset.x, offset.y); - var oldOrigin = FlxPoint.get(origin.x, origin.y); + if (__strum != null && strumRelativePos) { + var pos = FlxPoint.get(x, y); - // get offset pos without origin - var pos = FlxPoint.get(-offset.x, -offset.y); + setPosition(__strum.x, __strum.y); - // updates sin and cos values for angle - updateTrig(); + rotOffset.x -= pos.x / scale.x; + rotOffset.y -= pos.y / scale.y; - var sin = _sinAngle; - var cos = _cosAngle; - - var anglePos = FlxPoint.get( - (-cos * pos.x) + (-sin * pos.y), - (-sin * pos.x) + (-cos * pos.y)); + this.rotOffsetAngle = __noteAngle; - // applies new values - x -= anglePos.x; - y -= anglePos.y; - offset.set(); - origin.set(oldOrigin.x - oldOffset.x, oldOrigin.y - oldOffset.y); - - // draw super.draw(); - // reset values - offset.set(oldOffset.x, oldOffset.y); - origin.set(oldOrigin.x, oldOrigin.y); - x += anglePos.x; - y += anglePos.y; + this.rotOffsetAngle = 0; - // put flxpoints back in the recycling pool - oldOffset.put(); - oldOrigin.put(); + rotOffset.x += pos.x / scale.x; + rotOffset.y += pos.y / scale.y; + + setPosition(pos.x, pos.y); pos.put(); - anglePos.put(); - return; + } else { + super.draw(); } - super.draw(); + if (negativeScroll) offset.y *= -1; if (antialiasing && nextSustain == null) rotOffset.y -= 2; diff --git a/source/funkin/game/Strum.hx b/source/funkin/game/Strum.hx index ab33a111..6c68bb48 100644 --- a/source/funkin/game/Strum.hx +++ b/source/funkin/game/Strum.hx @@ -46,32 +46,42 @@ class Strum extends FlxSprite { public function updateNotePosition(daNote:Note) { if (!daNote.exists) return; - var offset = FlxPoint.get(daNote.isSustainNote ? ((Note.swagWidth - daNote.width) / 2) : 0, (Conductor.songPosition - daNote.strumTime) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2))); - var realOffset = FlxPoint.get(0, 0); - + daNote.__strumCameras = lastDrawCameras; - - if (daNote.isSustainNote) offset.y -= Note.swagWidth / 2; - + daNote.__strum = this; daNote.scrollFactor.set(scrollFactor.x, scrollFactor.y); - var noteAngle = daNote.__noteAngle = getNotesAngle(daNote); daNote.angle = daNote.isSustainNote ? noteAngle : angle; - if (Std.int(noteAngle % 360) != 0) { - var noteAngleCos = Math.cos(noteAngle / 180 * Math.PI); - var noteAngleSin = Math.sin(noteAngle / 180 * Math.PI); - realOffset.x = (noteAngleCos * offset.x) + (noteAngleSin * offset.y); - realOffset.y = (noteAngleSin * offset.x) + (noteAngleCos * offset.y); - } else { - realOffset.x = offset.x; - realOffset.y = offset.y; - } - realOffset.y *= -1; - daNote.setPosition(x + realOffset.x, y + realOffset.y); - - offset.put(); - realOffset.put(); + if (daNote.strumRelativePos) { + daNote.setPosition(daNote.isSustainNote ? ((Note.swagWidth - daNote.width) / 2) : 0, (daNote.strumTime - Conductor.songPosition) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2))); + if (daNote.isSustainNote) daNote.y += Note.swagWidth / 2; + } else { + var offset = FlxPoint.get(0, (Conductor.songPosition - daNote.strumTime) * (0.45 * FlxMath.roundDecimal(getScrollSpeed(daNote), 2))); + var realOffset = FlxPoint.get(0, 0); + + if (daNote.isSustainNote) offset.y -= Note.swagWidth / 2; + + if (Std.int(noteAngle % 360) != 0) { + var noteAngleCos = Math.cos(noteAngle / 180 * Math.PI); + var noteAngleSin = Math.sin(noteAngle / 180 * Math.PI); + var aOffset:FlxPoint = FlxPoint.get( + (daNote.origin.x / daNote.scale.x) - daNote.offset.x, + (daNote.origin.y / daNote.scale.y) - daNote.offset.y + ); + realOffset.x = -aOffset.x + (noteAngleCos * (offset.x + aOffset.x)) + (noteAngleSin * (offset.y + aOffset.y)); + realOffset.y = -aOffset.y + (noteAngleSin * (offset.x + aOffset.x)) + (noteAngleCos * (offset.y + aOffset.y)); + } else { + realOffset.x = offset.x; + realOffset.y = offset.y; + } + realOffset.y *= -1; + + daNote.setPosition(x + realOffset.x, y + realOffset.y); + + offset.put(); + realOffset.put(); + } } public function updateSustain(daNote:Note) {