2022-03-08 03:13:53 -05:00
|
|
|
package funkin;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
|
|
|
import flixel.FlxSprite;
|
2021-01-25 04:18:44 -05:00
|
|
|
import flixel.math.FlxMath;
|
2022-09-16 01:44:50 -04:00
|
|
|
import funkin.noteStuff.NoteBasic.NoteColor;
|
|
|
|
import funkin.noteStuff.NoteBasic.NoteData;
|
|
|
|
import funkin.noteStuff.NoteBasic.NoteType;
|
2022-05-03 13:02:37 -04:00
|
|
|
import funkin.play.PlayState;
|
|
|
|
import funkin.play.Strumline.StrumlineStyle;
|
2022-03-08 03:13:53 -05:00
|
|
|
import funkin.shaderslmfao.ColorSwap;
|
|
|
|
import funkin.ui.PreferencesMenu;
|
2022-05-03 13:02:37 -04:00
|
|
|
import funkin.util.Constants;
|
2021-03-20 01:03:42 -04:00
|
|
|
|
|
|
|
using StringTools;
|
|
|
|
|
2020-10-03 02:50:15 -04:00
|
|
|
class Note extends FlxSprite
|
|
|
|
{
|
2022-02-09 20:31:36 -05:00
|
|
|
public var data = new NoteData();
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2022-02-10 14:23:45 -05:00
|
|
|
/**
|
|
|
|
* code colors for.... code....
|
|
|
|
* i think goes in order of left to right
|
|
|
|
*
|
|
|
|
* left 0
|
|
|
|
* down 1
|
|
|
|
* up 2
|
|
|
|
* right 3
|
|
|
|
*/
|
|
|
|
public static var codeColors:Array<Int> = [0xFFFF22AA, 0xFF00EEFF, 0xFF00CC00, 0xFFCC1111];
|
|
|
|
|
2020-10-03 02:50:15 -04:00
|
|
|
public var mustPress:Bool = false;
|
2021-12-06 22:35:14 -05:00
|
|
|
public var followsTime:Bool = true; // used if you want the note to follow the time shit!
|
2020-10-03 13:36:39 -04:00
|
|
|
public var canBeHit:Bool = false;
|
|
|
|
public var tooLate:Bool = false;
|
|
|
|
public var wasGoodHit:Bool = false;
|
|
|
|
public var prevNote:Note;
|
2021-04-10 18:23:56 -04:00
|
|
|
|
2021-04-07 21:29:32 -04:00
|
|
|
private var willMiss:Bool = false;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2021-04-10 18:23:56 -04:00
|
|
|
public var invisNote:Bool = false;
|
|
|
|
|
2020-10-19 21:59:00 -04:00
|
|
|
public var isSustainNote:Bool = false;
|
2020-10-18 20:59:53 -04:00
|
|
|
|
2021-03-21 14:45:46 -04:00
|
|
|
public var colorSwap:ColorSwap;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
/** the lowercase name of the note, for anim control, i.e. left right up down */
|
|
|
|
public var dirName(get, never):String;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_dirName()
|
|
|
|
return data.dirName;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
/** the uppercase name of the note, for anim control, i.e. left right up down */
|
|
|
|
public var dirNameUpper(get, never):String;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_dirNameUpper()
|
|
|
|
return data.dirNameUpper;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
/** the lowercase name of the note's color, for anim control, i.e. purple blue green red */
|
|
|
|
public var colorName(get, never):String;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_colorName()
|
|
|
|
return data.colorName;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
/** the lowercase name of the note's color, for anim control, i.e. purple blue green red */
|
|
|
|
public var colorNameUpper(get, never):String;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_colorNameUpper()
|
|
|
|
return data.colorNameUpper;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
public var highStakes(get, never):Bool;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_highStakes()
|
|
|
|
return data.highStakes;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
public var lowStakes(get, never):Bool;
|
2022-02-23 16:49:54 -05:00
|
|
|
|
|
|
|
inline function get_lowStakes()
|
|
|
|
return data.lowStakes;
|
|
|
|
|
2020-10-04 04:38:21 -04:00
|
|
|
public static var swagWidth:Float = 160 * 0.7;
|
2020-10-13 22:12:31 -04:00
|
|
|
public static var PURP_NOTE:Int = 0;
|
|
|
|
public static var GREEN_NOTE:Int = 2;
|
|
|
|
public static var BLUE_NOTE:Int = 1;
|
|
|
|
public static var RED_NOTE:Int = 3;
|
2020-10-04 04:38:21 -04:00
|
|
|
|
2021-09-08 13:28:11 -04:00
|
|
|
// SCORING STUFF
|
2022-03-23 14:29:02 -04:00
|
|
|
public static var HIT_WINDOW:Float = (10 / 60) * 1000; // 166.67 ms hit window (10 frames at 60fps)
|
|
|
|
// thresholds are fractions of HIT_WINDOW ^^
|
2021-09-08 13:28:11 -04:00
|
|
|
// anything above bad threshold is shit
|
|
|
|
public static var BAD_THRESHOLD:Float = 0.8; // 125ms , 8 frames
|
|
|
|
public static var GOOD_THRESHOLD:Float = 0.55; // 91.67ms , 5.5 frames
|
|
|
|
public static var SICK_THRESHOLD:Float = 0.2; // 33.33ms , 2 frames
|
|
|
|
|
2021-12-30 00:09:16 -05:00
|
|
|
public var noteSpeedMulti:Float = 1;
|
|
|
|
public var pastHalfWay:Bool = false;
|
|
|
|
|
2021-11-29 15:26:45 -05:00
|
|
|
// anything below sick threshold is sick
|
2021-03-21 14:45:46 -04:00
|
|
|
public static var arrowColors:Array<Float> = [1, 1, 1, 1];
|
|
|
|
|
2022-05-03 13:02:37 -04:00
|
|
|
// Which note asset to load?
|
|
|
|
public var style:StrumlineStyle = NORMAL;
|
|
|
|
|
|
|
|
public function new(strumTime:Float = 0, noteData:NoteType, ?prevNote:Note, ?sustainNote:Bool = false, ?style:StrumlineStyle = NORMAL)
|
2020-10-03 02:50:15 -04:00
|
|
|
{
|
|
|
|
super();
|
|
|
|
|
2020-10-06 21:56:14 -04:00
|
|
|
if (prevNote == null)
|
|
|
|
prevNote = this;
|
|
|
|
|
2020-10-05 01:13:12 -04:00
|
|
|
this.prevNote = prevNote;
|
2020-10-19 21:59:00 -04:00
|
|
|
isSustainNote = sustainNote;
|
2020-10-05 01:13:12 -04:00
|
|
|
|
2020-10-04 04:38:21 -04:00
|
|
|
x += 50;
|
2020-11-10 21:07:56 -05:00
|
|
|
// MAKE SURE ITS DEFINITELY OFF SCREEN?
|
|
|
|
y -= 2000;
|
2022-01-22 16:53:38 -05:00
|
|
|
data.strumTime = strumTime;
|
2020-10-03 13:36:39 -04:00
|
|
|
|
2022-01-22 16:57:49 -05:00
|
|
|
data.noteData = noteData;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2022-05-03 13:02:37 -04:00
|
|
|
this.style = style;
|
|
|
|
|
|
|
|
if (this.style == null)
|
|
|
|
this.style = StrumlineStyle.NORMAL;
|
|
|
|
|
2022-02-28 23:04:55 -05:00
|
|
|
// TODO: Make this logic more generic
|
2022-05-03 13:02:37 -04:00
|
|
|
switch (this.style)
|
2021-01-25 04:18:44 -05:00
|
|
|
{
|
2022-05-03 13:02:37 -04:00
|
|
|
case PIXEL:
|
2021-02-08 16:34:48 -05:00
|
|
|
loadGraphic(Paths.image('weeb/pixelUI/arrows-pixels'), true, 17, 17);
|
2021-02-02 00:48:22 -05:00
|
|
|
|
|
|
|
animation.add('greenScroll', [6]);
|
|
|
|
animation.add('redScroll', [7]);
|
|
|
|
animation.add('blueScroll', [5]);
|
|
|
|
animation.add('purpleScroll', [4]);
|
|
|
|
|
|
|
|
if (isSustainNote)
|
|
|
|
{
|
2021-02-08 16:34:48 -05:00
|
|
|
loadGraphic(Paths.image('weeb/pixelUI/arrowEnds'), true, 7, 6);
|
2021-02-02 00:48:22 -05:00
|
|
|
|
|
|
|
animation.add('purpleholdend', [4]);
|
|
|
|
animation.add('greenholdend', [6]);
|
|
|
|
animation.add('redholdend', [7]);
|
|
|
|
animation.add('blueholdend', [5]);
|
|
|
|
|
|
|
|
animation.add('purplehold', [0]);
|
|
|
|
animation.add('greenhold', [2]);
|
|
|
|
animation.add('redhold', [3]);
|
|
|
|
animation.add('bluehold', [1]);
|
|
|
|
}
|
|
|
|
|
2022-03-11 01:30:01 -05:00
|
|
|
setGraphicSize(Std.int(width * Constants.PIXEL_ART_SCALE));
|
2021-02-02 00:48:22 -05:00
|
|
|
updateHitbox();
|
|
|
|
|
2021-01-25 04:18:44 -05:00
|
|
|
default:
|
2021-02-08 16:34:48 -05:00
|
|
|
frames = Paths.getSparrowAtlas('NOTE_assets');
|
2020-10-05 01:13:12 -04:00
|
|
|
|
2021-03-20 01:03:42 -04:00
|
|
|
animation.addByPrefix('greenScroll', 'green instance');
|
|
|
|
animation.addByPrefix('redScroll', 'red instance');
|
|
|
|
animation.addByPrefix('blueScroll', 'blue instance');
|
|
|
|
animation.addByPrefix('purpleScroll', 'purple instance');
|
2020-10-05 01:13:12 -04:00
|
|
|
|
2021-01-25 04:18:44 -05:00
|
|
|
animation.addByPrefix('purpleholdend', 'pruple end hold');
|
|
|
|
animation.addByPrefix('greenholdend', 'green hold end');
|
|
|
|
animation.addByPrefix('redholdend', 'red hold end');
|
|
|
|
animation.addByPrefix('blueholdend', 'blue hold end');
|
|
|
|
|
|
|
|
animation.addByPrefix('purplehold', 'purple hold piece');
|
|
|
|
animation.addByPrefix('greenhold', 'green hold piece');
|
|
|
|
animation.addByPrefix('redhold', 'red hold piece');
|
|
|
|
animation.addByPrefix('bluehold', 'blue hold piece');
|
|
|
|
|
|
|
|
setGraphicSize(Std.int(width * 0.7));
|
|
|
|
updateHitbox();
|
|
|
|
antialiasing = true;
|
2021-03-20 04:33:44 -04:00
|
|
|
|
|
|
|
// colorSwap.colorToReplace = 0xFFF9393F;
|
|
|
|
// colorSwap.newColor = 0xFF00FF00;
|
|
|
|
|
|
|
|
// color = FlxG.random.color();
|
|
|
|
// color.saturation *= 4;
|
|
|
|
// replaceColor(0xFFC1C1C1, FlxColor.RED);
|
2021-01-25 04:18:44 -05:00
|
|
|
}
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2021-03-21 14:45:46 -04:00
|
|
|
colorSwap = new ColorSwap();
|
|
|
|
shader = colorSwap.shader;
|
2021-03-21 16:29:47 -04:00
|
|
|
updateColors();
|
2021-03-21 14:45:46 -04:00
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
x += swagWidth * data.int;
|
|
|
|
animation.play(data.colorName + 'Scroll');
|
2020-10-03 02:50:15 -04:00
|
|
|
|
2020-10-24 05:36:50 -04:00
|
|
|
// trace(prevNote);
|
2020-10-05 01:13:12 -04:00
|
|
|
|
2020-10-19 21:59:00 -04:00
|
|
|
if (isSustainNote && prevNote != null)
|
2020-10-03 15:32:15 -04:00
|
|
|
{
|
2020-10-03 02:50:15 -04:00
|
|
|
alpha = 0.6;
|
2020-10-05 01:13:12 -04:00
|
|
|
|
2021-03-30 18:10:15 -04:00
|
|
|
if (PreferencesMenu.getPref('downscroll'))
|
|
|
|
angle = 180;
|
|
|
|
|
2020-10-05 01:13:12 -04:00
|
|
|
x += width / 2;
|
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
animation.play(data.colorName + 'holdend');
|
2020-10-05 01:13:12 -04:00
|
|
|
|
|
|
|
updateHitbox();
|
|
|
|
|
|
|
|
x -= width / 2;
|
|
|
|
|
2022-03-11 01:30:01 -05:00
|
|
|
if (PlayState.instance.currentStageId.startsWith('school'))
|
2021-02-01 05:52:10 -05:00
|
|
|
x += 30;
|
|
|
|
|
2020-10-19 21:59:00 -04:00
|
|
|
if (prevNote.isSustainNote)
|
2020-10-05 01:13:12 -04:00
|
|
|
{
|
2022-02-09 20:31:36 -05:00
|
|
|
prevNote.animation.play(prevNote.colorName + 'hold');
|
2021-02-13 17:39:31 -05:00
|
|
|
prevNote.updateHitbox();
|
2021-08-01 21:29:34 -04:00
|
|
|
|
2021-12-06 17:49:05 -05:00
|
|
|
var scaleThing:Float = Math.round((Conductor.stepCrochet) * (0.45 * FlxMath.roundDecimal(SongLoad.getSpeed(), 2)));
|
2021-08-01 21:29:34 -04:00
|
|
|
// get them a LIL closer together cuz the antialiasing blurs the edges
|
|
|
|
if (antialiasing)
|
|
|
|
scaleThing *= 1.0 + (1.0 / prevNote.frameHeight);
|
|
|
|
prevNote.scale.y = scaleThing / prevNote.frameHeight;
|
|
|
|
prevNote.updateHitbox();
|
2020-10-05 01:13:12 -04:00
|
|
|
}
|
2020-10-03 15:32:15 -04:00
|
|
|
}
|
2020-10-03 02:50:15 -04:00
|
|
|
}
|
2020-10-03 13:36:39 -04:00
|
|
|
|
2021-06-07 21:14:50 -04:00
|
|
|
override function destroy()
|
|
|
|
{
|
|
|
|
prevNote = null;
|
|
|
|
|
|
|
|
super.destroy();
|
|
|
|
}
|
|
|
|
|
2021-03-21 14:45:46 -04:00
|
|
|
public function updateColors():Void
|
|
|
|
{
|
2022-01-22 16:57:49 -05:00
|
|
|
colorSwap.update(arrowColors[data.noteData]);
|
2021-03-21 14:45:46 -04:00
|
|
|
}
|
|
|
|
|
2020-10-03 13:36:39 -04:00
|
|
|
override function update(elapsed:Float)
|
|
|
|
{
|
|
|
|
super.update(elapsed);
|
|
|
|
|
2022-03-21 00:19:05 -04:00
|
|
|
// mustPress indicates the player is the one pressing the key
|
2020-10-03 13:36:39 -04:00
|
|
|
if (mustPress)
|
|
|
|
{
|
2021-04-07 21:29:32 -04:00
|
|
|
// miss on the NEXT frame so lag doesnt make u miss notes
|
2021-04-08 07:33:36 -04:00
|
|
|
if (willMiss && !wasGoodHit)
|
2021-04-07 21:29:32 -04:00
|
|
|
{
|
2020-10-03 13:36:39 -04:00
|
|
|
tooLate = true;
|
2021-04-07 21:29:32 -04:00
|
|
|
canBeHit = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-22 16:53:38 -05:00
|
|
|
if (!pastHalfWay && data.strumTime <= Conductor.songPosition)
|
2021-12-30 00:09:16 -05:00
|
|
|
{
|
|
|
|
pastHalfWay = true;
|
|
|
|
noteSpeedMulti *= 2;
|
|
|
|
}
|
|
|
|
|
2022-01-22 16:53:38 -05:00
|
|
|
if (data.strumTime > Conductor.songPosition - HIT_WINDOW)
|
2022-03-21 00:19:05 -04:00
|
|
|
{
|
|
|
|
// * 0.5 if sustain note, so u have to keep holding it closer to all the way thru!
|
2022-01-22 16:53:38 -05:00
|
|
|
if (data.strumTime < Conductor.songPosition + (HIT_WINDOW * (isSustainNote ? 0.5 : 1)))
|
2021-04-07 21:29:32 -04:00
|
|
|
canBeHit = true;
|
|
|
|
}
|
2021-04-10 18:23:56 -04:00
|
|
|
else
|
2021-04-07 21:29:32 -04:00
|
|
|
{
|
|
|
|
canBeHit = true;
|
|
|
|
willMiss = true;
|
|
|
|
}
|
|
|
|
}
|
2020-10-03 13:36:39 -04:00
|
|
|
}
|
|
|
|
else
|
2020-10-04 02:42:58 -04:00
|
|
|
{
|
2020-10-03 13:36:39 -04:00
|
|
|
canBeHit = false;
|
|
|
|
|
2022-01-22 16:53:38 -05:00
|
|
|
if (data.strumTime <= Conductor.songPosition)
|
2020-10-04 02:42:58 -04:00
|
|
|
wasGoodHit = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tooLate)
|
|
|
|
{
|
|
|
|
if (alpha > 0.3)
|
|
|
|
alpha = 0.3;
|
|
|
|
}
|
2020-10-03 13:36:39 -04:00
|
|
|
}
|
2022-02-23 16:49:54 -05:00
|
|
|
|
2022-02-09 20:31:36 -05:00
|
|
|
static public function fromData(data:NoteData, prevNote:Note, isSustainNote = false)
|
|
|
|
{
|
|
|
|
return new Note(data.strumTime, data.noteData, prevNote, isSustainNote);
|
|
|
|
}
|
2020-10-03 02:50:15 -04:00
|
|
|
}
|