wip gameover scripts by neo
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package funkin.backend.scripting.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CANCEL this event to prevent default behaviour!
|
||||||
|
*/
|
||||||
|
final class GameOverCreationEvent extends CancellableEvent
|
||||||
|
{
|
||||||
|
// TODO: documentation
|
||||||
|
public var x:Float;
|
||||||
|
|
||||||
|
public var y:Float;
|
||||||
|
|
||||||
|
public var character:String;
|
||||||
|
|
||||||
|
public var player:Bool;
|
||||||
|
|
||||||
|
public var gameOverSong:String;
|
||||||
|
|
||||||
|
public var lossSFX:String;
|
||||||
|
|
||||||
|
public var retrySFX:String;
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package funkin.game;
|
package funkin.game;
|
||||||
|
|
||||||
|
import funkin.backend.scripting.events.GameOverCreationEvent;
|
||||||
|
import funkin.backend.scripting.events.CancellableEvent;
|
||||||
|
import funkin.backend.scripting.Script;
|
||||||
import flixel.addons.transition.FlxTransitionableState;
|
import flixel.addons.transition.FlxTransitionableState;
|
||||||
import flixel.sound.FlxSound;
|
import flixel.sound.FlxSound;
|
||||||
import flixel.FlxSubState;
|
import flixel.FlxSubState;
|
||||||
@@ -13,19 +16,30 @@ import funkin.backend.system.Conductor;
|
|||||||
class GameOverSubstate extends MusicBeatSubstate
|
class GameOverSubstate extends MusicBeatSubstate
|
||||||
{
|
{
|
||||||
var character:Character;
|
var character:Character;
|
||||||
|
|
||||||
public var characterName:String;
|
public var characterName:String;
|
||||||
public var gameOverSong:String;
|
public var gameOverSong:String;
|
||||||
public var lossSFXName:String;
|
public var lossSFXName:String;
|
||||||
public var retrySFX:String;
|
public var retrySFX:String;
|
||||||
public var player:Bool;
|
public var player:Bool;
|
||||||
|
|
||||||
var camFollow:FlxObject;
|
var camFollow:FlxObject;
|
||||||
|
|
||||||
|
public static var script:String = "";
|
||||||
|
|
||||||
|
public var gameoverScript:Script;
|
||||||
|
public var game:PlayState = PlayState.instance; // shortcut
|
||||||
|
|
||||||
|
private var __cancelDefault:Bool = false;
|
||||||
|
|
||||||
var x:Float = 0;
|
var x:Float = 0;
|
||||||
var y:Float = 0;
|
var y:Float = 0;
|
||||||
|
|
||||||
public var lossSFX:FlxSound;
|
public var lossSFX:FlxSound;
|
||||||
|
|
||||||
public function new(x:Float, y:Float, character:String = "bf-dead", player:Bool = true, gameOverSong:String = "gameOver", lossSFX:String = "gameOverSFX", retrySFX:String = "gameOverEnd") {
|
public function new(x:Float, y:Float, character:String = "bf-dead", player:Bool = true, gameOverSong:String = "gameOver", lossSFX:String = "gameOverSFX",
|
||||||
|
retrySFX:String = "gameOverEnd")
|
||||||
|
{
|
||||||
super();
|
super();
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
@@ -39,9 +53,28 @@ class GameOverSubstate extends MusicBeatSubstate
|
|||||||
public override function create()
|
public override function create()
|
||||||
{
|
{
|
||||||
super.create();
|
super.create();
|
||||||
|
|
||||||
if (FlxG.sound.music != null)
|
if (FlxG.sound.music != null)
|
||||||
FlxG.sound.music.stop();
|
FlxG.sound.music.stop();
|
||||||
|
|
||||||
|
gameoverScript = Script.create(Paths.script(script));
|
||||||
|
gameoverScript.setParent(this);
|
||||||
|
gameoverScript.load();
|
||||||
|
|
||||||
|
var event = EventManager.get(GameOverCreationEvent).recycle(x, y, characterName, player, gameOverSong, lossSFXName, retrySFX);
|
||||||
|
gameoverScript.call('create', [event]);
|
||||||
|
|
||||||
|
x = event.x;
|
||||||
|
y = event.y;
|
||||||
|
characterName = event.character;
|
||||||
|
player = event.player;
|
||||||
|
gameOverSong = event.gameOverSong;
|
||||||
|
lossSFXName = event.lossSFX;
|
||||||
|
retrySFX = event.retrySFX;
|
||||||
|
|
||||||
|
if (__cancelDefault = event.cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
character = new Character(x, y, characterName, player);
|
character = new Character(x, y, characterName, player);
|
||||||
character.danceOnBeat = false;
|
character.danceOnBeat = false;
|
||||||
character.playAnim('firstDeath');
|
character.playAnim('firstDeath');
|
||||||
@@ -56,12 +89,19 @@ class GameOverSubstate extends MusicBeatSubstate
|
|||||||
Conductor.changeBPM(100);
|
Conductor.changeBPM(100);
|
||||||
|
|
||||||
DiscordUtil.changePresence('Game Over', PlayState.SONG.meta.displayName + " (" + PlayState.difficulty + ")");
|
DiscordUtil.changePresence('Game Over', PlayState.SONG.meta.displayName + " (" + PlayState.difficulty + ")");
|
||||||
|
|
||||||
|
gameoverScript.call("postCreate");
|
||||||
}
|
}
|
||||||
|
|
||||||
override function update(elapsed:Float)
|
override function update(elapsed:Float)
|
||||||
{
|
{
|
||||||
super.update(elapsed);
|
super.update(elapsed);
|
||||||
|
|
||||||
|
gameoverScript.call("update", [elapsed]);
|
||||||
|
|
||||||
|
if (__cancelDefault)
|
||||||
|
return;
|
||||||
|
|
||||||
if (controls.ACCEPT)
|
if (controls.ACCEPT)
|
||||||
{
|
{
|
||||||
endBullshit();
|
endBullshit();
|
||||||
@@ -79,7 +119,10 @@ class GameOverSubstate extends MusicBeatSubstate
|
|||||||
FlxG.switchState(new FreeplayState());
|
FlxG.switchState(new FreeplayState());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEnding && ((!lossSFX.playing) || (character.getAnimName() == "firstDeath" && character.isAnimFinished())) && (FlxG.sound.music == null || !FlxG.sound.music.playing)) {
|
if (!isEnding
|
||||||
|
&& ((!lossSFX.playing) || (character.getAnimName() == "firstDeath" && character.isAnimFinished()))
|
||||||
|
&& (FlxG.sound.music == null || !FlxG.sound.music.playing))
|
||||||
|
{
|
||||||
CoolUtil.playMusic(Paths.music(gameOverSong), false, 1, true, 100);
|
CoolUtil.playMusic(Paths.music(gameOverSong), false, 1, true, 100);
|
||||||
beatHit(0);
|
beatHit(0);
|
||||||
}
|
}
|
||||||
@@ -88,6 +131,12 @@ class GameOverSubstate extends MusicBeatSubstate
|
|||||||
override function beatHit(curBeat:Int)
|
override function beatHit(curBeat:Int)
|
||||||
{
|
{
|
||||||
super.beatHit(curBeat);
|
super.beatHit(curBeat);
|
||||||
|
|
||||||
|
gameoverScript.call("onBeatHit", [curBeat]);
|
||||||
|
|
||||||
|
if (__cancelDefault)
|
||||||
|
return;
|
||||||
|
|
||||||
if (FlxG.sound.music != null && FlxG.sound.music.playing)
|
if (FlxG.sound.music != null && FlxG.sound.music.playing)
|
||||||
character.playAnim("deathLoop", true, DANCE);
|
character.playAnim("deathLoop", true, DANCE);
|
||||||
}
|
}
|
||||||
@@ -96,33 +145,48 @@ class GameOverSubstate extends MusicBeatSubstate
|
|||||||
|
|
||||||
function endBullshit():Void
|
function endBullshit():Void
|
||||||
{
|
{
|
||||||
if (!isEnding)
|
if (isEnding)
|
||||||
|
return;
|
||||||
|
isEnding = true;
|
||||||
|
|
||||||
|
var event = new CancellableEvent();
|
||||||
|
gameoverScript.call('onEnd', [event]);
|
||||||
|
|
||||||
|
if (event.cancelled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
character.playAnim('deathConfirm', true);
|
||||||
|
if (FlxG.sound.music != null)
|
||||||
|
FlxG.sound.music.stop();
|
||||||
|
FlxG.sound.music = null;
|
||||||
|
|
||||||
|
var sound = FlxG.sound.play(Paths.sound(retrySFX));
|
||||||
|
|
||||||
|
var secsLength:Float = sound.length / 1000;
|
||||||
|
var waitTime = 0.7;
|
||||||
|
var fadeOutTime = secsLength - 0.7;
|
||||||
|
|
||||||
|
if (fadeOutTime < 0.5)
|
||||||
{
|
{
|
||||||
isEnding = true;
|
fadeOutTime = secsLength;
|
||||||
character.playAnim('deathConfirm', true);
|
waitTime = 0;
|
||||||
if (FlxG.sound.music != null)
|
|
||||||
FlxG.sound.music.stop();
|
|
||||||
FlxG.sound.music = null;
|
|
||||||
|
|
||||||
var sound = FlxG.sound.play(Paths.sound(retrySFX));
|
|
||||||
|
|
||||||
var secsLength:Float = sound.length / 1000;
|
|
||||||
var waitTime = 0.7;
|
|
||||||
var fadeOutTime = secsLength - 0.7;
|
|
||||||
|
|
||||||
if (fadeOutTime < 0.5) {
|
|
||||||
fadeOutTime = secsLength;
|
|
||||||
waitTime = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
new FlxTimer().start(waitTime, function(tmr:FlxTimer)
|
|
||||||
{
|
|
||||||
FlxG.camera.fade(FlxColor.BLACK, fadeOutTime, false, function()
|
|
||||||
{
|
|
||||||
MusicBeatState.skipTransOut = true;
|
|
||||||
FlxG.switchState(new PlayState());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new FlxTimer().start(waitTime, function(tmr:FlxTimer)
|
||||||
|
{
|
||||||
|
FlxG.camera.fade(FlxColor.BLACK, fadeOutTime, false, function()
|
||||||
|
{
|
||||||
|
MusicBeatState.skipTransOut = true;
|
||||||
|
FlxG.switchState(new PlayState());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
override function destroy()
|
||||||
|
{
|
||||||
|
gameoverScript.call("onDestroy");
|
||||||
|
gameoverScript.destroy();
|
||||||
|
|
||||||
|
super.destroy();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,6 +514,7 @@ class PlayState extends MusicBeatState
|
|||||||
if (FlxG.sound.music != null) FlxG.sound.music.stop();
|
if (FlxG.sound.music != null) FlxG.sound.music.stop();
|
||||||
|
|
||||||
PauseSubState.script = "";
|
PauseSubState.script = "";
|
||||||
|
GameOverSubstate.script = "";
|
||||||
(scripts = new ScriptPack("PlayState")).setParent(this);
|
(scripts = new ScriptPack("PlayState")).setParent(this);
|
||||||
|
|
||||||
camGame = camera;
|
camGame = camera;
|
||||||
|
|||||||
Reference in New Issue
Block a user