Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
swag swagging
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeMaru committed Dec 18, 2023
1 parent b94fed4 commit 4cc08a1
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 25 deletions.
9 changes: 8 additions & 1 deletion source/funkin/graphics/SmartSprite.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ enum RenderMode {

class SmartSprite extends FlxRepeatSprite {
public var renderMode:RenderMode = QUAD;
public function setRenderMode(value:String) {
renderMode = switch (value.toLowerCase().trim()) {
case "quad" | "q" | "1": QUAD;
case "repeat" | "r" | "2": REPEAT;
default: QUAD; // Ill maybe add more render modes over time idk
}
}

public function new(?X:Float, ?Y:Float, ?SimpleGraphic:FlxGraphicAsset) {
super(X, Y, SimpleGraphic, 0, 0);
Expand All @@ -26,7 +33,7 @@ class SmartSprite extends FlxRepeatSprite {
updateTrig();
if (angle != 0) _matrix.rotateWithTrig(_cosAngle, _sinAngle);
}
updateSkewMatrix();
inline updateSkewMatrix();
_matrix.concat(_skewMatrix);
}

Expand Down
78 changes: 78 additions & 0 deletions source/funkin/objects/note/BasicNote.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package funkin.objects.note;

import funkin.graphics.SmartSprite;

class BasicNote extends SmartSprite {
public var strumTime:Float = 0.0;
public var noteData:Int = 0;
public var noteSpeed:Float = 1.0;
public var targetStrum:NoteStrum;
public var parentNote:Note;
public var childNote:Sustain;

public var isSustainNote(default, set):Bool = false;
inline function set_isSustainNote(value:Bool) {
renderMode = value ? REPEAT : QUAD;
return isSustainNote = value;
}

private var curSkinData:SkinMapData;
public var skin(default, set):String = "default";
inline function set_skin(?value:String) {
skin = value ?? SkinUtil.curSkin;
curSkinData = NoteUtil.getSkinSprites(skin, noteData);
updateSprites();
return skin;
}

public function changeSkin(?value:String) {
if (value != skin)
skin = value;
}

public function updateSprites() {
loadFromSprite(curSkinData.baseSprite);
}

public var approachAngle:Float = 0;
public var spawnMult:Float = 1.0;

public function new(noteData:Int = 0, strumTime:Float = 0.0, skin:String = "default") {
super();
this.noteData = noteData;
this.strumTime = strumTime;
this.skin = skin;
approachAngle = Preferences.getPref('downscroll') ? 180 : 0;
}

override function update(elapsed:Float) {
super.update(elapsed);
if (targetStrum != null) {
moveToStrum();
}
}

inline public function moveToStrum() {
final noteMove:Float = getMillPos(Conductor.songPosition - strumTime); // Position with strumtime
y = targetStrum.y - (noteMove * getCos()); // Set Position
x = targetStrum.x - (noteMove * -getSin());
}

inline public function getCos() {
return FlxMath.fastCos(FlxAngle.asRadians(approachAngle));
}

inline public function getSin() {
return FlxMath.fastSin(FlxAngle.asRadians(approachAngle));
}

// Converts song milliseconds to a position on screen
inline public function getMillPos(mills:Float):Float {
return mills * (0.45 * noteSpeed);
}

// Converts a position on screen to song milliseconds
inline public function getPosMill(pos:Float):Float {
return pos / (0.45 * noteSpeed);
}
}
10 changes: 0 additions & 10 deletions source/funkin/objects/note/Note.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@ interface INoteData {
public var noteData:Int;
}

interface INoteObject extends INoteData {
public var strumTime:Float;
public var noteSpeed:Float;
public var targetStrum:NoteStrum;
public var parentNote:Note;
public var childNote:Sustain;

public var isSustainNote:Bool;
}

class Note extends FlxSpriteExt implements INoteData {
public var noteData:Int = 0;
public var strumTime:Float = 0;
Expand Down
36 changes: 22 additions & 14 deletions source/funkin/objects/note/Sustain.hx
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
package funkin.objects.note;

import flixel.graphics.frames.FlxFrame;
import funkin.graphics.FlxRepeatSprite;

class Sustain extends FlxRepeatSprite implements INoteData {
public var noteData:Int = 0;
public var noteSpeed:Float = 1.0;
class Sustain extends BasicNote {
public var susLength:Float = 0.0;

public function new(noteData:Int = 0) {
super();
public function new(noteData:Int = 0, strumTime:Float = 0.0, susLength:Float = 0.0, skin:String = "default", ?parentNote:Note) {
super(noteData, strumTime, skin); // Load skin

this.parentNote = parentNote;
isSustainNote = true;
drawStyle = BOTTOM_TOP;
alpha = 0.6;
this.noteData = noteData % Conductor.NOTE_DATA_LENGTH;

changeSkin("default");
this.susLength = susLength;
setSusLength(susLength);

//clipRect = new FlxRect(0,0,0,0);
}

var skinData:SkinMapData;
function updateSusLength() {
setSusLength(susLength);
}

function setSusLength(mills:Float = 0.0) {
repeatHeight = getMillPos(mills) + NoteUtil.swagHeight * 0.5;
}

public function changeSkin(value:String = "default") {
skinData = NoteUtil.getSkinSprites(value, noteData);
loadFromSprite(skinData.baseSprite);
override function updateSprites() {
super.updateSprites();
updateHitbox();

final holdFrame = animation.getByName("hold" + CoolUtil.directionArray[noteData]).frames[0];
Expand All @@ -34,8 +42,8 @@ class Sustain extends FlxRepeatSprite implements INoteData {

override function setupTile(tileX:Int, tileY:Int, baseFrame:FlxFrame) {
switch (tileY) {
case 0: playAnim("hold" + CoolUtil.directionArray[noteData] + "-end");
case 1: playAnim("hold" + CoolUtil.directionArray[noteData]);
case 0: playAnim("hold" + CoolUtil.directionArray[noteData] + "-end"); // Tail
case 1: playAnim("hold" + CoolUtil.directionArray[noteData]); // Piece
}
return super.setupTile(tileX, tileY, frame);
}
Expand Down

0 comments on commit 4cc08a1

Please sign in to comment.