Skip to content
This repository was archived by the owner on Oct 18, 2025. It is now read-only.

Commit 0b95456

Browse files
New Note System (WIP)
1 parent 72399b3 commit 0b95456

File tree

8 files changed

+223
-389
lines changed

8 files changed

+223
-389
lines changed

source/core/enums/NoteState.hx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package core.enums;
33
enum abstract NoteState(String)
44
{
55
var HIT = 'hit';
6-
var LOST = 'lost';
6+
var MISSED = 'missed';
77
var NEUTRAL = 'neutral';
88
var HELD = 'held';
99
var RELEASED = 'released';

source/funkin/debug/FPSField.hx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,16 @@ class FPSField extends DebugField
3030
var memory:Float = 0;
3131
var memoryPeak:Float = 0;
3232

33-
private var times:Array<Float> = [];
34-
3533
override function __enterFrame(time:#if linux Float #else Int #end)
3634
{
3735
super.__enterFrame(time);
3836

39-
final now:Float = haxe.Timer.stamp() * 1000;
40-
41-
times.push(now);
42-
43-
while (times[0] < now - 1000)
44-
times.shift();
45-
46-
fps = CoolUtil.fpsLerp(fps, times.length < FlxG.updateFramerate ? times.length : FlxG.updateFramerate, 0.5);
37+
fps = CoolUtil.fpsLerp(fps, FlxG.elapsed == 0 ? 0 : (1 / FlxG.elapsed), 0.25);
4738
}
4839

4940
override function updateField(elapsed:Float)
5041
{
51-
title.text = 'FPS: ' + Std.string(Math.round(fps));
42+
title.text = 'FPS: ' + Std.string(Math.floor(fps));
5243

5344
#if cpp
5445
memory = Gc.memInfo64(Gc.MEM_INFO_USAGE);

source/funkin/states/PlayState.hx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ class PlayState extends ScriptState
181181

182182
Conductor.bpm = SONG.bpm;
183183

184+
if (SONG.sections[0] != null && SONG.sections[0].changeBPM)
185+
Conductor.bpm = SONG.sections[0].bpm;
186+
184187
initScripts();
185188

186189
camGame.target = camPosition;
@@ -200,9 +203,6 @@ class PlayState extends ScriptState
200203
scrollSpeed = SONG.speed;
201204

202205
initHUD();
203-
204-
if (SONG.sections[0] != null && SONG.sections[0].changeBPM)
205-
Conductor.bpm = SONG.sections[0].bpm;
206206

207207
initCountdown();
208208

@@ -217,8 +217,6 @@ class PlayState extends ScriptState
217217
{
218218
super.update(elapsed);
219219

220-
strumLines.update();
221-
222220
callOnScripts('onUpdate', [elapsed]);
223221

224222
var firsEvent = events[0];
@@ -607,13 +605,13 @@ class PlayState extends ScriptState
607605
}
608606

609607
callOnHScripts('onNoteHit', [note, rating]);
610-
callOnLuaScripts('onNoteHit', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType), Std.string(rating)]);
608+
callOnLuaScripts('onNoteHit', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType), Std.string(rating)]);
611609
}
612610

613611
strl.postNoteHitCallback = function(note:Note, rating:Rating)
614612
{
615613
callOnHScripts('postNoteHit', [note, rating]);
616-
callOnLuaScripts('postNoteHit', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType), Std.string(rating)]);
614+
callOnLuaScripts('postNoteHit', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType), Std.string(rating)]);
617615
}
618616

619617
strl.noteMissCallback = function(note:Note)
@@ -631,25 +629,25 @@ class PlayState extends ScriptState
631629
}
632630

633631
callOnHScripts('onNoteMiss', [note]);
634-
callOnLuaScripts('onNoteMiss', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType)]);
632+
callOnLuaScripts('onNoteMiss', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType)]);
635633
}
636634

637635
strl.postNoteMissCallback = function(note:Note)
638636
{
639637
callOnHScripts('postNoteMiss', [note]);
640-
callOnLuaScripts('postNoteMiss', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType)]);
638+
callOnLuaScripts('postNoteMiss', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType)]);
641639
}
642640

643641
strl.noteSpawnCallback = function(note:Note)
644642
{
645643
callOnHScripts('onNoteSpawn', [note]);
646-
callOnLuaScripts('onNoteSpawn', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType)]);
644+
callOnLuaScripts('onNoteSpawn', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType)]);
647645
}
648646

