generated from ShadowMario/FNF-PsychEngine
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
246 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
package meta.state; | ||
|
||
import flixel.FlxG; | ||
import flixel.FlxState; | ||
import flixel.FlxSprite; | ||
import flixel.group.FlxGroup.FlxTypedGroup; | ||
import flixel.effects.FlxFlicker; | ||
import flixel.util.FlxColor; | ||
import flixel.text.FlxText; | ||
import flixel.math.FlxMath; | ||
import flixel.FlxCamera; | ||
import flixel.FlxObject; | ||
|
||
import meta.*; | ||
import meta.data.*; | ||
import meta.data.alphabet.*; | ||
|
||
import meta.state.*; | ||
|
||
using StringTools; | ||
|
||
class GameExitState extends FlxState | ||
{ | ||
var options:Array<String> = ['Yes', 'No']; | ||
|
||
private var grpOptions:FlxTypedGroup<Alphabet>; | ||
private static var curSelected:Int = 0; | ||
|
||
function openSelectedSubstate(label:String) { | ||
switch(label) { | ||
case 'Yes': | ||
quitGame(); | ||
case 'No': | ||
FlxG.sound.playMusic(Paths.music('freakyMenu')); | ||
MusicBeatState.switchState(new MainMenuState()); | ||
} | ||
} | ||
|
||
var accepted:Bool; | ||
var allowInputs:Bool = false; | ||
|
||
var selectorLeft:Alphabet; | ||
var selectorRight:Alphabet; | ||
|
||
var camFollow:FlxObject; | ||
var camFollowPos:FlxObject; | ||
var camMain:FlxCamera; | ||
|
||
var bg:FlxSprite; | ||
|
||
override function create() | ||
{ | ||
camMain = new FlxCamera(); | ||
FlxG.cameras.reset(camMain); | ||
FlxG.cameras.setDefaultDrawTarget(camMain, true); | ||
camFollow = new FlxObject(0, 0, 1, 1); | ||
camFollowPos = new FlxObject(0, 0, 1, 1); | ||
add(camFollow); | ||
add(camFollowPos); | ||
FlxG.camera.follow(camFollowPos, null, 1); | ||
|
||
var yScroll:Float = Math.max(0.25 - (0.05 * (options.length - 4)), 0.1); | ||
bg = new FlxSprite().loadGraphic(Paths.image('menuDesat')); | ||
bg.updateHitbox(); | ||
bg.screenCenter(); | ||
bg.scrollFactor.set(0, yScroll / 3); | ||
bg.antialiasing = true; | ||
add(bg); | ||
|
||
var header:Alphabet = new Alphabet(0, -55, 'Exit the game?', true); | ||
header.scrollFactor.set(0, Math.max(0.25 - (0.05 * (options.length - 4)), 0.1)); | ||
header.screenCenter(X); | ||
add(header); | ||
|
||
initOptions(); | ||
|
||
selectorLeft = new Alphabet(0, 0, '>', true); | ||
selectorLeft.scrollFactor.set(0, yScroll); | ||
add(selectorLeft); | ||
selectorRight = new Alphabet(0, 0, '<', true); | ||
selectorRight.scrollFactor.set(0, yScroll); | ||
add(selectorRight); | ||
|
||
changeSelection(); | ||
|
||
allowInputs = true; | ||
|
||
super.create(); | ||
} | ||
|
||
function initOptions() { | ||
grpOptions = new FlxTypedGroup<Alphabet>(); | ||
add(grpOptions); | ||
|
||
for (i in 0...options.length) | ||
{ | ||
var optionText:Alphabet = new Alphabet(0, 0, options[i], true); | ||
optionText.screenCenter(); | ||
optionText.y += (100 * (i - (options.length / 2))) + 50; | ||
optionText.scrollFactor.set(0, Math.max(0.25 - (0.05 * (options.length - 4)), 0.1)); | ||
grpOptions.add(optionText); | ||
} | ||
} | ||
|
||
override function update(elapsed:Float) { | ||
super.update(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)); | ||
|
||
var mult:Float = FlxMath.lerp(1.07, bg.scale.x, CoolUtil.boundTo(1 - (elapsed * 9), 0, 1)); | ||
bg.scale.set(mult, mult); | ||
bg.updateHitbox(); | ||
bg.offset.set(); | ||
|
||
if (allowInputs) | ||
{ | ||
if ((FlxG.keys.justPressed.UP || FlxG.keys.justPressed.DOWN) && !accepted) { | ||
changeSelection(FlxG.keys.justPressed.UP ? -1 : 1); | ||
} | ||
|
||
if (FlxG.keys.justPressed.ENTER && !accepted) { | ||
accepted = true; // locks inputs | ||
FlxG.sound.play(Paths.sound('confirmMenu')); | ||
if (ClientPrefs.flashing) { | ||
grpOptions.forEach(function(grpOptions:Alphabet) | ||
{ | ||
FlxFlicker.flicker(grpOptions, 1, 0.06, false, false, function(flick:FlxFlicker) | ||
{ | ||
openSelectedSubstate(options[curSelected]); | ||
}); | ||
}); | ||
} else { | ||
new FlxTimer().start(1, function(tmr:FlxTimer) | ||
{ | ||
openSelectedSubstate(options[curSelected]); | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function changeSelection(change:Int = 0) { | ||
curSelected += change; | ||
if (curSelected < 0) | ||
curSelected = options.length - 1; | ||
if (curSelected >= options.length) | ||
curSelected = 0; | ||
|
||
var bullShit:Int = 0; | ||
|
||
for (item in grpOptions.members) { | ||
item.targetY = bullShit - curSelected; | ||
bullShit++; | ||
|
||
item.alpha = 0.6; | ||
if (item.targetY == 0) { | ||
item.alpha = 1; | ||
selectorLeft.x = item.x - 63; | ||
selectorLeft.y = item.y; | ||
selectorRight.x = item.x + item.width + 15; | ||
selectorRight.y = item.y; | ||
var add:Float = (grpOptions.members.length > 4 ? grpOptions.members.length * 8 : 0); | ||
camFollow.setPosition(item.getGraphicMidpoint().x, item.getGraphicMidpoint().y - add); | ||
} | ||
} | ||
} | ||
|
||
function quitGame() { | ||
FlxG.camera.fade(FlxColor.BLACK, 0.5, false, function() { Sys.exit(0); }, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters