1
0
Fork 0
mirror of https://github.com/ninjamuffin99/Funkin.git synced 2024-12-01 03:04:30 +00:00
Funkin/source/Note.hx

153 lines
3.2 KiB
Haxe
Raw Normal View History

2020-10-03 06:50:15 +00:00
package;
import flixel.FlxSprite;
2020-10-04 06:42:58 +00:00
import flixel.graphics.frames.FlxAtlasFrames;
2020-10-03 06:50:15 +00:00
import flixel.util.FlxColor;
class Note extends FlxSprite
{
public var strumTime:Float = 0;
public var mustPress:Bool = false;
public var noteData:Int = 0;
2020-10-03 17:36:39 +00:00
public var canBeHit:Bool = false;
public var tooLate:Bool = false;
public var wasGoodHit:Bool = false;
public var prevNote:Note;
2020-10-03 06:50:15 +00:00
2020-10-03 19:32:15 +00:00
public var noteScore:Float = 1;
2020-10-04 08:38:21 +00:00
public static var swagWidth:Float = 160 * 0.7;
2020-10-07 01:56:14 +00:00
public function new(strumTime:Float, noteData:Int, ?prevNote:Note)
2020-10-03 06:50:15 +00:00
{
super();
2020-10-07 01:56:14 +00:00
if (prevNote == null)
prevNote = this;
2020-10-05 05:13:12 +00:00
this.prevNote = prevNote;
2020-10-04 08:38:21 +00:00
x += 50;
2020-10-03 06:50:15 +00:00
this.strumTime = strumTime;
2020-10-03 17:36:39 +00:00
2020-10-03 06:50:15 +00:00
this.noteData = noteData;
2020-10-04 06:42:58 +00:00
var tex = FlxAtlasFrames.fromSparrow(AssetPaths.NOTE_assets__png, AssetPaths.NOTE_assets__xml);
frames = tex;
2020-10-04 08:38:21 +00:00
animation.addByPrefix('greenScroll', 'green0');
animation.addByPrefix('redScroll', 'red0');
animation.addByPrefix('blueScroll', 'blue0');
animation.addByPrefix('purpleScroll', 'purple0');
2020-10-04 06:42:58 +00:00
2020-10-05 05:13:12 +00: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');
2020-10-04 08:38:21 +00:00
setGraphicSize(Std.int(width * 0.7));
updateHitbox();
2020-10-05 02:31:38 +00:00
antialiasing = true;
2020-10-03 06:50:15 +00:00
switch (Math.abs(noteData))
{
case 1:
2020-10-03 17:36:39 +00:00
x += swagWidth * 2;
2020-10-04 08:38:21 +00:00
animation.play('greenScroll');
2020-10-03 06:50:15 +00:00
case 2:
2020-10-03 17:36:39 +00:00
x += swagWidth * 3;
2020-10-04 08:38:21 +00:00
animation.play('redScroll');
2020-10-03 06:50:15 +00:00
case 3:
2020-10-03 17:36:39 +00:00
x += swagWidth * 1;
2020-10-04 08:38:21 +00:00
animation.play('blueScroll');
2020-10-03 06:50:15 +00:00
case 4:
2020-10-03 17:36:39 +00:00
x += swagWidth * 0;
2020-10-04 08:38:21 +00:00
animation.play('purpleScroll');
2020-10-03 06:50:15 +00:00
}
2020-10-05 05:13:12 +00:00
trace(prevNote);
if (noteData < 0 && prevNote != null)
2020-10-03 19:32:15 +00:00
{
noteScore * 0.2;
2020-10-03 06:50:15 +00:00
alpha = 0.6;
2020-10-05 05:13:12 +00:00
x += width / 2;
switch (noteData)
{
case -1:
animation.play('greenholdend');
case -2:
animation.play('redholdend');
case -3:
animation.play('blueholdend');
case -4:
animation.play('purpleholdend');
}
updateHitbox();
x -= width / 2;
if (prevNote.noteData < 0)
{
switch (prevNote.noteData)
{
case -1:
prevNote.animation.play('greenhold');
case -2:
prevNote.animation.play('redhold');
case -3:
prevNote.animation.play('bluehold');
case -4:
prevNote.animation.play('purplehold');
}
prevNote.offset.y = -19;
prevNote.scale.y *= 2.25;
// prevNote.setGraphicSize();
}
2020-10-03 19:32:15 +00:00
}
2020-10-03 06:50:15 +00:00
}
2020-10-03 17:36:39 +00:00
override function update(elapsed:Float)
{
super.update(elapsed);
if (mustPress)
{
if (strumTime > Conductor.songPosition - Conductor.safeZoneOffset
&& strumTime < Conductor.songPosition + Conductor.safeZoneOffset)
{
canBeHit = true;
}
else
canBeHit = false;
if (strumTime < Conductor.songPosition - Conductor.safeZoneOffset)
tooLate = true;
}
else
2020-10-04 06:42:58 +00:00
{
2020-10-03 17:36:39 +00:00
canBeHit = false;
2020-10-04 06:42:58 +00:00
if (strumTime <= Conductor.songPosition)
{
wasGoodHit = true;
}
}
if (tooLate)
{
if (alpha > 0.3)
alpha = 0.3;
}
2020-10-03 17:36:39 +00:00
}
2020-10-03 06:50:15 +00:00
}