649647
strl.postNoteSpawnCallback = function(note:Note)
650648
{
651649
callOnHScripts('postNoteSpawn', [note]);
652-
callOnLuaScripts('postNoteSpawn', [note.noteVariant, note.data, note.strumTime, note.noteLength, Std.string(note.type), Std.string(note.noteType)]);
650+
callOnLuaScripts('postNoteSpawn', [note.noteVariant, note.data, note.time, Std.string(note.type), Std.string(note.noteType)]);
653651
}
654652

655653
switch (character.type)

source/funkin/visuals/game/Note.hx

Lines changed: 25 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -13,85 +13,74 @@ class Note extends FlxSprite
1313
{
1414
public var data:Int;
1515

16-
public var strumTime:Float = 0;
16+
public var time:Float = 0;
1717

1818
public var children:Array<Note> = [];
1919

20+
public var direction:Float = 0;
21+
2022
public var sustainHitLenght:Float;
2123

2224
public var spawned:Bool = false;
2325

2426
public var state:NoteState = NEUTRAL;
25-
public var type:ALECharacterType;
26-
public var noteType:NoteType = NORMAL;
2727

28-
public var noteVariant:String = '';
28+
public var type:ALECharacterType;
2929

30-
public var noteLength:Float = 0;
30+
public final noteType:NoteType;
3131

32-
public var prevNote:Note;
33-
public var parentNote:Note;
32+
public var noteVariant:String = '';
3433

3534
public var characterIndex:Int;
35+
3636
public var selected:Bool = false;
3737

3838
public var ignorable:Bool = false;
3939

4040
public var character:Character;
4141

42-
public var ableToHit(get, never):Bool;
43-
function get_ableToHit():Bool
44-
return state == NEUTRAL && Math.abs(strumTime - Conductor.songPosition) < 175;
45-
4642
public var texture(default, set):String;
4743
public function set_texture(value:String):String
4844
{
4945
texture = value;
5046

5147
frames = Paths.getSparrowAtlas('notes/' + texture);
5248

53-
for (anim in [['0', 'note'], [' hold piece', 'piece'], [' hold end', 'end']])
54-
for (col in ['purple', 'blue', 'green', 'red'])
55-
animation.addByPrefix(anim[1] + CoolUtil.capitalize(col), col + anim[0], 24, false);
56-
57-
animation.onFrameChange.add((name:String, frameNumber:Int, frameIndex:Int) -> {
58-
centerOffsets();
59-
centerOrigin();
60-
});
49+
var color:String = ['purple', 'blue', 'green', 'red'][data];
50+
51+
animation.addByPrefix('idle',
52+
switch (noteType)
53+
{
54+
case NORMAL:
55+
color + '0';
56+
case SUSTAIN:
57+
color + ' hold piece';
58+
case SUSTAIN_END:
59+
color + ' hold end';
60+
},
61+
24, false);
6162

6263
scale.set(0.7, 0.7);
6364

64-
if (noteType == NORMAL)
65-
{
66-
centerOffsets();
67-
centerOrigin();
68-
}
69-
70-
if (prevNote != null && prevNote.noteType != NORMAL)
71-
{
72-
prevNote.animation.play('idle');
73-
prevNote.scale.y *= Conductor.stepCrochet / 1000 * 1.05;
74-
prevNote.updateHitbox();
75-
}
65+
animation.play('idle', true);
7666

67+
centerOffsets();
68+
centerOrigin();
7769
updateHitbox();
78-
79-
setMeta(data, noteType);
8070

8171
return texture;
8272
}
8373

8474
public var shaderRef:RGBShaderReference;
8575

86-
public function new(strumTime:Float, data:Int, noteLength:Float, noteVariant:Null<String>, type:ALECharacterType, noteType:NoteType, texture:String = 'note')
76+
public function new(time:Float, data:Int, noteVariant:Null<String>, noteType:NoteType, type:ALECharacterType, texture:String = 'note')
8777
{
8878
super();
8979

9080
this.noteVariant = noteVariant;
9181

92-
this.strumTime = strumTime;
82+
this.time = time;
9383
this.data = data;
94-
this.noteLength = noteLength;
9584

9685
this.type = type;
9786
this.noteType = noteType;
@@ -110,83 +99,4 @@ class Note extends FlxSprite
11099

111100
antialiasing = ClientPrefs.data.antialiasing;
112101
}
113-
114-
public static inline function setNotePosition(note:FlxSprite, target:FlxSprite, angle:Float, offsetX:Float, offsetY:Float)
115-
{
116-
offsetX += target.width / 2 - note.width / 2;
117-
118-
var radians = FlxAngle.asRadians(angle - 90);
119-
120-
note.x = target.x + Math.cos(radians) * offsetX + Math.sin(radians) * offsetY;
121-
note.y = target.y + Math.cos(radians) * offsetY + Math.sin(radians) * offsetX;
122-
}
123-
124-
override function update(elapsed:Float)
125-
{
126-
super.update(elapsed);
127-
128-
/*
129-
if (strum != null)
130-
{
131-
alpha = strum.alpha * (noteType == NORMAL ? 1 : state == LOST ? 0.25 : 0.5);
132-
angle = strum.angle;
133-
scale.x = strum.scale.x;
134-
scale.y = strum.scale.y;
135-
}
136-
*/
137-
}
138-
139-
public function setMeta(data:Int, noteType:NoteType)
140-
{
141-
this.data = data;
142-
this.noteType = noteType;
143-
144-
var anim = switch(noteType)
145-
{
146-
case NORMAL:
147-
'note';
148-
case SUSTAIN:
149-
'piece';
150-
case SUSTAIN_END:
151-
'end';
152-
}
153-
154-
var color = switch (data)
155-
{
156-
case 0:
157-
'Purple';
158-
case 1:
159-
'Blue';
160-
case 2:
161-
'Green';
162-
case 3:
163-
'Red';
164-
default:
165-
'';
166-
};
167-
168-
animation.play(anim + color, true);
169-
170-
var shaderArray:Array<FlxColor> = ClientPrefs.data.arrowRGB[data];
171-
shaderRef.r = shaderArray[0];
172-
shaderRef.g = shaderArray[1];
173-
shaderRef.b = shaderArray[2];
174-
}
175-
176-
public function resetNote(strumTime:Float, data:Int, noteLength:Float, noteVariant:Null<String>, noteType:NoteType)
177-
{
178-
this.strumTime = strumTime;
179-
this.noteLength = noteLength;
180-
this.noteVariant = noteVariant;
181-
182-
state = NEUTRAL;
183-
184-
y = FlxG.height * 2;
185-
186-
setMeta(data, noteType);
187-
188-
active = true;
189-
190-
flipY = noteType == SUSTAIN_END && ClientPrefs.data.downScroll;
191-
}
192102
}

