This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SchmovinUtil.hx
148 lines (125 loc) · 2.84 KB
/
SchmovinUtil.hx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
* @ Author: 4mbr0s3 2
* @ Create Time: 2021-06-22 16:25:26
* @ Modified by: 4mbr0s3 2
* @ Modified time: 2021-11-13 12:35:53
*/
package schmovin;
import flixel.FlxSprite;
import flixel.math.FlxPoint;
import lime.math.Vector4;
// Decorator for receptor to include column data
class Receptor
{
public var wrappee:FlxSprite;
public var column:Int;
public var x(get, set):Float;
public var y(get, set):Float;
public var angle(get, set):Float;
public var scale(get, set):FlxPoint;
function get_x()
{
return wrappee.x;
}
function set_x(v:Float)
{
return wrappee.x = v;
}
function get_y()
{
return wrappee.y;
}
function set_y(v:Float)
{
return wrappee.y = v;
}
function get_angle()
{
return wrappee.angle;
}
function set_angle(v:Float)
{
return wrappee.angle = v;
}
function get_scale()
{
return wrappee.scale;
}
function set_scale(v:FlxPoint)
{
return wrappee.scale.set(v.x, v.y);
}
public function new(receptor:FlxSprite, column:Int)
{
this.wrappee = receptor;
this.column = column;
}
}
class SchmovinUtil
{
public static inline function GetTotalColumn(note:Note)
{
return note.noteData + GetPlayer(note) * 4;
}
public static inline function NoteWidthHalf()
{
return Note.swagWidth / 2;
}
public static inline function PosNoteWidthHalf()
{
return new Vector4(NoteWidthHalf(), NoteWidthHalf());
}
public static inline function Vec4NotePosition(note:Note)
{
return new Vector4(note.x, note.y).add(SchmovinUtil.PosNoteWidthHalf());
}
public static inline function Vec4ReceptorPosition(rec:Receptor)
{
return new Vector4(rec.x, rec.y).add(SchmovinUtil.PosNoteWidthHalf());
}
public static inline function Vec4Lerp(vec:Vector4, vec2:Vector4, lerp:Float)
{
var out1 = vec.clone();
out1.scaleBy(1 - lerp);
var out2 = vec2.clone();
out2.scaleBy(lerp);
return out1.add(out2);
}
public static inline function GetPlayerOfTotalColumn(column:Int)
{
return column > 3 ? 1 : 0;
}
public static inline function GetReceptor(note:Note, state:PlayState)
{
var column = GetTotalColumn(note);
return new Receptor(state.strumLineNotes.members[column], column);
}
public static inline function GetPlayer(note:Note)
{
return note.mustPress ? 1 : 0;
}
public static inline function GetReceptors(player:Int, state:PlayState):Array<Receptor>
{
var receptors = [];
for (index in 0...state.strumLineNotes.members.length)
{
if (GetPlayerOfTotalColumn(index) == player)
{
var receptor = state.strumLineNotes.members[index];
receptors.push(new Receptor(receptor, index));
}
}
return receptors;
}
public static inline function GetNotes(player:Int, state:PlayState):Array<Note>
{
var notes = [];
for (index in 0...state.notes.members.length)
{
var note = state.notes.members[index];
if (GetPlayer(note) == player)
notes.push(note);
}
return notes;
}
}