-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathMainMenuState.hx
More file actions
405 lines (351 loc) · 12.3 KB
/
Copy pathMainMenuState.hx
File metadata and controls
405 lines (351 loc) · 12.3 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
package;
#if desktop
import Discord.DiscordClient;
#end
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.addons.display.FlxBackdrop;
import flixel.FlxCamera;
import flixel.addons.transition.FlxTransitionableState;
import flixel.effects.FlxFlicker;
import flixel.graphics.frames.FlxAtlasFrames;
import flixel.group.FlxGroup.FlxTypedGroup;
import flixel.text.FlxText;
import flixel.math.FlxMath;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxColor;
import lime.app.Application;
import Achievements;
import editors.MasterEditorMenu;
import flixel.input.keyboard.FlxKey;
using StringTools;
class MainMenuState extends MusicBeatState
{
public static var psychEngineVersion:String = '0.5.2h'; //This is also used for DiscÑord RPC
public static var curSelected:Int = 0;
var menuItems:FlxTypedGroup<FlxSprite>;
private var camGame:FlxCamera;
private var camAchievement:FlxCamera;
var background2:FlxSprite;
var optionShit:Array<String> = [
'story_mode',
'freeplay',
//#if MODS_ALLOWED 'mods', #end
//#if ACHIEVEMENTS_ALLOWED 'awards', #end
'credits',
//#if !switch 'donate', #end
'options',
'youtube',
'plushie'
];
var magenta:FlxSprite;
var camFollow:FlxObject;
var camFollowPos:FlxObject;
var debugKeys:Array<FlxKey>;
var char:FlxSprite;
override function create()
{
WeekData.loadTheFirstEnabledMod();
#if desktop
// Updating Discord Rich Presence
DiscordClient.changePresence("In the Menus", null);
#end
debugKeys = ClientPrefs.copyKey(ClientPrefs.keyBinds.get('debug_1'));
camGame = new FlxCamera();
camAchievement = new FlxCamera();
camAchievement.bgColor.alpha = 0;
FlxG.cameras.reset(camGame);
FlxG.cameras.add(camAchievement);
FlxCamera.defaultCameras = [camGame];
transIn = FlxTransitionableState.defaultTransIn;
transOut = FlxTransitionableState.defaultTransOut;
persistentUpdate = persistentDraw = true;
var yScroll:Float = Math.max(0.25 - (0.05 * (optionShit.length - 4)), 0.1);
var bg:FlxSprite = new FlxSprite(-80).loadGraphic(Paths.image('menuBG'));
bg.scrollFactor.set(0, yScroll);
bg.setGraphicSize(Std.int(bg.width * 1.175));
bg.updateHitbox();
bg.screenCenter();
bg.antialiasing = ClientPrefs.globalAntialiasing;
add(bg);
var background:FlxSprite = new FlxSprite().loadGraphic(Paths.image('mainmenu/menuBG'));
background.scrollFactor.set();
background.screenCenter();
background.antialiasing = ClientPrefs.globalAntialiasing;
add(background);
var bgScroll:FlxBackdrop = new FlxBackdrop(Paths.image('mainmenu/mainBG'), 5, 5, true, true, -33, -32);
bgScroll.scrollFactor.set();
bgScroll.screenCenter();
bgScroll.velocity.set(50, 50);
bgScroll.antialiasing = ClientPrefs.globalAntialiasing;
add(bgScroll);
camFollow = new FlxObject(0, 0, 1, 1);
camFollowPos = new FlxObject(0, 0, 1, 1);
add(camFollow);
add(camFollowPos);
magenta = new FlxSprite(-80).loadGraphic(Paths.image('menuDesat'));
magenta.scrollFactor.set(0, yScroll);
magenta.setGraphicSize(Std.int(magenta.width * 1.175));
magenta.updateHitbox();
magenta.screenCenter();
magenta.visible = false;
magenta.antialiasing = ClientPrefs.globalAntialiasing;
magenta.color = 0xFFfd719b;
//add(magenta);
background2 = new FlxSprite().loadGraphic(Paths.image('mainmenu/menuBG'));
background2.scrollFactor.set();
background2.screenCenter();
background2.visible = false;
background2.antialiasing = ClientPrefs.globalAntialiasing;
background2.color = FlxColor.MAGENTA;
add(background2);
// magenta.scrollFactor.set();
menuItems = new FlxTypedGroup<FlxSprite>();
add(menuItems);
var scale:Float = 1;
/*if(optionShit.length > 6) {
scale = 6 / optionShit.length;
}*/
for (i in 0...optionShit.length)
{
var offset:Float = 108 - (Math.max(optionShit.length, 4) - 4) * 80;
var menuItem:FlxSprite = new FlxSprite(100, (i * 140) + offset);
menuItem.scale.x = scale;
menuItem.scale.y = scale;
menuItem.frames = Paths.getSparrowAtlas('mainmenu/menu_' + optionShit[i]);
menuItem.animation.addByPrefix('idle', optionShit[i] + " basic", 24);
menuItem.animation.addByPrefix('selected', optionShit[i] + " white", 24);
menuItem.animation.play('idle');
menuItem.ID = i;
//menuItem.screenCenter(X);
menuItems.add(menuItem);
var scr:Float = (optionShit.length - 4) * 0.135;
if(optionShit.length < 6) scr = 0;
menuItem.scrollFactor.set(0, scr);
menuItem.antialiasing = ClientPrefs.globalAntialiasing;
//menuItem.setGraphicSize(Std.int(menuItem.width * 0.58));
menuItem.updateHitbox();
}
FlxG.camera.follow(camFollowPos, null, 1);
var versionShit:FlxText = new FlxText(12, FlxG.height - 64, 0, "Psych Engine Tutorials By EIT",12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
var versionShit:FlxText = new FlxText(12, FlxG.height - 44, 0, "Psych Engine v" + psychEngineVersion, 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
var versionShit:FlxText = new FlxText(12, FlxG.height - 24, 0, "Friday Night Funkin' v" + Application.current.meta.get('version'), 12);
versionShit.scrollFactor.set();
versionShit.setFormat("VCR OSD Mono", 16, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
add(versionShit);
// NG.core.calls.event.logEvent('swag').send();
changeItem();
#if ACHIEVEMENTS_ALLOWED
Achievements.loadAchievements();
var leDate = Date.now();
if (leDate.getDay() == 5 && leDate.getHours() >= 18) {
var achieveID:Int = Achievements.getAchievementIndex('friday_night_play');
if(!Achievements.isAchievementUnlocked(Achievements.achievementsStuff[achieveID][2])) { //It's a friday night. WEEEEEEEEEEEEEEEEEE
Achievements.achievementsMap.set(Achievements.achievementsStuff[achieveID][2], true);
giveAchievement();
ClientPrefs.saveSettings();
}
}
#end
super.create();
switch (FlxG.random.int(1, 6))
{
case 1:
char = new FlxSprite(820, 170).loadGraphic(Paths.image('mainmenu/hellron'));//put your cords and image here
char.frames = Paths.getSparrowAtlas('mainmenu/hellron');//here put the name of the xml
char.animation.addByPrefix('idleR', 'idle normal', 24, true);//on 'idle normal' change it to your xml one
char.animation.play('idleR');//you can rename the anim however you want to
char.scrollFactor.set();
FlxG.sound.play(Paths.sound('appear'), 2);
char.flipX = true;//this is for flipping it to look left instead of right you can make it however you want
char.antialiasing = ClientPrefs.globalAntialiasing;
add(char);
case 2:
char = new FlxSprite(790, 200).loadGraphic(Paths.image('mainmenu/BOYFRIEND_Run'));
char.frames = Paths.getSparrowAtlas('mainmenu/BOYFRIEND_Run');
char.animation.addByPrefix('idleB', 'BF idle dance', 24, true);
char.animation.play('idleB');
char.scrollFactor.set();
char.antialiasing = ClientPrefs.globalAntialiasing;
add(char);
case 3:
char = new FlxSprite(810, 120).loadGraphic(Paths.image('mainmenu/sans_assets'));
char.frames = Paths.getSparrowAtlas('mainmenu/sans_assets');
char.animation.addByPrefix('idleS', 'SANS Idle', 24, true);
char.animation.play('idleS');
char.scrollFactor.set();
char.flipX = true;
char.antialiasing = ClientPrefs.globalAntialiasing;
add(char);
case 4:
char = new FlxSprite(650, 130).loadGraphic(Paths.image('mainmenu/Glitched'));
char.frames = Paths.getSparrowAtlas('mainmenu/Glitched');
char.animation.addByPrefix('idleG', 'idle???', 24, true);
char.animation.play('idleG');
char.scrollFactor.set();
char.flipX = true;
char.antialiasing = ClientPrefs.globalAntialiasing;
FlxG.sound.play(Paths.sound('miaou'), 2);
add(char);
case 5:
char = new FlxSprite(700, 130).loadGraphic(Paths.image('mainmenu/hellron-drippin'));
char.frames = Paths.getSparrowAtlas('mainmenu/hellron-drippin');
char.animation.addByPrefix('idleRD', 'idle instance', 24, true);
char.animation.play('idleRD');
char.scrollFactor.set();
char.flipX = true;
char.antialiasing = ClientPrefs.globalAntialiasing;
FlxG.sound.play(Paths.sound('SUS'), 2);
add(char);
case 6:
char = new FlxSprite(790, 190).loadGraphic(Paths.image('mainmenu/Sans_Gold'));
char.frames = Paths.getSparrowAtlas('mainmenu/Sans_Gold');
char.animation.addByPrefix('idleSG', 'Silver Idle', 24, true);
char.animation.play('idleSG');
char.scrollFactor.set();
FlxG.sound.play(Paths.sound('error'), 2);
char.antialiasing = ClientPrefs.globalAntialiasing;
background.color = FlxColor.BLACK;
bgScroll.color = FlxColor.BLACK;
background2.color = FlxColor.BLACK;
add(char);
}
}
#if ACHIEVEMENTS_ALLOWED
// Unlocks "Freaky on a Friday Night" achievement
function giveAchievement() {
add(new AchievementObject('friday_night_play', camAchievement));
FlxG.sound.play(Paths.sound('confirmMenu'), 0.7);
trace('Giving achievement "friday_night_play"');
}
#end
var selectedSomethin:Bool = false;
override function update(elapsed:Float)
{
if (FlxG.sound.music.volume < 0.8)
{
FlxG.sound.music.volume += 0.5 * FlxG.elapsed;
}
var lerpVal:Float = CoolUtil.boundTo(elapsed * 7.5, 0, 1);
camFollowPos.setPosition(FlxMath.lerp(camFollowPos.x, camFollow.x, lerpVal), FlxMath.lerp(camFollowPos.y, camFollow.y, lerpVal));
if (!selectedSomethin)
{
if (controls.UI_UP_P)
{
FlxG.sound.play(Paths.sound('scrollMenu'));
changeItem(-1);
}
if (controls.UI_DOWN_P)
{
FlxG.sound.play(Paths.sound('scrollMenu'));
changeItem(1);
}
if (controls.BACK)
{
selectedSomethin = true;
FlxG.sound.play(Paths.sound('cancelMenu'));
MusicBeatState.switchState(new TitleState());
}
if (controls.ACCEPT)
{
if (optionShit[curSelected] == 'donate')
{
CoolUtil.browserLoad('https://ninja-muffin24.itch.io/funkin');
}
else if (optionShit[curSelected] == 'youtube')
{
CoolUtil.browserLoad('https://youtube.com');
}
else
{
selectedSomethin = true;
FlxG.sound.play(Paths.sound('confirmMenu'));
if(ClientPrefs.flashing) FlxFlicker.flicker(background2, 1.1, 0.15, false);
if(ClientPrefs.flashing) FlxFlicker.flicker(char, 1.1, 0.15, false);
menuItems.forEach(function(spr:FlxSprite)
{
if (curSelected != spr.ID)
{
FlxTween.tween(spr, {alpha: 0}, 0.4, {
ease: FlxEase.quadOut,
onComplete: function(twn:FlxTween)
{
spr.kill();
}
});
}
else
{
FlxFlicker.flicker(spr, 1, 0.06, false, false, function(flick:FlxFlicker)
{
var daChoice:String = optionShit[curSelected];
switch (daChoice)
{
case 'story_mode':
MusicBeatState.switchState(new StoryMenuState());
case 'freeplay':
MusicBeatState.switchState(new FreeplayState());
#if MODS_ALLOWED
case 'mods':
MusicBeatState.switchState(new ModsMenuState());
#end
case 'awards':
MusicBeatState.switchState(new AchievementsMenuState());
case 'credits':
MusicBeatState.switchState(new CreditsState());
case 'options':
LoadingState.loadAndSwitchState(new options.OptionsState());
case 'plushie':
FlxG.switchState(new dumb.PlushieState());
}
});
}
});
}
}
#if desktop
else if (FlxG.keys.anyJustPressed(debugKeys))
{
selectedSomethin = true;
MusicBeatState.switchState(new MasterEditorMenu());
}
#end
}
super.update(elapsed);
menuItems.forEach(function(spr:FlxSprite)
{
//spr.screenCenter(X);
});
}
function changeItem(huh:Int = 0)
{
curSelected += huh;
if (curSelected >= menuItems.length)
curSelected = 0;
if (curSelected < 0)
curSelected = menuItems.length - 1;
menuItems.forEach(function(spr:FlxSprite)
{
spr.animation.play('idle');
spr.updateHitbox();
if (spr.ID == curSelected)
{
spr.animation.play('selected');
var add:Float = 0;
if(menuItems.length > 4) {
add = menuItems.length * 8;
}
camFollow.setPosition(spr.getGraphicMidpoint().x, spr.getGraphicMidpoint().y - add);
spr.centerOffsets();
}
});
}
}