source/funkin/visuals/game/Splash.hx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ class Splash extends AttachedSprite
5555
visible = false;
5656
});
5757

58-
centerOffsets();
59-
centerOrigin();
60-
6158
scale.set(0.85, 0.85);
6259

6360
updateHitbox();
@@ -75,8 +72,6 @@ class Splash extends AttachedSprite
7572
{
7673
super();
7774

78-
visible = false;
79-
8075
this.noteData = noteData;
8176

8277
var rgbPalette = new RGBPalette();
@@ -89,6 +84,8 @@ class Splash extends AttachedSprite
8984

9085
texture = texture;
9186

87+
visible = false;
88+
9289
antialiasing = ClientPrefs.data.antialiasing;
9390

9491
alphaMult = ClientPrefs.data.splashAlpha / 100;

source/funkin/visuals/game/Strum.hx

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Strum extends FlxSprite
1313

1414
public var type:ALECharacterType;
1515

16-
public var direction:Float = 90;
16+
public var direction:Float = 0;
1717

1818
public var scrollSpeed:Float = 1;
1919

@@ -26,18 +26,11 @@ class Strum extends FlxSprite
2626

2727
frames = Paths.getSparrowAtlas('notes/' + texture);
2828

29-
var animToPlay:String = switch (data)
30-
{
31-
case 0: 'left';
32-
case 1: 'down';
33-
case 2: 'up';
34-
case 3: 'right';
35-
default: null;
36-
};
29+
var anim:String = ['left', 'down', 'up', 'right'][data];
3730

38-
animation.addByPrefix('idle', 'arrow' + animToPlay.toUpperCase(), 24, false);
39-
animation.addByPrefix('pressed', animToPlay + ' press', 24, false);
40-
animation.addByPrefix('hit', animToPlay + ' confirm', 24, false);
31+
animation.addByPrefix('idle', 'arrow' + anim.toUpperCase(), 24, false);
32+
animation.addByPrefix('pressed', anim + ' press', 24, false);
33+
animation.addByPrefix('hit', anim + ' confirm', 24, false);
4134

4235
animation.onFrameChange.add((name:String, frameNumber:Int, frameIndex:Int) -> {
4336
centerOffsets();
@@ -54,9 +47,7 @@ class Strum extends FlxSprite
5447

5548
scale.set(0.7, 0.7);
5649

57-
updateHitbox();
58-
centerOffsets();
59-
centerOrigin();
50+
updateHitbox();
6051

6152
animation.play('idle', true);
6253

@@ -93,7 +84,5 @@ class Strum extends FlxSprite
9384
shaderRef.b = shaderArray[2];
9485

9586
antialiasing = ClientPrefs.data.antialiasing;
96-
97-
animation.play('idle', true);
9887
}
9988
}

0 commit comments

Comments
 (0)