2022-03-08 03:13:53 -05:00
|
|
|
|
package funkin.play;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
|
2023-08-02 11:00:23 -04:00
|
|
|
|
import flixel.addons.transition.FlxTransitionableSubState;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
import funkin.ui.debug.charting.ChartEditorState;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
import haxe.Int64;
|
2023-07-13 20:27:45 -04:00
|
|
|
|
import funkin.play.notes.notestyle.NoteStyle;
|
|
|
|
|
import funkin.data.notestyle.NoteStyleData;
|
|
|
|
|
import funkin.data.notestyle.NoteStyleRegistry;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
import flixel.addons.display.FlxPieDial;
|
2023-08-04 16:15:07 -04:00
|
|
|
|
import flixel.addons.transition.Transition;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
import flixel.addons.transition.FlxTransitionableState;
|
2020-10-25 16:51:06 -04:00
|
|
|
|
import flixel.FlxCamera;
|
2020-10-04 02:42:58 -04:00
|
|
|
|
import flixel.FlxObject;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
import flixel.FlxSprite;
|
|
|
|
|
import flixel.FlxState;
|
2020-10-09 17:24:20 -04:00
|
|
|
|
import flixel.FlxSubState;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
import flixel.input.keyboard.FlxKey;
|
2020-10-05 05:48:30 -04:00
|
|
|
|
import flixel.math.FlxMath;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
import flixel.math.FlxPoint;
|
2021-01-16 17:21:06 -05:00
|
|
|
|
import flixel.math.FlxRect;
|
2020-10-03 02:50:15 -04:00
|
|
|
|
import flixel.text.FlxText;
|
2020-10-05 14:24:51 -04:00
|
|
|
|
import flixel.tweens.FlxEase;
|
2020-10-03 15:32:15 -04:00
|
|
|
|
import flixel.tweens.FlxTween;
|
2020-10-05 16:32:41 -04:00
|
|
|
|
import flixel.ui.FlxBar;
|
2020-10-04 02:42:58 -04:00
|
|
|
|
import flixel.util.FlxColor;
|
2020-10-03 15:32:15 -04:00
|
|
|
|
import flixel.util.FlxTimer;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
import funkin.audio.VoicesGroup;
|
2023-10-17 00:38:28 -04:00
|
|
|
|
import funkin.save.Save;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
import funkin.Highscore.Tallies;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
import funkin.input.PreciseInputManager;
|
2022-03-11 01:30:01 -05:00
|
|
|
|
import funkin.modding.events.ScriptEvent;
|
|
|
|
|
import funkin.modding.events.ScriptEventDispatcher;
|
2022-04-18 20:39:41 -04:00
|
|
|
|
import funkin.play.character.BaseCharacter;
|
2023-05-25 18:34:26 -04:00
|
|
|
|
import funkin.play.character.CharacterData.CharacterDataParser;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
import funkin.play.cutscene.dialogue.Conversation;
|
|
|
|
|
import funkin.play.cutscene.dialogue.ConversationDataParser;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
import funkin.play.cutscene.VanillaCutscenes;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
import funkin.play.cutscene.VideoCutscene;
|
2023-09-08 17:46:44 -04:00
|
|
|
|
import funkin.data.event.SongEventData.SongEventParser;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
import funkin.play.notes.NoteSprite;
|
|
|
|
|
import funkin.play.notes.NoteDirection;
|
|
|
|
|
import funkin.play.notes.Strumline;
|
2023-06-27 18:06:33 -04:00
|
|
|
|
import funkin.play.notes.SustainTrail;
|
2022-07-06 21:49:42 -04:00
|
|
|
|
import funkin.play.scoring.Scoring;
|
2023-06-27 21:29:50 -04:00
|
|
|
|
import funkin.NoteSplash;
|
2022-09-22 06:34:03 -04:00
|
|
|
|
import funkin.play.song.Song;
|
2023-09-08 17:46:44 -04:00
|
|
|
|
import funkin.data.song.SongRegistry;
|
|
|
|
|
import funkin.data.song.SongData.SongEventData;
|
|
|
|
|
import funkin.data.song.SongData.SongNoteData;
|
2023-09-25 23:24:07 -04:00
|
|
|
|
import funkin.data.song.SongData.SongCharacterData;
|
2022-03-08 03:13:53 -05:00
|
|
|
|
import funkin.play.stage.Stage;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
import funkin.play.stage.StageData.StageDataParser;
|
2022-03-08 03:13:53 -05:00
|
|
|
|
import funkin.ui.PopUpStuff;
|
|
|
|
|
import funkin.ui.PreferencesMenu;
|
2023-06-01 18:52:58 -04:00
|
|
|
|
import funkin.ui.stageBuildShit.StageOffsetSubState;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
import funkin.ui.story.StoryMenuState;
|
2023-03-18 15:47:23 -04:00
|
|
|
|
import funkin.util.SerializerUtil;
|
2022-03-11 01:30:01 -05:00
|
|
|
|
import funkin.util.SortUtil;
|
2022-03-09 10:29:03 -05:00
|
|
|
|
import lime.ui.Haptic;
|
2021-03-22 10:09:46 -04:00
|
|
|
|
#if discord_rpc
|
2021-03-21 16:29:47 -04:00
|
|
|
|
import Discord.DiscordClient;
|
|
|
|
|
#end
|
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Parameters used to initialize the PlayState.
|
|
|
|
|
*/
|
|
|
|
|
typedef PlayStateParams =
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The song to play.
|
|
|
|
|
*/
|
|
|
|
|
targetSong:Song,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The difficulty to play the song on.
|
|
|
|
|
* @default `Constants.DEFAULT_DIFFICULTY`
|
|
|
|
|
*/
|
|
|
|
|
?targetDifficulty:String,
|
|
|
|
|
/**
|
|
|
|
|
* The character to play as.
|
|
|
|
|
* @default `bf`, or the first character in the song's character list.
|
|
|
|
|
*/
|
|
|
|
|
?targetCharacter:String,
|
2023-07-26 16:52:58 -04:00
|
|
|
|
/**
|
|
|
|
|
* Whether the song should start in Practice Mode.
|
|
|
|
|
* @default `false`
|
|
|
|
|
*/
|
|
|
|
|
?practiceMode:Bool,
|
|
|
|
|
/**
|
|
|
|
|
* Whether the song should be in minimal mode.
|
|
|
|
|
* @default `false`
|
|
|
|
|
*/
|
|
|
|
|
?minimalMode:Bool,
|
2023-07-26 20:03:31 -04:00
|
|
|
|
/**
|
|
|
|
|
* If specified, the game will jump to the specified timestamp after the countdown ends.
|
|
|
|
|
*/
|
|
|
|
|
?startTimestamp:Float,
|
2023-08-04 16:15:07 -04:00
|
|
|
|
/**
|
|
|
|
|
* If specified, the game will not load the instrumental or vocal tracks,
|
|
|
|
|
* and must be loaded externally.
|
|
|
|
|
*/
|
|
|
|
|
?overrideMusic:Bool,
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
|
/**
|
|
|
|
|
* The gameplay state, where all the rhythm gaming happens.
|
2023-07-26 16:52:58 -04:00
|
|
|
|
* SubState so it can be loaded as a child of the chart editor.
|
2023-02-21 20:58:15 -05:00
|
|
|
|
*/
|
2023-07-26 16:52:58 -04:00
|
|
|
|
class PlayState extends MusicBeatSubState
|
2020-10-03 02:50:15 -04:00
|
|
|
|
{
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* STATIC VARIABLES
|
|
|
|
|
* Static variables should be used for information that must be persisted between states or between resets,
|
|
|
|
|
* such as the active song or song playlist.
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* The currently active PlayState.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* There should be only one PlayState in existance at a time, we can use a singleton.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
|
|
|
|
public static var instance:PlayState = null;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* This sucks. We need this because FlxG.resetState(); assumes the constructor has no arguments.
|
|
|
|
|
* @see https://github.com/HaxeFlixel/flixel/issues/2541
|
|
|
|
|
*/
|
|
|
|
|
static var lastParams:PlayStateParams = null;
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* PUBLIC INSTANCE VARIABLES
|
|
|
|
|
* Public instance variables should be used for information that must be reset or dereferenced
|
|
|
|
|
* every time the state is changed, but may need to be accessed externally.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The currently selected stage.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var currentSong:Song = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The currently selected difficulty.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var currentDifficulty:String = Constants.DEFAULT_DIFFICULTY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The player character being used for this level, as a character ID.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var currentPlayerId:String = 'bf';
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-01-27 02:38:37 -05:00
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The currently active Stage. This is the object containing all the props.
|
2023-01-27 02:38:37 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var currentStage:Stage = null;
|
2023-01-27 02:38:37 -05:00
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* Gets set to true when the PlayState needs to reset (player opted to restart or died).
|
|
|
|
|
* Gets disabled once resetting happens.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var needsReset:Bool = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The current 'Blueball Counter' to display in the pause menu.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
* Resets when you beat a song or go back to the main menu.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var deathCounter:Int = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The player's current health.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-27 13:43:42 -04:00
|
|
|
|
public var health:Float = Constants.HEALTH_STARTING;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The player's current score.
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* TODO: Move this to its own class.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var songScore:Int = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* An empty FlxObject contained in the scene.
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* The current gameplay camera will always follow this object. Tween its position to move the camera smoothly.
|
2023-06-09 15:34:56 -04:00
|
|
|
|
*
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* It needs to be an object in the scene for the camera to be configured to follow it.
|
|
|
|
|
* We optionally make this an FlxSprite so we can draw a debug graphic with it.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
public var cameraFollowPoint:FlxObject;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The camera follow point from the last stage.
|
|
|
|
|
* Used to persist the position of the `cameraFollowPosition` between levels.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var previousCameraFollowPoint:FlxSprite = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* The current camera zoom level.
|
2023-06-09 15:34:56 -04:00
|
|
|
|
*
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The camera zoom is increased every beat, and lerped back to this value every frame, creating a smooth 'zoom-in' effect.
|
|
|
|
|
* Defaults to 1.05 but may be larger or smaller depending on the current stage,
|
|
|
|
|
* and may be changed by the `ZoomCamera` song event.
|
|
|
|
|
*/
|
|
|
|
|
public var defaultCameraZoom:Float = FlxCamera.defaultZoom * 1.05;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The current HUD camera zoom level.
|
2023-06-09 15:34:56 -04:00
|
|
|
|
*
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* The camera zoom is increased every beat, and lerped back to this value every frame, creating a smooth 'zoom-in' effect.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var defaultHUDCameraZoom:Float = FlxCamera.defaultZoom * 1.0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* Intensity of the gameplay camera zoom.
|
|
|
|
|
* @default `1.5%`
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var cameraZoomIntensity:Float = Constants.DEFAULT_ZOOM_INTENSITY;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* Intensity of the HUD camera zoom.
|
|
|
|
|
* @default `3.0%`
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var hudCameraZoomIntensity:Float = Constants.DEFAULT_ZOOM_INTENSITY * 2.0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* How many beats (quarter notes) between camera zooms.
|
|
|
|
|
* @default One camera zoom per measure (four beats).
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public var cameraZoomRate:Int = Constants.DEFAULT_ZOOM_RATE;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the game is currently in the countdown before the song resumes.
|
|
|
|
|
*/
|
|
|
|
|
public var isInCountdown:Bool = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the game is currently in Practice Mode.
|
|
|
|
|
* If true, player will not lose gain or lose score from notes.
|
|
|
|
|
*/
|
|
|
|
|
public var isPracticeMode:Bool = false;
|
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
/**
|
|
|
|
|
* In Minimal Mode, the stage and characters are not loaded and a standard background is used.
|
|
|
|
|
*/
|
|
|
|
|
public var isMinimalMode:Bool = false;
|
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Whether the game is currently in an animated cutscene, and gameplay should be stopped.
|
|
|
|
|
*/
|
|
|
|
|
public var isInCutscene:Bool = false;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Whether the inputs should be disabled for whatever reason... used for the stage edit lol!
|
|
|
|
|
*/
|
|
|
|
|
public var disableKeys:Bool = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
public var startTimestamp:Float = 0.0;
|
|
|
|
|
|
2023-08-04 16:15:07 -04:00
|
|
|
|
var overrideMusic:Bool = false;
|
|
|
|
|
|
2023-08-31 18:47:23 -04:00
|
|
|
|
public var isSubState(get, never):Bool;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
|
|
function get_isSubState():Bool
|
|
|
|
|
{
|
|
|
|
|
return this._parentState != null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 18:47:23 -04:00
|
|
|
|
public var isChartingMode(get, never):Bool;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
|
|
|
|
|
function get_isChartingMode():Bool
|
|
|
|
|
{
|
|
|
|
|
return this._parentState != null && Std.isOfType(this._parentState, ChartEditorState);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-16 17:37:56 -04:00
|
|
|
|
/**
|
|
|
|
|
* The current dialogue.
|
|
|
|
|
*/
|
|
|
|
|
public var currentConversation:Conversation;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Key press inputs which have been received but not yet processed.
|
|
|
|
|
* These are encoded with an OS timestamp, so they
|
|
|
|
|
**/
|
|
|
|
|
var inputPressQueue:Array<PreciseInputEvent> = [];
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Key release inputs which have been received but not yet processed.
|
|
|
|
|
* These are encoded with an OS timestamp, so they
|
|
|
|
|
**/
|
|
|
|
|
var inputReleaseQueue:Array<PreciseInputEvent> = [];
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* PRIVATE INSTANCE VARIABLES
|
|
|
|
|
* Private instance variables should be used for information that must be reset or dereferenced
|
|
|
|
|
* every time the state is reset, but should not be accessed externally.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* The Array containing the upcoming song events.
|
|
|
|
|
* The `update()` function regularly shifts these out to trigger events.
|
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
|
var songEvents:Array<SongEventData>;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* If true, the player is allowed to pause the game.
|
|
|
|
|
* Disabled during the ending of a song.
|
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
|
var mayPauseGame:Bool = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The displayed value of the player's health.
|
|
|
|
|
* Used to provide smooth animations based on linear interpolation of the player's health.
|
|
|
|
|
*/
|
2023-06-27 13:43:42 -04:00
|
|
|
|
var healthLerp:Float = Constants.HEALTH_STARTING;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* How long the user has held the "Skip Video Cutscene" button for.
|
|
|
|
|
*/
|
|
|
|
|
var skipHeldTimer:Float = 0;
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* Forcibly disables all update logic while the game moves back to the Menu state.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* This is used only when a critical error occurs and the game absolutely cannot continue.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
|
var criticalFailure:Bool = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
|
/**
|
2023-06-02 15:35:01 -04:00
|
|
|
|
* False as long as the countdown has not finished yet.
|
|
|
|
|
*/
|
|
|
|
|
var startingSong:Bool = false;
|
|
|
|
|
|
2023-08-09 00:28:09 -04:00
|
|
|
|
/**
|
|
|
|
|
* False until `create()` has completed.
|
|
|
|
|
*/
|
|
|
|
|
var initialized:Bool = false;
|
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* A group of audio tracks, used to play the song's vocals.
|
2023-02-21 20:58:15 -05:00
|
|
|
|
*/
|
2023-08-04 16:15:07 -04:00
|
|
|
|
public var vocals:VoicesGroup;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if discord_rpc
|
|
|
|
|
// Discord RPC variables
|
|
|
|
|
var storyDifficultyText:String = '';
|
|
|
|
|
var iconRPC:String = '';
|
|
|
|
|
var detailsText:String = '';
|
|
|
|
|
var detailsPausedText:String = '';
|
|
|
|
|
#end
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* RENDER OBJECTS
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* The FlxText which displays the current score.
|
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
|
var scoreText:FlxText;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The bar which displays the player's health.
|
|
|
|
|
* Dynamically updated based on the value of `healthLerp` (which is based on `health`).
|
|
|
|
|
*/
|
|
|
|
|
public var healthBar:FlxBar;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The background image used for the health bar.
|
|
|
|
|
* Emma says the image is slightly skewed so I'm leaving it as an image instead of a `createGraphic`.
|
|
|
|
|
*/
|
|
|
|
|
public var healthBarBG:FlxSprite;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The health icon representing the player.
|
|
|
|
|
*/
|
|
|
|
|
public var iconP1:HealthIcon;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The health icon representing the opponent.
|
|
|
|
|
*/
|
|
|
|
|
public var iconP2:HealthIcon;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sprite group containing active player's strumline notes.
|
|
|
|
|
*/
|
|
|
|
|
public var playerStrumline:Strumline;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The sprite group containing opponent's strumline notes.
|
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
public var opponentStrumline:Strumline;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The camera which contains, and controls visibility of, the user interface elements.
|
|
|
|
|
*/
|
|
|
|
|
public var camHUD:FlxCamera;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The camera which contains, and controls visibility of, the stage and characters.
|
|
|
|
|
*/
|
|
|
|
|
public var camGame:FlxCamera;
|
|
|
|
|
|
2023-02-21 20:58:15 -05:00
|
|
|
|
/**
|
|
|
|
|
* The camera which contains, and controls visibility of, a video cutscene.
|
|
|
|
|
*/
|
|
|
|
|
public var camCutscene:FlxCamera;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* The combo popups. Includes the real-time combo counter and the rating.
|
|
|
|
|
*/
|
|
|
|
|
var comboPopUps:PopUpStuff;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The circular sprite that appears while the user is holding down the Skip Cutscene button.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
var skipTimer:FlxPieDial;
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* PROPERTIES
|
|
|
|
|
*/
|
|
|
|
|
/**
|
|
|
|
|
* If a substate is rendering over the PlayState, it is paused and normal update logic is skipped.
|
|
|
|
|
* Examples include:
|
|
|
|
|
* - The Pause screen is open.
|
|
|
|
|
* - The Game Over screen is open.
|
|
|
|
|
* - The Chart Editor screen is open.
|
|
|
|
|
*/
|
2023-01-22 22:25:45 -05:00
|
|
|
|
var isGamePaused(get, never):Bool;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
function get_isGamePaused():Bool
|
|
|
|
|
{
|
|
|
|
|
// Note: If there is a substate which requires the game to act unpaused,
|
|
|
|
|
// this should be changed to include something like `&& Std.isOfType()`
|
|
|
|
|
return this.subState != null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Data for the current difficulty for the current song.
|
|
|
|
|
* Includes chart data, scroll speed, and other information.
|
|
|
|
|
*/
|
2023-08-31 18:47:23 -04:00
|
|
|
|
public var currentChart(get, never):SongDifficulty;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function get_currentChart():SongDifficulty
|
|
|
|
|
{
|
|
|
|
|
if (currentSong == null || currentDifficulty == null) return null;
|
|
|
|
|
return currentSong.getDifficulty(currentDifficulty);
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* The internal ID of the currently active Stage.
|
|
|
|
|
* Used to retrieve the data required to build the `currentStage`.
|
|
|
|
|
*/
|
2023-08-31 18:47:23 -04:00
|
|
|
|
public var currentStageId(get, never):String;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
function get_currentStageId():String
|
|
|
|
|
{
|
|
|
|
|
if (currentChart == null || currentChart.stage == null || currentChart.stage == '') return Constants.DEFAULT_STAGE;
|
|
|
|
|
return currentChart.stage;
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* The length of the current song, in milliseconds.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var currentSongLengthMs(get, never):Float;
|
|
|
|
|
|
|
|
|
|
function get_currentSongLengthMs():Float
|
|
|
|
|
{
|
|
|
|
|
return FlxG?.sound?.music?.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Refactor or document
|
|
|
|
|
var generatedMusic:Bool = false;
|
|
|
|
|
var perfectMode:Bool = false;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Instantiate a new PlayState.
|
|
|
|
|
* @param params The parameters used to initialize the PlayState.
|
|
|
|
|
* Includes information about what song to play and more.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public function new(params:PlayStateParams)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-02 15:35:01 -04:00
|
|
|
|
super();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Validate parameters.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
if (params == null && lastParams == null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-02 15:35:01 -04:00
|
|
|
|
throw 'PlayState constructor called with no available parameters.';
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
else if (params == null)
|
|
|
|
|
{
|
|
|
|
|
trace('WARNING: PlayState constructor called with no parameters. Reusing previous parameters.');
|
|
|
|
|
params = lastParams;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lastParams = params;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Apply parameters.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
currentSong = params.targetSong;
|
|
|
|
|
if (params.targetDifficulty != null) currentDifficulty = params.targetDifficulty;
|
|
|
|
|
if (params.targetCharacter != null) currentPlayerId = params.targetCharacter;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
isPracticeMode = params.practiceMode ?? false;
|
|
|
|
|
isMinimalMode = params.minimalMode ?? false;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
startTimestamp = params.startTimestamp ?? 0.0;
|
2023-08-04 16:15:07 -04:00
|
|
|
|
overrideMusic = params.overrideMusic ?? false;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// Don't do anything else here! Wait until create() when we attach to the camera.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Called when the PlayState is switched to.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
public override function create():Void
|
|
|
|
|
{
|
|
|
|
|
if (instance != null)
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Do something in this case? IDK.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
trace('WARNING: PlayState instance already exists. This should not happen.');
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
instance = this;
|
|
|
|
|
|
2023-06-27 21:29:50 -04:00
|
|
|
|
NoteSplash.buildSplashFrames();
|
|
|
|
|
|
2023-10-09 14:13:14 -04:00
|
|
|
|
if (!assertChartExists()) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (false)
|
|
|
|
|
{
|
|
|
|
|
// Displays the camera follow point as a sprite for debug purposes.
|
|
|
|
|
cameraFollowPoint = new FlxSprite(0, 0).makeGraphic(8, 8, 0xFF00FF00);
|
|
|
|
|
cameraFollowPoint.visible = false;
|
|
|
|
|
cameraFollowPoint.zIndex = 1000000;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Camera follow point is an invisible point in space.
|
|
|
|
|
cameraFollowPoint = new FlxObject(0, 0);
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
// Reduce physics accuracy (who cares!!!) to improve animation quality.
|
|
|
|
|
FlxG.fixedTimestep = false;
|
|
|
|
|
|
|
|
|
|
// This state receives update() even when a substate is active.
|
|
|
|
|
this.persistentUpdate = true;
|
|
|
|
|
// This state receives draw calls even when a substate is active.
|
|
|
|
|
this.persistentDraw = true;
|
|
|
|
|
|
|
|
|
|
// Stop any pre-existing music.
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (!overrideMusic && FlxG.sound.music != null) FlxG.sound.music.stop();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Prepare the current song's instrumental and vocals to be played.
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (!overrideMusic && currentChart != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
|
currentChart.cacheInst();
|
|
|
|
|
currentChart.cacheVocals();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Prepare the Conductor.
|
2023-08-04 16:15:07 -04:00
|
|
|
|
Conductor.forceBPM(null);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
Conductor.mapTimeChanges(currentChart.timeChanges);
|
2023-07-26 20:03:31 -04:00
|
|
|
|
Conductor.update((Conductor.beatLengthMs * -5) + startTimestamp);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// The song is now loaded. We can continue to initialize the play state.
|
|
|
|
|
initCameras();
|
|
|
|
|
initHealthBar();
|
2023-07-26 16:52:58 -04:00
|
|
|
|
if (!isMinimalMode)
|
|
|
|
|
{
|
|
|
|
|
initStage();
|
|
|
|
|
initCharacters();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
initMinimalMode();
|
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
initStrumlines();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Initialize the judgements and combo meter.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
comboPopUps = new PopUpStuff();
|
|
|
|
|
comboPopUps.cameras = [camHUD];
|
|
|
|
|
add(comboPopUps);
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// The little dial that shows up when you hold the Skip Cutscene key.
|
|
|
|
|
skipTimer = new FlxPieDial(16, 16, 32, FlxColor.WHITE, 36, CIRCLE, true, 24);
|
|
|
|
|
skipTimer.amount = 0;
|
|
|
|
|
skipTimer.zIndex = 1000;
|
|
|
|
|
add(skipTimer);
|
|
|
|
|
// Renders only in video cutscene mode.
|
|
|
|
|
skipTimer.cameras = [camCutscene];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if discord_rpc
|
|
|
|
|
// Initialize Discord Rich Presence.
|
|
|
|
|
initDiscord();
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Read the song's note data and pass it to the strumlines.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
generateSong();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Reset the camera's zoom and force it to focus on the camera follow point.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
resetCamera();
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
initPreciseInputs();
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.worldBounds.set(0, 0, FlxG.width, FlxG.height);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// The song is loaded and in the process of starting.
|
|
|
|
|
// This gets set back to false when the chart actually starts.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
startingSong = true;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: We hardcoded the transition into Winter Horrorland. Do this with a ScriptedSong instead.
|
2023-09-08 17:46:44 -04:00
|
|
|
|
if ((currentSong?.id ?? '').toLowerCase() == 'winter-horrorland')
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// VanillaCutscenes will call startCountdown later.
|
|
|
|
|
VanillaCutscenes.playHorrorStartCutscene();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Call a script event to start the countdown.
|
|
|
|
|
// Songs with cutscenes should call event.cancel().
|
|
|
|
|
// As long as they call `PlayState.instance.startCountdown()` later, the countdown will start.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
startCountdown();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 18:08:49 -04:00
|
|
|
|
// Do this last to prevent beatHit from being called before create() is done.
|
|
|
|
|
super.create();
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
leftWatermarkText.cameras = [camHUD];
|
|
|
|
|
rightWatermarkText.cameras = [camHUD];
|
|
|
|
|
|
|
|
|
|
// Initialize some debug stuff.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
#if debug
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Display the version number (and git commit hash) in the bottom right corner.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
this.rightWatermarkText.text = Constants.VERSION;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
|
|
|
|
FlxG.console.registerObject('playState', this);
|
|
|
|
|
#end
|
2023-08-09 00:28:09 -04:00
|
|
|
|
|
|
|
|
|
initialized = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-09 14:13:14 -04:00
|
|
|
|
function assertChartExists():Bool
|
|
|
|
|
{
|
|
|
|
|
// Returns null if the song failed to load or doesn't have the selected difficulty.
|
|
|
|
|
if (currentSong == null || currentChart == null)
|
|
|
|
|
{
|
|
|
|
|
// We have encountered a critical error. Prevent Flixel from trying to run any gameplay logic.
|
|
|
|
|
criticalFailure = true;
|
|
|
|
|
|
|
|
|
|
// Choose an error message.
|
|
|
|
|
var message:String = 'There was a critical error. Click OK to return to the main menu.';
|
|
|
|
|
if (currentSong == null)
|
|
|
|
|
{
|
|
|
|
|
message = 'The was a critical error loading this song\'s chart. Click OK to return to the main menu.';
|
|
|
|
|
}
|
|
|
|
|
else if (currentDifficulty == null)
|
|
|
|
|
{
|
|
|
|
|
message = 'The was a critical error selecting a difficulty for this song. Click OK to return to the main menu.';
|
|
|
|
|
}
|
|
|
|
|
else if (currentSong.getDifficulty(currentDifficulty) == null)
|
|
|
|
|
{
|
|
|
|
|
message = 'The was a critical error retrieving data for this song on "$currentDifficulty" difficulty. Click OK to return to the main menu.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Display a popup. This blocks the application until the user clicks OK.
|
|
|
|
|
lime.app.Application.current.window.alert(message, 'Error loading PlayState');
|
|
|
|
|
|
|
|
|
|
// Force the user back to the main menu.
|
|
|
|
|
if (isSubState)
|
|
|
|
|
{
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlxG.switchState(new MainMenuState());
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
public override function update(elapsed:Float):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (criticalFailure) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
super.update(elapsed);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
updateHealthBar();
|
|
|
|
|
updateScoreText();
|
|
|
|
|
|
|
|
|
|
// Handle restarting the song when needed (player death or pressing Retry)
|
|
|
|
|
if (needsReset)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-10-09 14:13:14 -04:00
|
|
|
|
if (!assertChartExists()) return;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dispatchEvent(new ScriptEvent(ScriptEvent.SONG_RETRY));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
resetCamera();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
persistentUpdate = true;
|
|
|
|
|
persistentDraw = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
startingSong = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
inputSpitter = [];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Reset music properly.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.pause();
|
2023-07-26 20:03:31 -04:00
|
|
|
|
FlxG.sound.music.time = (startTimestamp);
|
2023-10-09 14:19:52 -04:00
|
|
|
|
|
2023-10-18 01:02:10 -04:00
|
|
|
|
if (!overrideMusic)
|
|
|
|
|
{
|
|
|
|
|
vocals = currentChart.buildVocals();
|
|
|
|
|
|
|
|
|
|
if (vocals.members.length == 0)
|
|
|
|
|
{
|
|
|
|
|
trace('WARNING: No vocals found for this song.');
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-09 14:19:52 -04:00
|
|
|
|
vocals.pause();
|
2023-06-22 01:41:01 -04:00
|
|
|
|
vocals.time = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.volume = 1;
|
|
|
|
|
vocals.volume = 1;
|
|
|
|
|
vocals.playerVolume = 1;
|
|
|
|
|
vocals.opponentVolume = 1;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 21:34:38 -04:00
|
|
|
|
if (currentStage != null) currentStage.resetStage();
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
2023-07-31 13:42:13 -04:00
|
|
|
|
playerStrumline.vwooshNotes();
|
|
|
|
|
opponentStrumline.vwooshNotes();
|
|
|
|
|
|
2023-07-25 21:39:19 -04:00
|
|
|
|
playerStrumline.clean();
|
|
|
|
|
opponentStrumline.clean();
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Delete all notes and reset the arrays.
|
|
|
|
|
regenNoteData();
|
|
|
|
|
|
|
|
|
|
// Reset camera zooming
|
|
|
|
|
cameraZoomIntensity = Constants.DEFAULT_ZOOM_INTENSITY;
|
|
|
|
|
hudCameraZoomIntensity = Constants.DEFAULT_ZOOM_INTENSITY * 2.0;
|
|
|
|
|
cameraZoomRate = Constants.DEFAULT_ZOOM_RATE;
|
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health = Constants.HEALTH_STARTING;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
songScore = 0;
|
|
|
|
|
Highscore.tallies.combo = 0;
|
|
|
|
|
Countdown.performCountdown(currentStageId.startsWith('school'));
|
|
|
|
|
|
|
|
|
|
needsReset = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update the conductor.
|
|
|
|
|
if (startingSong)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (isInCountdown)
|
|
|
|
|
{
|
2023-07-26 20:03:31 -04:00
|
|
|
|
Conductor.update(Conductor.songPosition + elapsed * 1000);
|
|
|
|
|
if (Conductor.songPosition >= startTimestamp) startSong();
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// DO NOT FORGET TO REMOVE THE HARDCODE! WHEN I MAKE BETTER OFFSET SYSTEM!
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// :nerd: um ackshually it's not 13 it's 11.97278911564
|
2023-09-25 23:24:07 -04:00
|
|
|
|
if (Constants.EXT_SOUND == 'mp3') Conductor.offset = Constants.MP3_DELAY_MS;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
Conductor.update();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (!isGamePaused)
|
|
|
|
|
{
|
|
|
|
|
// Interpolation type beat
|
|
|
|
|
if (Conductor.lastSongPos != Conductor.songPosition)
|
|
|
|
|
{
|
|
|
|
|
Conductor.lastSongPos = Conductor.songPosition;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var androidPause:Bool = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if android
|
|
|
|
|
androidPause = FlxG.android.justPressed.BACK;
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Attempt to pause the game.
|
|
|
|
|
if ((controls.PAUSE || androidPause) && isInCountdown && mayPauseGame)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var event = new PauseScriptEvent(FlxG.random.bool(1 / 1000));
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dispatchEvent(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (!event.eventCanceled)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Pause updates while the substate is open, preventing the game state from advancing.
|
|
|
|
|
persistentUpdate = false;
|
|
|
|
|
// Enable drawing while the substate is open, allowing the game state to be shown behind the pause menu.
|
|
|
|
|
persistentDraw = true;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// There is a 1/1000 change to use a special pause menu.
|
|
|
|
|
// This prevents the player from resuming, but that's the point.
|
|
|
|
|
// It's a reference to Gitaroo Man, which doesn't let you pause the game.
|
2023-07-26 16:52:58 -04:00
|
|
|
|
if (!isSubState && event.gitaroo)
|
2023-06-22 01:41:01 -04:00
|
|
|
|
{
|
|
|
|
|
FlxG.switchState(new GitarooPause(
|
|
|
|
|
{
|
|
|
|
|
targetSong: currentSong,
|
|
|
|
|
targetDifficulty: currentDifficulty,
|
|
|
|
|
targetCharacter: currentPlayerId,
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var boyfriendPos:FlxPoint = new FlxPoint(0, 0);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Prevent the game from crashing if Boyfriend isn't present.
|
|
|
|
|
if (currentStage != null && currentStage.getBoyfriend() != null)
|
|
|
|
|
{
|
|
|
|
|
boyfriendPos = currentStage.getBoyfriend().getScreenPosition();
|
|
|
|
|
}
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
var pauseSubState:FlxSubState = new PauseSubState(isChartingMode);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
2023-08-02 11:00:23 -04:00
|
|
|
|
FlxTransitionableSubState.skipNextTransIn = true;
|
|
|
|
|
FlxTransitionableSubState.skipNextTransOut = true;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
openSubState(pauseSubState);
|
|
|
|
|
pauseSubState.camera = camHUD;
|
|
|
|
|
// boyfriendPos.put(); // TODO: Why is this here?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if discord_rpc
|
|
|
|
|
DiscordClient.changePresence(detailsPausedText, currentSong.song + ' (' + storyDifficultyText + ')', iconRPC);
|
2023-02-21 20:58:15 -05:00
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Cap health.
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (health > Constants.HEALTH_MAX) health = Constants.HEALTH_MAX;
|
|
|
|
|
if (health < Constants.HEALTH_MIN) health = Constants.HEALTH_MIN;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Lerp the camera zoom towards the target level.
|
|
|
|
|
if (subState == null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.camera.zoom = FlxMath.lerp(defaultCameraZoom, FlxG.camera.zoom, 0.95);
|
|
|
|
|
camHUD.zoom = FlxMath.lerp(defaultHUDCameraZoom, camHUD.zoom, 0.95);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentStage != null)
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.watch.addQuick('bfAnim', currentStage.getBoyfriend().getCurrentAnimation());
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Add a song event for Handle GF dance speed.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Handle player death.
|
|
|
|
|
if (!isInCutscene && !disableKeys && !_exiting)
|
|
|
|
|
{
|
|
|
|
|
// RESET = Quick Game Over Screen
|
|
|
|
|
if (controls.RESET)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health = Constants.HEALTH_MIN;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('RESET = True');
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if CAN_CHEAT // brandon's a pussy
|
|
|
|
|
if (controls.CHEAT)
|
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += 0.25 * Constants.HEALTH_MAX; // +25% health.
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('User is cheating!');
|
|
|
|
|
}
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (health <= Constants.HEALTH_MIN && !isPracticeMode)
|
2023-06-22 01:41:01 -04:00
|
|
|
|
{
|
|
|
|
|
vocals.pause();
|
|
|
|
|
FlxG.sound.music.pause();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
deathCounter += 1;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dispatchEvent(new ScriptEvent(ScriptEvent.GAME_OVER));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Disable updates, preventing animations in the background from playing.
|
|
|
|
|
persistentUpdate = false;
|
|
|
|
|
#if debug
|
|
|
|
|
if (FlxG.keys.pressed.THREE)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Change the key or delete this?
|
|
|
|
|
// In debug builds, pressing 3 to kill the player makes the background transparent.
|
|
|
|
|
persistentDraw = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
#end
|
|
|
|
|
persistentDraw = false;
|
|
|
|
|
#if debug
|
|
|
|
|
}
|
|
|
|
|
#end
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var gameOverSubState = new GameOverSubState();
|
2023-08-02 18:08:49 -04:00
|
|
|
|
FlxTransitionableSubState.skipNextTransIn = true;
|
|
|
|
|
FlxTransitionableSubState.skipNextTransOut = true;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
openSubState(gameOverSubState);
|
|
|
|
|
|
|
|
|
|
#if discord_rpc
|
|
|
|
|
// Game Over doesn't get his own variable because it's only used here
|
|
|
|
|
DiscordClient.changePresence('Game Over - ' + detailsText, currentSong.song + ' (' + storyDifficultyText + ')', iconRPC);
|
|
|
|
|
#end
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// Query and activate song events.
|
|
|
|
|
// TODO: Check that these work even when songPosition is less than 0.
|
|
|
|
|
if (songEvents != null && songEvents.length > 0)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var songEventsToActivate:Array<SongEventData> = SongEventParser.queryEvents(songEvents, Conductor.songPosition);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (songEventsToActivate.length > 0)
|
|
|
|
|
{
|
|
|
|
|
trace('Found ${songEventsToActivate.length} event(s) to activate.');
|
|
|
|
|
for (event in songEventsToActivate)
|
|
|
|
|
{
|
2023-07-26 21:34:38 -04:00
|
|
|
|
// If an event is trying to play, but it's over 5 seconds old, skip it.
|
|
|
|
|
if (event.time - Conductor.songPosition < -5000)
|
|
|
|
|
{
|
|
|
|
|
event.activated = true;
|
|
|
|
|
continue;
|
|
|
|
|
};
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var eventEvent:SongEventScriptEvent = new SongEventScriptEvent(event);
|
|
|
|
|
dispatchEvent(eventEvent);
|
|
|
|
|
// Calling event.cancelEvent() skips the event. Neat!
|
|
|
|
|
if (!eventEvent.eventCanceled)
|
|
|
|
|
{
|
|
|
|
|
SongEventParser.handleEvent(event);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Handle keybinds.
|
|
|
|
|
processInputQueue();
|
|
|
|
|
if (!isInCutscene && !disableKeys) debugKeyShit();
|
|
|
|
|
if (isInCutscene && !disableKeys) handleCutsceneKeys(elapsed);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Moving notes into position is now done by Strumline.update().
|
2023-06-27 17:22:51 -04:00
|
|
|
|
processNotes(elapsed);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
public override function dispatchEvent(event:ScriptEvent):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// ORDER: Module, Stage, Character, Song, Conversation, Note
|
|
|
|
|
// Modules should get the first chance to cancel the event.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// super.dispatchEvent(event) dispatches event to module scripts.
|
|
|
|
|
super.dispatchEvent(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Dispatch event to stage script.
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentStage, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Dispatch event to character script(s).
|
|
|
|
|
if (currentStage != null) currentStage.dispatchToCharacters(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Dispatch event to song script.
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentSong, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Dispatch event to conversation script.
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentConversation, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Dispatch event to note scripts
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Function called before opening a new substate.
|
|
|
|
|
* @param subState The substate to open.
|
|
|
|
|
*/
|
|
|
|
|
public override function openSubState(subState:FlxSubState):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// If there is a substate which requires the game to continue,
|
|
|
|
|
// then make this a condition.
|
2023-08-04 17:25:13 -04:00
|
|
|
|
var shouldPause = (Std.isOfType(subState, PauseSubState) || Std.isOfType(subState, GameOverSubState));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (shouldPause)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Pause the music.
|
|
|
|
|
if (FlxG.sound.music != null)
|
|
|
|
|
{
|
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
|
if (vocals != null) vocals.pause();
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Pause the countdown.
|
|
|
|
|
Countdown.pauseCountdown();
|
|
|
|
|
}
|
2023-08-04 17:25:13 -04:00
|
|
|
|
else {}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
super.openSubState(subState);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Function called before closing the current substate.
|
|
|
|
|
* @param subState
|
|
|
|
|
*/
|
|
|
|
|
public override function closeSubState():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (Std.isOfType(subState, PauseSubState))
|
2023-06-22 01:41:01 -04:00
|
|
|
|
{
|
|
|
|
|
var event:ScriptEvent = new ScriptEvent(ScriptEvent.RESUME, true);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dispatchEvent(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (event.eventCanceled) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-02 18:08:49 -04:00
|
|
|
|
// Resume
|
|
|
|
|
FlxG.sound.music.play();
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (FlxG.sound.music != null && !startingSong && !isInCutscene) resyncVocals();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Resume the countdown.
|
|
|
|
|
Countdown.resumeCountdown();
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if discord_rpc
|
|
|
|
|
if (startTimer.finished)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
DiscordClient.changePresence(detailsText, '${currentChart.songName} ($storyDifficultyText)', iconRPC, true,
|
|
|
|
|
currentSongLengthMs - Conductor.songPosition);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
DiscordClient.changePresence(detailsText, '${currentChart.songName} ($storyDifficultyText)', iconRPC);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-08-04 16:15:07 -04:00
|
|
|
|
else if (Std.isOfType(subState, Transition))
|
|
|
|
|
{
|
|
|
|
|
// Do nothing.
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
super.closeSubState();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
#if discord_rpc
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Function called when the game window gains focus.
|
|
|
|
|
*/
|
|
|
|
|
public override function onFocus():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (health > Constants.HEALTH_MIN && !paused && FlxG.autoPause)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (Conductor.songPosition > 0.0) DiscordClient.changePresence(detailsText, currentSong.song
|
|
|
|
|
+ ' ('
|
|
|
|
|
+ storyDifficultyText
|
|
|
|
|
+ ')', iconRPC, true,
|
|
|
|
|
currentSongLengthMs
|
|
|
|
|
- Conductor.songPosition);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
else
|
2023-06-02 15:35:01 -04:00
|
|
|
|
DiscordClient.changePresence(detailsText, currentSong.song + ' (' + storyDifficultyText + ')', iconRPC);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
super.onFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Function called when the game window loses focus.
|
|
|
|
|
*/
|
|
|
|
|
public override function onFocusLost():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (health > Constants.HEALTH_MIN && !paused && FlxG.autoPause) DiscordClient.changePresence(detailsPausedText,
|
|
|
|
|
currentSong.song + ' (' + storyDifficultyText + ')', iconRPC);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
super.onFocusLost();
|
|
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* This function is called whenever Flixel switches switching to a new FlxState.
|
|
|
|
|
* @return Whether to actually switch to the new state.
|
|
|
|
|
*/
|
2023-07-31 14:08:48 -04:00
|
|
|
|
@:haxe.warning("-WDeprecated")
|
2023-06-22 01:41:01 -04:00
|
|
|
|
override function switchTo(nextState:FlxState):Bool
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var result:Bool = super.switchTo(nextState);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (result)
|
|
|
|
|
{
|
|
|
|
|
performCleanup();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
return result;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes any references to the current stage, then clears the stage cache,
|
|
|
|
|
* then reloads all the stages.
|
2023-06-08 16:30:45 -04:00
|
|
|
|
*
|
2023-01-22 19:55:30 -05:00
|
|
|
|
* This is useful for when you want to edit a stage without reloading the whole game.
|
|
|
|
|
* Reloading works on both the JSON and the HXC, if applicable.
|
2023-06-08 16:30:45 -04:00
|
|
|
|
*
|
2023-01-22 19:55:30 -05:00
|
|
|
|
* Call this by pressing F5 on a debug build.
|
|
|
|
|
*/
|
2023-06-02 15:35:01 -04:00
|
|
|
|
override function debug_refreshModules():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-13 20:27:45 -04:00
|
|
|
|
// Prevent further gameplay updates, which will try to reference dead objects.
|
|
|
|
|
criticalFailure = true;
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
// Remove the current stage. If the stage gets deleted while it's still in use,
|
|
|
|
|
// it'll probably crash the game or something.
|
|
|
|
|
if (this.currentStage != null)
|
|
|
|
|
{
|
|
|
|
|
remove(currentStage);
|
|
|
|
|
var event:ScriptEvent = new ScriptEvent(ScriptEvent.DESTROY, false);
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentStage, event);
|
|
|
|
|
currentStage = null;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 20:27:45 -04:00
|
|
|
|
// Stop the instrumental.
|
|
|
|
|
if (FlxG.sound.music != null)
|
|
|
|
|
{
|
|
|
|
|
FlxG.sound.music.stop();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-02 15:35:01 -04:00
|
|
|
|
// Stop the vocals.
|
2023-07-13 20:27:45 -04:00
|
|
|
|
if (vocals != null && vocals.exists)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
|
|
|
|
vocals.stop();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
super.debug_refreshModules();
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
|
|
|
|
var event:ScriptEvent = new ScriptEvent(ScriptEvent.CREATE, false);
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentSong, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
override function stepHit():Bool
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-08-09 00:28:09 -04:00
|
|
|
|
if (criticalFailure || !initialized) return false;
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// super.stepHit() returns false if a module cancelled the event.
|
|
|
|
|
if (!super.stepHit()) return false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-03 11:40:19 -04:00
|
|
|
|
if (isGamePaused) return false;
|
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
if (!startingSong
|
|
|
|
|
&& FlxG.sound.music != null
|
2023-06-26 20:40:26 -04:00
|
|
|
|
&& (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 200
|
|
|
|
|
|| Math.abs(vocals.checkSyncError(Conductor.songPosition - Conductor.offset)) > 200))
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace("VOCALS NEED RESYNC");
|
|
|
|
|
if (vocals != null) trace(vocals.checkSyncError(Conductor.songPosition - Conductor.offset));
|
|
|
|
|
trace(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset));
|
|
|
|
|
resyncVocals();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (iconP1 != null) iconP1.onStepHit(Std.int(Conductor.currentStep));
|
|
|
|
|
if (iconP2 != null) iconP2.onStepHit(Std.int(Conductor.currentStep));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
return true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
override function beatHit():Bool
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-08-09 00:28:09 -04:00
|
|
|
|
if (criticalFailure || !initialized) return false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// super.beatHit() returns false if a module cancelled the event.
|
|
|
|
|
if (!super.beatHit()) return false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-03 11:40:19 -04:00
|
|
|
|
if (isGamePaused) return false;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (generatedMusic)
|
|
|
|
|
{
|
|
|
|
|
// TODO: Sort more efficiently, or less often, to improve performance.
|
|
|
|
|
// activeNotes.sort(SortUtil.byStrumtime, FlxSort.DESCENDING);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Only zoom camera if we are zoomed by less than 35%.
|
|
|
|
|
if (FlxG.camera.zoom < (1.35 * defaultCameraZoom) && cameraZoomRate > 0 && Conductor.currentBeat % cameraZoomRate == 0)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Zoom camera in (1.5%)
|
|
|
|
|
FlxG.camera.zoom += cameraZoomIntensity * defaultCameraZoom;
|
|
|
|
|
// Hud zooms double (3%)
|
|
|
|
|
camHUD.zoom += hudCameraZoomIntensity * defaultHUDCameraZoom;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// trace('Not bopping camera: ${FlxG.camera.zoom} < ${(1.35 * defaultCameraZoom)} && ${cameraZoomRate} > 0 && ${Conductor.currentBeat} % ${cameraZoomRate} == ${Conductor.currentBeat % cameraZoomRate}}');
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// That combo milestones that got spoiled that one time.
|
|
|
|
|
// Comes with NEAT visual and audio effects.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// bruh this var is bonkers i thot it was a function lmfaooo
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Break up into individual lines to aid debugging.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var shouldShowComboText:Bool = false;
|
|
|
|
|
// TODO: Re-enable combo text (how to do this without sections?).
|
|
|
|
|
// if (currentSong != null)
|
|
|
|
|
// {
|
|
|
|
|
// shouldShowComboText = (Conductor.currentBeat % 8 == 7);
|
|
|
|
|
// var daSection = .getSong()[Std.int(Conductor.currentBeat / 16)];
|
|
|
|
|
// shouldShowComboText = shouldShowComboText && (daSection != null && daSection.mustHitSection);
|
|
|
|
|
// shouldShowComboText = shouldShowComboText && (Highscore.tallies.combo > 5);
|
|
|
|
|
//
|
|
|
|
|
// var daNextSection = .getSong()[Std.int(Conductor.currentBeat / 16) + 1];
|
|
|
|
|
// var isEndOfSong = .getSong().length < Std.int(Conductor.currentBeat / 16);
|
|
|
|
|
// shouldShowComboText = shouldShowComboText && (isEndOfSong || (daNextSection != null && !daNextSection.mustHitSection));
|
|
|
|
|
// }
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (shouldShowComboText)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var animShit:ComboMilestone = new ComboMilestone(-100, 300, Highscore.tallies.combo);
|
|
|
|
|
animShit.scrollFactor.set(0.6, 0.6);
|
|
|
|
|
animShit.cameras = [camHUD];
|
|
|
|
|
add(animShit);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var frameShit:Float = (1 / 24) * 2; // equals 2 frames in the animation
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
new FlxTimer().start(((Conductor.beatLengthMs / 1000) * 1.25) - frameShit, function(tmr) {
|
|
|
|
|
animShit.forceFinish();
|
|
|
|
|
});
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (playerStrumline != null) playerStrumline.onBeatHit();
|
|
|
|
|
if (opponentStrumline != null) opponentStrumline.onBeatHit();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Make the characters dance on the beat
|
|
|
|
|
danceOnBeat();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
return true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
override function destroy():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentConversation != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
remove(currentConversation);
|
|
|
|
|
currentConversation.kill();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
super.destroy();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Handles characters dancing to the beat of the current song.
|
|
|
|
|
*
|
|
|
|
|
* TODO: Move some of this logic into `Bopper.hx`, or individual character scripts.
|
|
|
|
|
*/
|
|
|
|
|
function danceOnBeat():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentStage == null) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Add HEY! song events to Tutorial.
|
|
|
|
|
if (Conductor.currentBeat % 16 == 15
|
|
|
|
|
&& currentStage.getDad().characterId == 'gf'
|
|
|
|
|
&& Conductor.currentBeat > 16
|
|
|
|
|
&& Conductor.currentBeat < 48)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentStage.getBoyfriend().playAnimation('hey', true);
|
|
|
|
|
currentStage.getDad().playAnimation('cheer', true);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the game and HUD cameras.
|
|
|
|
|
*/
|
|
|
|
|
function initCameras():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
camGame = new SwagCamera();
|
|
|
|
|
camHUD = new FlxCamera();
|
|
|
|
|
camHUD.bgColor.alpha = 0; // Show the game scene behind the camera.
|
|
|
|
|
camCutscene = new FlxCamera();
|
|
|
|
|
camCutscene.bgColor.alpha = 0; // Show the game scene behind the camera.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.cameras.reset(camGame);
|
|
|
|
|
FlxG.cameras.add(camHUD, false);
|
|
|
|
|
FlxG.cameras.add(camCutscene, false);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Configure camera follow point.
|
|
|
|
|
if (previousCameraFollowPoint != null)
|
|
|
|
|
{
|
|
|
|
|
cameraFollowPoint.setPosition(previousCameraFollowPoint.x, previousCameraFollowPoint.y);
|
|
|
|
|
previousCameraFollowPoint = null;
|
|
|
|
|
}
|
|
|
|
|
add(cameraFollowPoint);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the health bar on the HUD.
|
|
|
|
|
*/
|
|
|
|
|
function initHealthBar():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-10-17 00:38:28 -04:00
|
|
|
|
var healthBarYPos:Float = Preferences.downscroll ? FlxG.height * 0.1 : FlxG.height * 0.9;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
healthBarBG = new FlxSprite(0, healthBarYPos).loadGraphic(Paths.image('healthBar'));
|
|
|
|
|
healthBarBG.screenCenter(X);
|
|
|
|
|
healthBarBG.scrollFactor.set(0, 0);
|
|
|
|
|
add(healthBarBG);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
healthBar = new FlxBar(healthBarBG.x + 4, healthBarBG.y + 4, RIGHT_TO_LEFT, Std.int(healthBarBG.width - 8), Std.int(healthBarBG.height - 8), this,
|
|
|
|
|
'healthLerp', 0, 2);
|
|
|
|
|
healthBar.scrollFactor.set();
|
|
|
|
|
healthBar.createFilledBar(Constants.COLOR_HEALTH_BAR_RED, Constants.COLOR_HEALTH_BAR_GREEN);
|
|
|
|
|
add(healthBar);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// The score text below the health bar.
|
|
|
|
|
scoreText = new FlxText(healthBarBG.x + healthBarBG.width - 190, healthBarBG.y + 30, 0, '', 20);
|
|
|
|
|
scoreText.setFormat(Paths.font('vcr.ttf'), 16, FlxColor.WHITE, RIGHT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
|
|
|
|
|
scoreText.scrollFactor.set();
|
|
|
|
|
add(scoreText);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Move the health bar to the HUD camera.
|
|
|
|
|
healthBar.cameras = [camHUD];
|
|
|
|
|
healthBarBG.cameras = [camHUD];
|
|
|
|
|
scoreText.cameras = [camHUD];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Generates the stage and all its props.
|
|
|
|
|
*/
|
|
|
|
|
function initStage():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
loadStage(currentStageId);
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
function initMinimalMode():Void
|
|
|
|
|
{
|
|
|
|
|
// Create the green background.
|
|
|
|
|
var menuBG = new FlxSprite().loadGraphic(Paths.image('menuDesat'));
|
|
|
|
|
menuBG.color = 0xFF4CAF50;
|
|
|
|
|
menuBG.setGraphicSize(Std.int(menuBG.width * 1.1));
|
|
|
|
|
menuBG.updateHitbox();
|
|
|
|
|
menuBG.screenCenter();
|
|
|
|
|
menuBG.scrollFactor.set(0, 0);
|
|
|
|
|
menuBG.zIndex = -1000;
|
|
|
|
|
add(menuBG);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Loads stage data from cache, assembles the props,
|
|
|
|
|
* and adds it to the state.
|
|
|
|
|
* @param id
|
|
|
|
|
*/
|
|
|
|
|
function loadStage(id:String):Void
|
|
|
|
|
{
|
|
|
|
|
currentStage = StageDataParser.fetchStage(id);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentStage != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Actually create and position the sprites.
|
|
|
|
|
var event:ScriptEvent = new ScriptEvent(ScriptEvent.CREATE, false);
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentStage, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Apply camera zoom level from stage data.
|
|
|
|
|
defaultCameraZoom = currentStage.camZoom;
|
2023-02-22 14:46:46 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Add the stage to the scene.
|
|
|
|
|
this.add(currentStage);
|
2023-02-22 15:01:07 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if debug
|
|
|
|
|
FlxG.console.registerObject('stage', currentStage);
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// lolol
|
|
|
|
|
lime.app.Application.current.window.alert('Nice job, you ignoramus. $id isn\'t a real stage.\nI\'m falling back to the default so the game doesn\'t shit itself.',
|
|
|
|
|
'Stage Error');
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-21 20:58:15 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Generates the character sprites and adds them to the stage.
|
|
|
|
|
*/
|
|
|
|
|
function initCharacters():Void
|
|
|
|
|
{
|
|
|
|
|
if (currentSong == null || currentChart == null)
|
|
|
|
|
{
|
|
|
|
|
trace('Song difficulty could not be loaded.');
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-09-25 23:24:07 -04:00
|
|
|
|
var currentCharacterData:SongCharacterData = currentChart.characters; // Switch the character we are playing as by manipulating currentPlayerId.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// GIRLFRIEND
|
|
|
|
|
//
|
2023-09-25 23:24:07 -04:00
|
|
|
|
var girlfriend:BaseCharacter = CharacterDataParser.fetchCharacter(currentCharacterData.girlfriend);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (girlfriend != null)
|
|
|
|
|
{
|
|
|
|
|
girlfriend.characterType = CharacterType.GF;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-09-25 23:24:07 -04:00
|
|
|
|
else if (currentCharacterData.girlfriend != '')
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
|
trace('WARNING: Could not load girlfriend character with ID ${currentCharacterData.girlfriend}, skipping...');
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Chosen GF was '' so we don't load one.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// DAD
|
|
|
|
|
//
|
2023-09-25 23:24:07 -04:00
|
|
|
|
var dad:BaseCharacter = CharacterDataParser.fetchCharacter(currentCharacterData.opponent);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (dad != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dad.characterType = CharacterType.DAD;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// OPPONENT HEALTH ICON
|
|
|
|
|
//
|
2023-07-13 20:27:45 -04:00
|
|
|
|
iconP2 = new HealthIcon('dad', 1);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
iconP2.y = healthBar.y - (iconP2.height / 2);
|
2023-07-13 20:27:45 -04:00
|
|
|
|
dad.initHealthIcon(true); // Apply the character ID here
|
2023-06-22 01:41:01 -04:00
|
|
|
|
add(iconP2);
|
|
|
|
|
iconP2.cameras = [camHUD];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// BOYFRIEND
|
|
|
|
|
//
|
2023-09-25 23:24:07 -04:00
|
|
|
|
var boyfriend:BaseCharacter = CharacterDataParser.fetchCharacter(currentCharacterData.player);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (boyfriend != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
boyfriend.characterType = CharacterType.BF;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// PLAYER HEALTH ICON
|
|
|
|
|
//
|
2023-07-13 20:27:45 -04:00
|
|
|
|
iconP1 = new HealthIcon('bf', 0);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
iconP1.y = healthBar.y - (iconP1.height / 2);
|
2023-07-13 20:27:45 -04:00
|
|
|
|
boyfriend.initHealthIcon(false); // Apply the character ID here
|
2023-06-22 01:41:01 -04:00
|
|
|
|
add(iconP1);
|
|
|
|
|
iconP1.cameras = [camHUD];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
//
|
|
|
|
|
// ADD CHARACTERS TO SCENE
|
|
|
|
|
//
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentStage != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Characters get added to the stage, not the main scene.
|
|
|
|
|
if (girlfriend != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentStage.addCharacter(girlfriend, GF);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if debug
|
|
|
|
|
FlxG.console.registerObject('gf', girlfriend);
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (boyfriend != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentStage.addCharacter(boyfriend, BF);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
#if debug
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.console.registerObject('bf', boyfriend);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
#end
|
2023-06-16 17:37:56 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (dad != null)
|
2023-06-16 17:37:56 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentStage.addCharacter(dad, DAD);
|
|
|
|
|
// Camera starts at dad.
|
|
|
|
|
cameraFollowPoint.setPosition(dad.cameraFocusPoint.x, dad.cameraFocusPoint.y);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if debug
|
|
|
|
|
FlxG.console.registerObject('dad', dad);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
#end
|
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// Rearrange by z-indexes.
|
|
|
|
|
currentStage.refresh();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-16 17:37:56 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Constructs the strumlines for each player.
|
|
|
|
|
*/
|
|
|
|
|
function initStrumlines():Void
|
2023-02-21 20:58:15 -05:00
|
|
|
|
{
|
2023-07-13 20:27:45 -04:00
|
|
|
|
var noteStyleId:String = switch (currentStageId)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-13 20:27:45 -04:00
|
|
|
|
case 'school': 'pixel';
|
|
|
|
|
case 'schoolEvil': 'pixel';
|
2023-10-21 01:04:50 -04:00
|
|
|
|
default: Constants.DEFAULT_NOTE_STYLE;
|
2023-07-13 20:27:45 -04:00
|
|
|
|
}
|
|
|
|
|
var noteStyle:NoteStyle = NoteStyleRegistry.instance.fetchEntry(noteStyleId);
|
|
|
|
|
if (noteStyle == null) noteStyle = NoteStyleRegistry.instance.fetchDefault();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-13 20:27:45 -04:00
|
|
|
|
playerStrumline = new Strumline(noteStyle, true);
|
|
|
|
|
opponentStrumline = new Strumline(noteStyle, false);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
add(playerStrumline);
|
|
|
|
|
add(opponentStrumline);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// Position the player strumline on the right half of the screen
|
|
|
|
|
playerStrumline.x = FlxG.width / 2 + Constants.STRUMLINE_X_OFFSET; // Classic style
|
|
|
|
|
// playerStrumline.x = FlxG.width - playerStrumline.width - Constants.STRUMLINE_X_OFFSET; // Centered style
|
2023-10-17 00:38:28 -04:00
|
|
|
|
playerStrumline.y = Preferences.downscroll ? FlxG.height - playerStrumline.height - Constants.STRUMLINE_Y_OFFSET : Constants.STRUMLINE_Y_OFFSET;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
playerStrumline.zIndex = 200;
|
|
|
|
|
playerStrumline.cameras = [camHUD];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// Position the opponent strumline on the left half of the screen
|
2023-06-22 01:41:01 -04:00
|
|
|
|
opponentStrumline.x = Constants.STRUMLINE_X_OFFSET;
|
2023-10-17 00:38:28 -04:00
|
|
|
|
opponentStrumline.y = Preferences.downscroll ? FlxG.height - opponentStrumline.height - Constants.STRUMLINE_Y_OFFSET : Constants.STRUMLINE_Y_OFFSET;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
opponentStrumline.zIndex = 100;
|
|
|
|
|
opponentStrumline.cameras = [camHUD];
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (!PlayStatePlaylist.isStoryMode)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
playerStrumline.fadeInArrows();
|
|
|
|
|
opponentStrumline.fadeInArrows();
|
2023-02-21 20:58:15 -05:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
this.refresh();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the Discord Rich Presence.
|
|
|
|
|
*/
|
|
|
|
|
function initDiscord():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if discord_rpc
|
|
|
|
|
storyDifficultyText = difficultyString();
|
|
|
|
|
iconRPC = currentSong.player2;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// To avoid having duplicate images in Discord assets
|
|
|
|
|
switch (iconRPC)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'senpai-angry':
|
|
|
|
|
iconRPC = 'senpai';
|
|
|
|
|
case 'monster-christmas':
|
|
|
|
|
iconRPC = 'monster';
|
|
|
|
|
case 'mom-car':
|
|
|
|
|
iconRPC = 'mom';
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// String that contains the mode defined here so it isn't necessary to call changePresence for each mode
|
|
|
|
|
detailsText = isStoryMode ? 'Story Mode: Week $storyWeek' : 'Freeplay';
|
|
|
|
|
detailsPausedText = 'Paused - $detailsText';
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Updating Discord Rich Presence.
|
|
|
|
|
DiscordClient.changePresence(detailsText, '${currentChart.songName} ($storyDifficultyText)', iconRPC);
|
|
|
|
|
#end
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function initPreciseInputs():Void
|
|
|
|
|
{
|
|
|
|
|
FlxG.keys.preventDefaultKeys = [];
|
|
|
|
|
PreciseInputManager.instance.onInputPressed.add(onKeyPress);
|
|
|
|
|
PreciseInputManager.instance.onInputReleased.add(onKeyRelease);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Initializes the song (applying the chart, generating the notes, etc.)
|
|
|
|
|
* Should be done before the countdown starts.
|
|
|
|
|
*/
|
|
|
|
|
function generateSong():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentChart == null)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('Song difficulty could not be loaded.');
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-04 16:15:07 -04:00
|
|
|
|
// Conductor.forceBPM(currentChart.getStartingBPM());
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (!overrideMusic)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-09-25 23:24:07 -04:00
|
|
|
|
vocals = currentChart.buildVocals();
|
2023-08-04 16:15:07 -04:00
|
|
|
|
|
|
|
|
|
if (vocals.members.length == 0)
|
|
|
|
|
{
|
|
|
|
|
trace('WARNING: No vocals found for this song.');
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
regenNoteData();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
generatedMusic = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Read note data from the chart and generate the notes.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-07-26 20:03:31 -04:00
|
|
|
|
function regenNoteData(startTime:Float = 0):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
Highscore.tallies.combo = 0;
|
|
|
|
|
Highscore.tallies = new Tallies();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Reset song events.
|
|
|
|
|
songEvents = currentChart.getEvents();
|
|
|
|
|
SongEventParser.resetEvents(songEvents);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Reset the notes on each strumline.
|
|
|
|
|
var playerNoteData:Array<SongNoteData> = [];
|
|
|
|
|
var opponentNoteData:Array<SongNoteData> = [];
|
|
|
|
|
|
|
|
|
|
for (songNote in currentChart.notes)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var strumTime:Float = songNote.time;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
if (strumTime < startTime) continue; // Skip notes that are before the start time.
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var noteData:Int = songNote.getDirection();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var playerNote:Bool = true;
|
|
|
|
|
|
|
|
|
|
if (noteData > 3) playerNote = false;
|
|
|
|
|
|
|
|
|
|
switch (songNote.getStrumlineIndex())
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 0:
|
|
|
|
|
playerNoteData.push(songNote);
|
|
|
|
|
case 1:
|
|
|
|
|
opponentNoteData.push(songNote);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
playerStrumline.applyNoteData(playerNoteData);
|
|
|
|
|
opponentStrumline.applyNoteData(opponentNoteData);
|
2023-02-21 20:58:15 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Prepares to start the countdown.
|
|
|
|
|
* Ends any running cutscenes, creates the strumlines, and starts the countdown.
|
|
|
|
|
* This is public so that scripts can call it.
|
|
|
|
|
*/
|
|
|
|
|
public function startCountdown():Void
|
2023-07-02 16:46:40 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// If Countdown.performCountdown returns false, then the countdown was canceled by a script.
|
|
|
|
|
var result:Bool = Countdown.performCountdown(currentStageId.startsWith('school'));
|
|
|
|
|
if (!result) return;
|
2023-07-02 16:46:40 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
isInCutscene = false;
|
|
|
|
|
camCutscene.visible = false;
|
|
|
|
|
camHUD.visible = true;
|
2023-07-02 16:46:40 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Displays a dialogue cutscene with the given ID.
|
|
|
|
|
* This is used by song scripts to display dialogue.
|
|
|
|
|
*/
|
|
|
|
|
public function startConversation(conversationId:String):Void
|
2023-02-21 20:58:15 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
isInCutscene = true;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentConversation = ConversationDataParser.fetchConversation(conversationId);
|
|
|
|
|
if (currentConversation == null) return;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentConversation.completeCallback = onConversationComplete;
|
|
|
|
|
currentConversation.cameras = [camCutscene];
|
|
|
|
|
currentConversation.zIndex = 1000;
|
|
|
|
|
add(currentConversation);
|
|
|
|
|
refresh();
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var event:ScriptEvent = new ScriptEvent(ScriptEvent.CREATE, false);
|
|
|
|
|
ScriptEventDispatcher.callEvent(currentConversation, event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Handler function called when a conversation ends.
|
|
|
|
|
*/
|
|
|
|
|
function onConversationComplete():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-10-17 21:26:32 -04:00
|
|
|
|
isInCutscene = false;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
remove(currentConversation);
|
|
|
|
|
currentConversation = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (startingSong && !isInCountdown)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
startCountdown();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Starts playing the song after the countdown has completed.
|
|
|
|
|
*/
|
|
|
|
|
function startSong():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
dispatchEvent(new ScriptEvent(ScriptEvent.SONG_START));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
startingSong = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (!overrideMusic && !isGamePaused && currentChart != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentChart.playInst(1.0, false);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.onComplete = endSong;
|
2023-08-04 17:25:13 -04:00
|
|
|
|
FlxG.sound.music.play();
|
|
|
|
|
FlxG.sound.music.time = startTimestamp;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('Playing vocals...');
|
|
|
|
|
add(vocals);
|
|
|
|
|
vocals.play();
|
2023-07-26 20:03:31 -04:00
|
|
|
|
resyncVocals();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if discord_rpc
|
|
|
|
|
// Updating Discord Rich Presence (with Time Left)
|
|
|
|
|
DiscordClient.changePresence(detailsText, '${currentChart.songName} ($storyDifficultyText)', iconRPC, true, currentSongLengthMs);
|
|
|
|
|
#end
|
2023-07-26 20:03:31 -04:00
|
|
|
|
|
|
|
|
|
if (startTimestamp > 0)
|
|
|
|
|
{
|
|
|
|
|
FlxG.sound.music.time = startTimestamp;
|
|
|
|
|
handleSkippedNotes();
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Resyncronize the vocal tracks if they have become offset from the instrumental.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function resyncVocals():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (_exiting || vocals == null) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-08-02 18:08:49 -04:00
|
|
|
|
// Skip this if the music is paused (GameOver, Pause menu, etc.)
|
|
|
|
|
if (!FlxG.sound.music.playing) return;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
vocals.pause();
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.play();
|
|
|
|
|
Conductor.update();
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
vocals.time = FlxG.sound.music.time;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
vocals.play(false, FlxG.sound.music.time);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Updates the position and contents of the score display.
|
|
|
|
|
*/
|
|
|
|
|
function updateScoreText():Void
|
|
|
|
|
{
|
|
|
|
|
// TODO: Add functionality for modules to update the score text.
|
|
|
|
|
scoreText.text = 'Score:' + songScore;
|
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Updates the values of the health bar.
|
|
|
|
|
*/
|
|
|
|
|
function updateHealthBar():Void
|
|
|
|
|
{
|
|
|
|
|
healthLerp = FlxMath.lerp(healthLerp, health, 0.15);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Callback executed when one of the note keys is pressed.
|
|
|
|
|
*/
|
|
|
|
|
function onKeyPress(event:PreciseInputEvent):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-08-02 18:08:49 -04:00
|
|
|
|
if (isGamePaused) return;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Do the minimal possible work here.
|
|
|
|
|
inputPressQueue.push(event);
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Callback executed when one of the note keys is released.
|
|
|
|
|
*/
|
|
|
|
|
function onKeyRelease(event:PreciseInputEvent):Void
|
|
|
|
|
{
|
2023-08-02 18:08:49 -04:00
|
|
|
|
if (isGamePaused) return;
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Do the minimal possible work here.
|
|
|
|
|
inputReleaseQueue.push(event);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Handles opponent note hits and player note misses.
|
2023-06-02 15:35:01 -04:00
|
|
|
|
*/
|
2023-06-27 17:22:51 -04:00
|
|
|
|
function processNotes(elapsed:Float):Void
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-07-13 20:27:45 -04:00
|
|
|
|
if (playerStrumline?.notes?.members == null || opponentStrumline?.notes?.members == null) return;
|
2023-02-22 14:46:46 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Process notes on the opponent's side.
|
|
|
|
|
for (note in opponentStrumline.notes.members)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (note == null) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-22 20:16:43 -04:00
|
|
|
|
var hitWindowStart = note.strumTime - Constants.HIT_WINDOW_MS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var hitWindowCenter = note.strumTime;
|
2023-07-22 20:16:43 -04:00
|
|
|
|
var hitWindowEnd = note.strumTime + Constants.HIT_WINDOW_MS;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (Conductor.songPosition > hitWindowEnd)
|
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
if (note.hasMissed) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
note.tooEarly = false;
|
|
|
|
|
note.mayHit = false;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.hasMissed = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = true;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
|
|
|
|
else if (Conductor.songPosition > hitWindowCenter)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
if (note.hasBeenHit) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Call an event to allow canceling the note hit.
|
|
|
|
|
// NOTE: This is what handles the character animations!
|
|
|
|
|
var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_HIT, note, 0, true);
|
|
|
|
|
dispatchEvent(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
|
|
|
|
if (event.eventCanceled) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Command the opponent to hit the note on time.
|
|
|
|
|
// NOTE: This is what handles the strumline and cleaning up the note itself!
|
|
|
|
|
opponentStrumline.hitNote(note);
|
2023-07-05 22:11:58 -04:00
|
|
|
|
|
|
|
|
|
if (note.holdNoteSprite != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-05 22:11:58 -04:00
|
|
|
|
opponentStrumline.playNoteHoldCover(note.holdNoteSprite);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else if (Conductor.songPosition > hitWindowStart)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
if (note.hasBeenHit || note.hasMissed) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
note.tooEarly = false;
|
|
|
|
|
note.mayHit = true;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.hasMissed = false;
|
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = false;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
note.tooEarly = true;
|
|
|
|
|
note.mayHit = false;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.hasMissed = false;
|
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = false;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// Process hold notes on the opponent's side.
|
|
|
|
|
for (holdNote in opponentStrumline.holdNotes.members)
|
|
|
|
|
{
|
|
|
|
|
if (holdNote == null || !holdNote.alive) continue;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// While the hold note is being hit, and there is length on the hold note...
|
|
|
|
|
if (holdNote.hitNote && !holdNote.missedNote && holdNote.sustainLength > 0)
|
|
|
|
|
{
|
|
|
|
|
// Make sure the opponent keeps singing while the note is held.
|
|
|
|
|
if (currentStage != null && currentStage.getDad() != null && currentStage.getDad().isSinging())
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
currentStage.getDad().holdTimer = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// TODO: Potential penalty for dropping a hold note?
|
|
|
|
|
// if (holdNote.missedNote && !holdNote.handledMiss) { holdNote.handledMiss = true; }
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-07-08 01:03:46 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Process notes on the player's side.
|
|
|
|
|
for (note in playerStrumline.notes.members)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (note == null || note.hasBeenHit) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-22 20:16:43 -04:00
|
|
|
|
var hitWindowStart = note.strumTime - Constants.HIT_WINDOW_MS;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
var hitWindowCenter = note.strumTime;
|
2023-07-22 20:16:43 -04:00
|
|
|
|
var hitWindowEnd = note.strumTime + Constants.HIT_WINDOW_MS;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (Conductor.songPosition > hitWindowEnd)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.tooEarly = false;
|
|
|
|
|
note.mayHit = false;
|
|
|
|
|
note.hasMissed = true;
|
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = true;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-06-27 13:43:42 -04:00
|
|
|
|
else if (Conductor.songPosition > hitWindowStart)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.tooEarly = false;
|
|
|
|
|
note.mayHit = true;
|
|
|
|
|
note.hasMissed = false;
|
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = false;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
note.tooEarly = true;
|
|
|
|
|
note.mayHit = false;
|
|
|
|
|
note.hasMissed = false;
|
|
|
|
|
if (note.holdNoteSprite != null) note.holdNoteSprite.missedNote = false;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
// This becomes true when the note leaves the hit window.
|
|
|
|
|
// It might still be on screen.
|
|
|
|
|
if (note.hasMissed && !note.handledMiss)
|
2023-06-22 01:41:01 -04:00
|
|
|
|
{
|
|
|
|
|
// Call an event to allow canceling the note miss.
|
|
|
|
|
// NOTE: This is what handles the character animations!
|
|
|
|
|
var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_MISS, note, 0, true);
|
|
|
|
|
dispatchEvent(event);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
|
|
|
|
if (event.eventCanceled) continue;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Judge the miss.
|
|
|
|
|
// NOTE: This is what handles the scoring.
|
2023-07-26 21:34:38 -04:00
|
|
|
|
trace('Missed note! ${note.noteData}');
|
2023-06-22 01:41:01 -04:00
|
|
|
|
onNoteMiss(note);
|
2023-06-27 13:43:42 -04:00
|
|
|
|
|
|
|
|
|
note.handledMiss = true;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-26 20:40:26 -04:00
|
|
|
|
|
|
|
|
|
// Process hold notes on the player's side.
|
|
|
|
|
// This handles scoring so we don't need it on the opponent's side.
|
2023-06-27 17:22:51 -04:00
|
|
|
|
for (holdNote in playerStrumline.holdNotes.members)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-27 18:06:33 -04:00
|
|
|
|
if (holdNote == null || !holdNote.alive) continue;
|
|
|
|
|
|
2023-06-27 17:22:51 -04:00
|
|
|
|
// While the hold note is being hit, and there is length on the hold note...
|
2023-06-27 18:06:33 -04:00
|
|
|
|
if (holdNote.hitNote && !holdNote.missedNote && holdNote.sustainLength > 0)
|
2023-06-27 17:22:51 -04:00
|
|
|
|
{
|
|
|
|
|
// Grant the player health.
|
|
|
|
|
health += Constants.HEALTH_HOLD_BONUS_PER_SECOND * elapsed;
|
2023-10-06 11:42:39 -04:00
|
|
|
|
songScore += Std.int(Constants.SCORE_HOLD_BONUS_PER_SECOND * elapsed);
|
2023-06-27 17:22:51 -04:00
|
|
|
|
}
|
2023-07-08 01:03:46 -04:00
|
|
|
|
|
|
|
|
|
// TODO: Potential penalty for dropping a hold note?
|
|
|
|
|
// if (holdNote.missedNote && !holdNote.handledMiss) { holdNote.handledMiss = true; }
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Spitting out the input for ravy 🙇♂️!!
|
|
|
|
|
*/
|
|
|
|
|
var inputSpitter:Array<ScoreInput> = [];
|
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
function handleSkippedNotes():Void
|
|
|
|
|
{
|
|
|
|
|
for (note in playerStrumline.notes.members)
|
|
|
|
|
{
|
2023-07-26 21:34:38 -04:00
|
|
|
|
if (note == null || note.hasBeenHit) continue;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
var hitWindowEnd = note.strumTime + Constants.HIT_WINDOW_MS;
|
|
|
|
|
|
|
|
|
|
if (Conductor.songPosition > hitWindowEnd)
|
|
|
|
|
{
|
|
|
|
|
// We have passed this note.
|
|
|
|
|
// Flag the note for deletion without actually penalizing the player.
|
|
|
|
|
note.handledMiss = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-07-26 21:34:38 -04:00
|
|
|
|
|
|
|
|
|
playerStrumline.handleSkippedNotes();
|
|
|
|
|
opponentStrumline.handleSkippedNotes();
|
2023-07-26 20:03:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* PreciseInputEvents are put into a queue between update() calls,
|
|
|
|
|
* and then processed here.
|
|
|
|
|
*/
|
|
|
|
|
function processInputQueue():Void
|
|
|
|
|
{
|
|
|
|
|
if (inputPressQueue.length + inputReleaseQueue.length == 0) return;
|
|
|
|
|
|
|
|
|
|
// Ignore inputs during cutscenes.
|
|
|
|
|
if (isInCutscene || disableKeys)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
inputPressQueue = [];
|
|
|
|
|
inputReleaseQueue = [];
|
|
|
|
|
return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// Generate a list of notes within range.
|
2023-06-27 13:43:42 -04:00
|
|
|
|
var notesInRange:Array<NoteSprite> = playerStrumline.getNotesMayHit();
|
2023-06-27 18:06:33 -04:00
|
|
|
|
var holdNotesInRange:Array<SustainTrail> = playerStrumline.getHoldNotesHitOrMissed();
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// If there are notes in range, pressing a key will cause a ghost miss.
|
|
|
|
|
|
|
|
|
|
var notesByDirection:Array<Array<NoteSprite>> = [[], [], [], []];
|
|
|
|
|
|
|
|
|
|
for (note in notesInRange)
|
|
|
|
|
notesByDirection[note.direction].push(note);
|
|
|
|
|
|
|
|
|
|
while (inputPressQueue.length > 0)
|
2023-03-02 04:20:03 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var input:PreciseInputEvent = inputPressQueue.shift();
|
2023-03-02 04:20:03 -05:00
|
|
|
|
|
2023-06-26 20:40:26 -04:00
|
|
|
|
playerStrumline.pressKey(input.noteDirection);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var notesInDirection:Array<NoteSprite> = notesByDirection[input.noteDirection];
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (!Constants.GHOST_TAPPING && notesInDirection.length == 0)
|
2023-03-18 15:47:23 -04:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
// Pressed a wrong key with no notes nearby.
|
|
|
|
|
// Perform a ghost miss (anti-spam).
|
|
|
|
|
ghostNoteMiss(input.noteDirection, notesInRange.length > 0);
|
|
|
|
|
|
|
|
|
|
// Play the strumline animation.
|
|
|
|
|
playerStrumline.playPress(input.noteDirection);
|
2023-03-18 15:47:23 -04:00
|
|
|
|
}
|
2023-06-27 18:06:33 -04:00
|
|
|
|
else if (Constants.GHOST_TAPPING && (holdNotesInRange.length + notesInRange.length > 0) && notesInDirection.length == 0)
|
2023-03-18 15:47:23 -04:00
|
|
|
|
{
|
2023-06-27 13:43:42 -04:00
|
|
|
|
// Pressed a wrong key with no notes nearby AND with notes in a different direction available.
|
|
|
|
|
// Perform a ghost miss (anti-spam).
|
2023-06-22 01:41:01 -04:00
|
|
|
|
ghostNoteMiss(input.noteDirection, notesInRange.length > 0);
|
|
|
|
|
|
|
|
|
|
// Play the strumline animation.
|
|
|
|
|
playerStrumline.playPress(input.noteDirection);
|
2023-03-18 15:47:23 -04:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else if (notesInDirection.length > 0)
|
2023-03-18 15:47:23 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Choose the first note, deprioritizing low priority notes.
|
|
|
|
|
var targetNote:Null<NoteSprite> = notesInDirection.find((note) -> !note.lowPriority);
|
|
|
|
|
if (targetNote == null) targetNote = notesInDirection[0];
|
|
|
|
|
if (targetNote == null) continue;
|
|
|
|
|
|
|
|
|
|
// Judge and hit the note.
|
2023-07-26 21:34:38 -04:00
|
|
|
|
trace('Hit note! ${targetNote.noteData}');
|
2023-06-22 01:41:01 -04:00
|
|
|
|
goodNoteHit(targetNote, input);
|
|
|
|
|
|
|
|
|
|
targetNote.visible = false;
|
|
|
|
|
targetNote.kill();
|
2023-07-08 01:03:46 -04:00
|
|
|
|
notesInDirection.remove(targetNote);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// Play the strumline animation.
|
|
|
|
|
playerStrumline.playConfirm(input.noteDirection);
|
2023-03-18 15:47:23 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Play the strumline animation.
|
|
|
|
|
playerStrumline.playPress(input.noteDirection);
|
2023-03-18 15:47:23 -04:00
|
|
|
|
}
|
2023-03-02 04:20:03 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
while (inputReleaseQueue.length > 0)
|
|
|
|
|
{
|
|
|
|
|
var input:PreciseInputEvent = inputReleaseQueue.shift();
|
|
|
|
|
|
|
|
|
|
// Play the strumline animation.
|
|
|
|
|
playerStrumline.playStatic(input.noteDirection);
|
2023-06-26 20:40:26 -04:00
|
|
|
|
|
|
|
|
|
playerStrumline.releaseKey(input.noteDirection);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function goodNoteHit(note:NoteSprite, input:PreciseInputEvent):Void
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_HIT, note, Highscore.tallies.combo + 1, true);
|
|
|
|
|
dispatchEvent(event);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
|
|
|
|
if (event.eventCanceled) return;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-10-06 11:42:39 -04:00
|
|
|
|
Highscore.tallies.combo++;
|
|
|
|
|
Highscore.tallies.totalNotesHit++;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-10-06 11:42:39 -04:00
|
|
|
|
if (Highscore.tallies.combo > Highscore.tallies.maxCombo) Highscore.tallies.maxCombo = Highscore.tallies.combo;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
2023-10-06 11:42:39 -04:00
|
|
|
|
popUpScore(note, input);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
playerStrumline.hitNote(note);
|
2023-07-05 22:11:58 -04:00
|
|
|
|
|
2023-10-06 11:42:39 -04:00
|
|
|
|
if (note.isHoldNote && note.holdNoteSprite != null)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-07-08 01:03:46 -04:00
|
|
|
|
playerStrumline.playNoteHoldCover(note.holdNoteSprite);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-08 01:03:46 -04:00
|
|
|
|
vocals.playerVolume = 1;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Called when a note leaves the screen and is considered missed by the player.
|
|
|
|
|
* @param note
|
2023-06-02 15:35:01 -04:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function onNoteMiss(note:NoteSprite):Void
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// a MISS is when you let a note scroll past you!!
|
|
|
|
|
Highscore.tallies.missed++;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var event:NoteScriptEvent = new NoteScriptEvent(ScriptEvent.NOTE_MISS, note, Highscore.tallies.combo, true);
|
|
|
|
|
dispatchEvent(event);
|
|
|
|
|
// Calling event.cancelEvent() skips all the other logic! Neat!
|
|
|
|
|
if (event.eventCanceled) return;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health -= Constants.HEALTH_MISS_PENALTY;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
songScore -= 10;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (!isPracticeMode)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// messy copy paste rn lol
|
|
|
|
|
var pressArray:Array<Bool> = [
|
|
|
|
|
controls.NOTE_LEFT_P,
|
|
|
|
|
controls.NOTE_DOWN_P,
|
|
|
|
|
controls.NOTE_UP_P,
|
|
|
|
|
controls.NOTE_RIGHT_P
|
|
|
|
|
];
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var indices:Array<Int> = [];
|
|
|
|
|
for (i in 0...pressArray.length)
|
|
|
|
|
{
|
|
|
|
|
if (pressArray[i]) indices.push(i);
|
|
|
|
|
}
|
|
|
|
|
if (indices.length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (i in 0...indices.length)
|
|
|
|
|
{
|
|
|
|
|
inputSpitter.push(
|
|
|
|
|
{
|
|
|
|
|
t: Std.int(Conductor.songPosition),
|
|
|
|
|
d: indices[i],
|
|
|
|
|
l: 20
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputSpitter.push(
|
|
|
|
|
{
|
|
|
|
|
t: Std.int(Conductor.songPosition),
|
|
|
|
|
d: -1,
|
|
|
|
|
l: 20
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vocals.playerVolume = 0;
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (Highscore.tallies.combo != 0)
|
2023-06-02 15:35:01 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
Highscore.tallies.combo = comboPopUps.displayCombo(0);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (event.playSound)
|
|
|
|
|
{
|
|
|
|
|
vocals.playerVolume = 0;
|
|
|
|
|
FlxG.sound.play(Paths.soundRandom('missnote', 1, 3), FlxG.random.float(0.1, 0.2));
|
|
|
|
|
}
|
2023-06-02 15:35:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
|
|
|
|
* Called when a player presses a key with no note present.
|
|
|
|
|
* Scripts can modify the amount of health/score lost, whether player animations or sounds are used,
|
|
|
|
|
* or even cancel the event entirely.
|
2023-06-08 16:30:45 -04:00
|
|
|
|
*
|
|
|
|
|
* @param direction
|
|
|
|
|
* @param hasPossibleNotes
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function ghostNoteMiss(direction:NoteDirection, hasPossibleNotes:Bool = true):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
|
|
|
|
var event:GhostMissNoteScriptEvent = new GhostMissNoteScriptEvent(direction, // Direction missed in.
|
|
|
|
|
hasPossibleNotes, // Whether there was a note you could have hit.
|
2023-06-27 13:43:42 -04:00
|
|
|
|
- 1 * Constants.HEALTH_MISS_PENALTY, // How much health to add (negative).
|
2023-01-22 19:55:30 -05:00
|
|
|
|
- 10 // Amount of score to add (negative).
|
|
|
|
|
);
|
|
|
|
|
dispatchEvent(event);
|
|
|
|
|
|
|
|
|
|
// Calling event.cancelEvent() skips animations and penalties. Neat!
|
2023-01-22 22:25:45 -05:00
|
|
|
|
if (event.eventCanceled) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
health += event.healthChange;
|
2023-07-26 20:03:31 -04:00
|
|
|
|
songScore += event.scoreChange;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-03-02 04:20:03 -05:00
|
|
|
|
if (!isPracticeMode)
|
|
|
|
|
{
|
|
|
|
|
var pressArray:Array<Bool> = [
|
|
|
|
|
controls.NOTE_LEFT_P,
|
|
|
|
|
controls.NOTE_DOWN_P,
|
|
|
|
|
controls.NOTE_UP_P,
|
|
|
|
|
controls.NOTE_RIGHT_P
|
|
|
|
|
];
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-03-18 15:47:23 -04:00
|
|
|
|
var indices:Array<Int> = [];
|
|
|
|
|
for (i in 0...pressArray.length)
|
|
|
|
|
{
|
|
|
|
|
if (pressArray[i]) indices.push(i);
|
|
|
|
|
}
|
|
|
|
|
for (i in 0...indices.length)
|
|
|
|
|
{
|
|
|
|
|
inputSpitter.push(
|
|
|
|
|
{
|
|
|
|
|
t: Std.int(Conductor.songPosition),
|
|
|
|
|
d: indices[i],
|
|
|
|
|
l: 20
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-02 04:20:03 -05:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
|
|
|
|
if (event.playSound)
|
|
|
|
|
{
|
2023-05-25 18:34:26 -04:00
|
|
|
|
vocals.playerVolume = 0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
FlxG.sound.play(Paths.soundRandom('missnote', 1, 3), FlxG.random.float(0.1, 0.2));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Debug keys. Disabled while in cutscenes.
|
|
|
|
|
*/
|
|
|
|
|
function debugKeyShit():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if !debug
|
|
|
|
|
perfectMode = false;
|
|
|
|
|
#else
|
|
|
|
|
if (FlxG.keys.justPressed.H) camHUD.visible = !camHUD.visible;
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
// Eject button
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (FlxG.keys.justPressed.F4) FlxG.switchState(new MainMenuState());
|
|
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.F5) debug_refreshModules();
|
|
|
|
|
|
|
|
|
|
// Press U to open stage ditor.
|
|
|
|
|
if (FlxG.keys.justPressed.U)
|
|
|
|
|
{
|
|
|
|
|
// hack for HaxeUI generation, doesn't work unless persistentUpdate is false at state creation!!
|
|
|
|
|
disableKeys = true;
|
|
|
|
|
persistentUpdate = false;
|
|
|
|
|
openSubState(new StageOffsetSubState());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if debug
|
|
|
|
|
// 1: End the song immediately.
|
|
|
|
|
if (FlxG.keys.justPressed.ONE) endSong();
|
|
|
|
|
|
|
|
|
|
// 2: Gain 10% health.
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (FlxG.keys.justPressed.TWO) health += 0.1 * Constants.HEALTH_MAX;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// 3: Lose 5% health.
|
2023-06-27 13:43:42 -04:00
|
|
|
|
if (FlxG.keys.justPressed.THREE) health -= 0.05 * Constants.HEALTH_MAX;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
// 7: Move to the charter.
|
|
|
|
|
if (FlxG.keys.justPressed.SEVEN)
|
|
|
|
|
{
|
|
|
|
|
lime.app.Application.current.window.alert("Press ~ on the main menu to get to the editor", 'LOL');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8: Move to the offset editor.
|
2023-07-26 16:52:58 -04:00
|
|
|
|
if (FlxG.keys.justPressed.EIGHT)
|
|
|
|
|
{
|
|
|
|
|
lime.app.Application.current.window.alert("Press ~ on the main menu to get to the editor", 'LOL');
|
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
|
|
|
|
|
// 9: Toggle the old icon.
|
|
|
|
|
if (FlxG.keys.justPressed.NINE) iconP1.toggleOldIcon();
|
|
|
|
|
|
|
|
|
|
#if debug
|
2023-07-26 21:34:38 -04:00
|
|
|
|
// PAGEUP: Skip forward two sections.
|
|
|
|
|
// SHIFT+PAGEUP: Skip forward twenty sections.
|
|
|
|
|
if (FlxG.keys.justPressed.PAGEUP) changeSection(FlxG.keys.pressed.SHIFT ? 20 : 2);
|
|
|
|
|
// PAGEDOWN: Skip backward two section. Doesn't replace notes.
|
|
|
|
|
// SHIFT+PAGEDOWN: Skip backward twenty sections.
|
|
|
|
|
if (FlxG.keys.justPressed.PAGEDOWN) changeSection(FlxG.keys.pressed.SHIFT ? -20 : -2);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#end
|
|
|
|
|
|
|
|
|
|
if (FlxG.keys.justPressed.B) trace(inputSpitter.join('\n'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handles health, score, and rating popups when a note is hit.
|
|
|
|
|
*/
|
|
|
|
|
function popUpScore(daNote:NoteSprite, input:PreciseInputEvent):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
vocals.playerVolume = 1;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Calculate the input latency (do this as late as possible).
|
2023-08-04 11:13:41 -04:00
|
|
|
|
var inputLatencyMs:Float = haxe.Int64.toInt(PreciseInputManager.getCurrentTimestamp() - input.timestamp) / 1000.0 / 1000.0;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('Input: ${daNote.noteData.getDirectionName()} pressed ${inputLatencyMs}ms ago!');
|
|
|
|
|
|
|
|
|
|
// Get the offset and compensate for input latency.
|
|
|
|
|
// Round inward (trim remainder) for consistency.
|
|
|
|
|
var noteDiff:Int = Std.int(Conductor.songPosition - daNote.noteData.time - inputLatencyMs);
|
|
|
|
|
|
|
|
|
|
var score = Scoring.scoreNote(noteDiff, PBOT1);
|
|
|
|
|
var daRating = Scoring.judgeNote(noteDiff, PBOT1);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
switch (daRating)
|
|
|
|
|
{
|
|
|
|
|
case 'killer':
|
|
|
|
|
Highscore.tallies.killer += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += Constants.HEALTH_KILLER_BONUS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'sick':
|
|
|
|
|
Highscore.tallies.sick += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += Constants.HEALTH_SICK_BONUS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'good':
|
|
|
|
|
Highscore.tallies.good += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += Constants.HEALTH_GOOD_BONUS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'bad':
|
|
|
|
|
Highscore.tallies.bad += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += Constants.HEALTH_BAD_BONUS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'shit':
|
|
|
|
|
Highscore.tallies.shit += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health += Constants.HEALTH_SHIT_BONUS;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
case 'miss':
|
|
|
|
|
Highscore.tallies.missed += 1;
|
2023-06-27 13:43:42 -04:00
|
|
|
|
health -= Constants.HEALTH_MISS_PENALTY;
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (daRating == "sick" || daRating == "killer")
|
|
|
|
|
{
|
|
|
|
|
playerStrumline.playNoteSplash(daNote.noteData.getDirection());
|
|
|
|
|
}
|
2023-03-02 04:20:03 -05:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
songScore += score;
|
|
|
|
|
|
2023-03-02 04:20:03 -05:00
|
|
|
|
if (!isPracticeMode)
|
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Input splitter uses old input system, make it pull from the precise input queue directly.
|
2023-03-02 04:20:03 -05:00
|
|
|
|
var pressArray:Array<Bool> = [
|
|
|
|
|
controls.NOTE_LEFT_P,
|
|
|
|
|
controls.NOTE_DOWN_P,
|
|
|
|
|
controls.NOTE_UP_P,
|
|
|
|
|
controls.NOTE_RIGHT_P
|
|
|
|
|
];
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-03-18 15:47:23 -04:00
|
|
|
|
var indices:Array<Int> = [];
|
|
|
|
|
for (i in 0...pressArray.length)
|
|
|
|
|
{
|
|
|
|
|
if (pressArray[i]) indices.push(i);
|
|
|
|
|
}
|
|
|
|
|
if (indices.length > 0)
|
|
|
|
|
{
|
|
|
|
|
for (i in 0...indices.length)
|
|
|
|
|
{
|
|
|
|
|
inputSpitter.push(
|
|
|
|
|
{
|
|
|
|
|
t: Std.int(Conductor.songPosition),
|
|
|
|
|
d: indices[i],
|
|
|
|
|
l: 20
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
inputSpitter.push(
|
|
|
|
|
{
|
|
|
|
|
t: Std.int(Conductor.songPosition),
|
|
|
|
|
d: -1,
|
|
|
|
|
l: 20
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-03-02 04:20:03 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
comboPopUps.displayRating(daRating);
|
|
|
|
|
if (Highscore.tallies.combo >= 10 || Highscore.tallies.combo == 0) comboPopUps.displayCombo(Highscore.tallies.combo);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Handle keyboard inputs during cutscenes.
|
|
|
|
|
* This includes advancing conversations and skipping videos.
|
|
|
|
|
* @param elapsed Time elapsed since last game update.
|
|
|
|
|
*/
|
|
|
|
|
function handleCutsceneKeys(elapsed:Float):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentConversation != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (controls.CUTSCENE_ADVANCE) currentConversation?.advanceConversation();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (controls.CUTSCENE_SKIP)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
currentConversation?.trySkipConversation(elapsed);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentConversation?.trySkipConversation(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (VideoCutscene.isPlaying())
|
|
|
|
|
{
|
|
|
|
|
// This is a video cutscene.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (controls.CUTSCENE_SKIP)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trySkipVideoCutscene(elapsed);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
trySkipVideoCutscene(-1);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* Handle logic for the skip timer.
|
|
|
|
|
* If the skip button is being held, pass the amount of time elapsed since last game update.
|
|
|
|
|
* If the skip button has been released, pass a negative number.
|
|
|
|
|
*/
|
|
|
|
|
function trySkipVideoCutscene(elapsed:Float):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (skipTimer == null || skipTimer.animation == null) return;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (elapsed < 0)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
skipHeldTimer = 0.0;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
skipHeldTimer += elapsed;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
skipTimer.visible = skipHeldTimer >= 0.05;
|
|
|
|
|
skipTimer.amount = Math.min(skipHeldTimer / 1.5, 1.0);
|
|
|
|
|
|
|
|
|
|
if (skipHeldTimer >= 1.5)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
VideoCutscene.finishVideo();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
/**
|
|
|
|
|
* End the song. Handle saving high scores and transitioning to the results screen.
|
|
|
|
|
*/
|
|
|
|
|
function endSong():Void
|
|
|
|
|
{
|
|
|
|
|
dispatchEvent(new ScriptEvent(ScriptEvent.SONG_END));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if sys
|
|
|
|
|
// spitter for ravy, teehee!!
|
2023-10-21 01:04:50 -04:00
|
|
|
|
var writer = new json2object.JsonWriter<Array<ScoreInput>>();
|
|
|
|
|
var output = writer.write(inputSpitter, ' ');
|
2023-06-22 01:41:01 -04:00
|
|
|
|
sys.io.File.saveContent("./scores.json", output);
|
|
|
|
|
#end
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
deathCounter = 0;
|
|
|
|
|
mayPauseGame = false;
|
|
|
|
|
FlxG.sound.music.volume = 0;
|
|
|
|
|
vocals.volume = 0;
|
|
|
|
|
if (currentSong != null && currentSong.validScore)
|
|
|
|
|
{
|
|
|
|
|
// crackhead double thingie, sets whether was new highscore, AND saves the song!
|
2023-10-17 00:38:28 -04:00
|
|
|
|
var data =
|
|
|
|
|
{
|
|
|
|
|
score: songScore,
|
|
|
|
|
tallies:
|
|
|
|
|
{
|
|
|
|
|
killer: Highscore.tallies.killer,
|
|
|
|
|
sick: Highscore.tallies.sick,
|
|
|
|
|
good: Highscore.tallies.good,
|
|
|
|
|
bad: Highscore.tallies.bad,
|
|
|
|
|
shit: Highscore.tallies.shit,
|
|
|
|
|
missed: Highscore.tallies.missed,
|
|
|
|
|
combo: Highscore.tallies.combo,
|
|
|
|
|
maxCombo: Highscore.tallies.maxCombo,
|
|
|
|
|
totalNotesHit: Highscore.tallies.totalNotesHit,
|
|
|
|
|
totalNotes: Highscore.tallies.totalNotes,
|
|
|
|
|
},
|
|
|
|
|
accuracy: Highscore.tallies.totalNotesHit / Highscore.tallies.totalNotes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (Save.get().isSongHighScore(currentSong.id, currentDifficulty, data))
|
|
|
|
|
{
|
|
|
|
|
Save.get().setSongScore(currentSong.id, currentDifficulty, data);
|
|
|
|
|
#if newgrounds
|
|
|
|
|
NGio.postScore(score, currentSong.id);
|
|
|
|
|
#end
|
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (PlayStatePlaylist.isStoryMode)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
PlayStatePlaylist.campaignScore += songScore;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Pop the next song ID from the list.
|
|
|
|
|
// Returns null if the list is empty.
|
|
|
|
|
var targetSongId:String = PlayStatePlaylist.playlistSongIds.shift();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (targetSongId == null)
|
|
|
|
|
{
|
2023-07-22 20:16:43 -04:00
|
|
|
|
FlxG.sound.playMusic(Paths.music('freakyMenu/freakyMenu'));
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
transIn = FlxTransitionableState.defaultTransIn;
|
|
|
|
|
transOut = FlxTransitionableState.defaultTransOut;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Rework week unlock logic.
|
|
|
|
|
// StoryMenuState.weekUnlocked[Std.int(Math.min(storyWeek + 1, StoryMenuState.weekUnlocked.length - 1))] = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentSong.validScore)
|
|
|
|
|
{
|
|
|
|
|
NGio.unlockMedal(60961);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-10-03 19:14:46 -04:00
|
|
|
|
var data =
|
2023-10-17 00:38:28 -04:00
|
|
|
|
{
|
|
|
|
|
score: PlayStatePlaylist.campaignScore,
|
|
|
|
|
tallies:
|
|
|
|
|
{
|
|
|
|
|
// TODO: Sum up the values for the whole level!
|
|
|
|
|
killer: 0,
|
|
|
|
|
sick: 0,
|
|
|
|
|
good: 0,
|
|
|
|
|
bad: 0,
|
|
|
|
|
shit: 0,
|
|
|
|
|
missed: 0,
|
|
|
|
|
combo: 0,
|
|
|
|
|
maxCombo: 0,
|
|
|
|
|
totalNotesHit: 0,
|
|
|
|
|
totalNotes: 0,
|
|
|
|
|
},
|
|
|
|
|
accuracy: Highscore.tallies.totalNotesHit / Highscore.tallies.totalNotes,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (Save.get().isLevelHighScore(PlayStatePlaylist.campaignId, PlayStatePlaylist.campaignDifficulty, data))
|
|
|
|
|
{
|
|
|
|
|
Save.get().setLevelScore(PlayStatePlaylist.campaignId, PlayStatePlaylist.campaignDifficulty, data);
|
|
|
|
|
#if newgrounds
|
|
|
|
|
NGio.postScore(score, 'Level ${PlayStatePlaylist.campaignId}');
|
|
|
|
|
#end
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
if (isSubState)
|
|
|
|
|
{
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
moveToResultsScreen();
|
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var difficulty:String = '';
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('Loading next song ($targetSongId : $difficulty)');
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxTransitionableState.skipNextTransIn = true;
|
|
|
|
|
FlxTransitionableState.skipNextTransOut = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.stop();
|
|
|
|
|
vocals.stop();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Softcode this cutscene.
|
2023-09-08 17:46:44 -04:00
|
|
|
|
if (currentSong.id == 'eggnog')
|
2023-06-22 01:41:01 -04:00
|
|
|
|
{
|
|
|
|
|
var blackShit:FlxSprite = new FlxSprite(-FlxG.width * FlxG.camera.zoom,
|
|
|
|
|
-FlxG.height * FlxG.camera.zoom).makeGraphic(FlxG.width * 3, FlxG.height * 3, FlxColor.BLACK);
|
|
|
|
|
blackShit.scrollFactor.set();
|
|
|
|
|
add(blackShit);
|
|
|
|
|
camHUD.visible = false;
|
|
|
|
|
isInCutscene = true;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.play(Paths.sound('Lights_Shut_off'), function() {
|
|
|
|
|
// no camFollow so it centers on horror tree
|
2023-09-08 17:46:44 -04:00
|
|
|
|
var targetSong:Song = SongRegistry.instance.fetchEntry(targetSongId);
|
2023-08-22 23:18:37 -04:00
|
|
|
|
// Load and cache the song's charts.
|
|
|
|
|
// TODO: Do this in the loading state.
|
|
|
|
|
targetSong.cacheCharts(true);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var nextPlayState:PlayState = new PlayState(
|
|
|
|
|
{
|
|
|
|
|
targetSong: targetSong,
|
2023-10-11 17:33:55 -04:00
|
|
|
|
targetDifficulty: PlayStatePlaylist.campaignDifficulty,
|
2023-06-22 01:41:01 -04:00
|
|
|
|
targetCharacter: currentPlayerId,
|
|
|
|
|
});
|
|
|
|
|
nextPlayState.previousCameraFollowPoint = new FlxSprite(cameraFollowPoint.x, cameraFollowPoint.y);
|
|
|
|
|
LoadingState.loadAndSwitchState(nextPlayState);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-09-08 17:46:44 -04:00
|
|
|
|
var targetSong:Song = SongRegistry.instance.fetchEntry(targetSongId);
|
2023-08-22 23:18:37 -04:00
|
|
|
|
// Load and cache the song's charts.
|
|
|
|
|
// TODO: Do this in the loading state.
|
|
|
|
|
targetSong.cacheCharts(true);
|
2023-06-22 01:41:01 -04:00
|
|
|
|
var nextPlayState:PlayState = new PlayState(
|
|
|
|
|
{
|
|
|
|
|
targetSong: targetSong,
|
2023-10-11 17:33:55 -04:00
|
|
|
|
targetDifficulty: PlayStatePlaylist.campaignDifficulty,
|
2023-06-22 01:41:01 -04:00
|
|
|
|
targetCharacter: currentPlayerId,
|
|
|
|
|
});
|
|
|
|
|
nextPlayState.previousCameraFollowPoint = new FlxSprite(cameraFollowPoint.x, cameraFollowPoint.y);
|
|
|
|
|
LoadingState.loadAndSwitchState(nextPlayState);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-07-26 16:52:58 -04:00
|
|
|
|
if (isSubState)
|
|
|
|
|
{
|
|
|
|
|
this.close();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
moveToResultsScreen();
|
|
|
|
|
}
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-26 16:52:58 -04:00
|
|
|
|
public override function close():Void
|
|
|
|
|
{
|
2023-07-26 21:34:38 -04:00
|
|
|
|
criticalFailure = true; // Stop game updates.
|
2023-07-26 16:52:58 -04:00
|
|
|
|
performCleanup();
|
|
|
|
|
super.close();
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Perform necessary cleanup before leaving the PlayState.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function performCleanup():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (currentChart != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// TODO: Uncache the song.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-04 16:15:07 -04:00
|
|
|
|
if (!overrideMusic)
|
|
|
|
|
{
|
|
|
|
|
// Stop the music.
|
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
|
vocals.stop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlxG.sound.music.pause();
|
2023-08-04 17:25:13 -04:00
|
|
|
|
vocals.pause();
|
2023-08-04 16:15:07 -04:00
|
|
|
|
remove(vocals);
|
|
|
|
|
}
|
2023-07-26 21:34:38 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Remove reference to stage and remove sprites from it to save memory.
|
|
|
|
|
if (currentStage != null)
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
remove(currentStage);
|
|
|
|
|
currentStage.kill();
|
|
|
|
|
dispatchEvent(new ScriptEvent(ScriptEvent.DESTROY, false));
|
|
|
|
|
currentStage = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
GameOverSubState.reset();
|
|
|
|
|
|
|
|
|
|
// Clear the static reference to this state.
|
|
|
|
|
instance = null;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Play the camera zoom animation and move to the results screen.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function moveToResultsScreen():Void
|
2023-06-16 17:37:56 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
trace('WENT TO RESULTS SCREEN!');
|
2023-06-16 17:37:56 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Stop camera zooming on beat.
|
|
|
|
|
cameraZoomRate = 0;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// If the opponent is GF, zoom in on the opponent.
|
|
|
|
|
// Else, if there is no GF, zoom in on BF.
|
|
|
|
|
// Else, zoom in on GF.
|
|
|
|
|
var targetDad:Bool = currentStage.getDad() != null && currentStage.getDad().characterId == 'gf';
|
|
|
|
|
var targetBF:Bool = currentStage.getGirlfriend() == null && !targetDad;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
if (targetBF)
|
2023-06-16 17:37:56 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.camera.follow(currentStage.getBoyfriend(), null, 0.05);
|
|
|
|
|
FlxG.camera.targetOffset.y -= 350;
|
|
|
|
|
FlxG.camera.targetOffset.x += 20;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
else if (targetDad)
|
2023-06-16 17:37:56 -04:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.camera.follow(currentStage.getDad(), null, 0.05);
|
|
|
|
|
FlxG.camera.targetOffset.y -= 350;
|
|
|
|
|
FlxG.camera.targetOffset.x += 20;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
FlxG.camera.follow(currentStage.getGirlfriend(), null, 0.05);
|
|
|
|
|
FlxG.camera.targetOffset.y -= 350;
|
|
|
|
|
FlxG.camera.targetOffset.x += 20;
|
2023-06-16 17:37:56 -04:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxTween.tween(camHUD, {alpha: 0}, 0.6);
|
2023-06-16 17:37:56 -04:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
// Zoom in on Girlfriend (or BF if no GF)
|
|
|
|
|
new FlxTimer().start(0.8, function(_) {
|
|
|
|
|
if (targetBF)
|
|
|
|
|
{
|
|
|
|
|
currentStage.getBoyfriend().animation.play('hey');
|
|
|
|
|
}
|
|
|
|
|
else if (targetDad)
|
|
|
|
|
{
|
|
|
|
|
currentStage.getDad().animation.play('cheer');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
currentStage.getGirlfriend().animation.play('cheer');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zoom over to the Results screen.
|
|
|
|
|
FlxTween.tween(FlxG.camera, {zoom: 1200}, 1.1,
|
|
|
|
|
{
|
|
|
|
|
ease: FlxEase.expoIn,
|
|
|
|
|
onComplete: function(_) {
|
|
|
|
|
persistentUpdate = false;
|
|
|
|
|
vocals.stop();
|
|
|
|
|
camHUD.alpha = 1;
|
2023-10-11 17:33:55 -04:00
|
|
|
|
var res:ResultState = new ResultState(
|
|
|
|
|
{
|
|
|
|
|
storyMode: PlayStatePlaylist.isStoryMode,
|
|
|
|
|
title: PlayStatePlaylist.isStoryMode ? ('${PlayStatePlaylist.campaignTitle}') : ('${currentChart.songName} by ${currentChart.songArtist}'),
|
|
|
|
|
tallies: Highscore.tallies,
|
|
|
|
|
});
|
2023-06-22 01:41:01 -04:00
|
|
|
|
res.camera = camHUD;
|
|
|
|
|
openSubState(res);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Pauses music and vocals easily.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
public function pauseMusic():Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.pause();
|
|
|
|
|
vocals.pause();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resets the camera's zoom level and focus point.
|
|
|
|
|
*/
|
|
|
|
|
public function resetCamera():Void
|
|
|
|
|
{
|
|
|
|
|
FlxG.camera.follow(cameraFollowPoint, LOCKON, 0.04);
|
|
|
|
|
FlxG.camera.targetOffset.set();
|
|
|
|
|
FlxG.camera.zoom = defaultCameraZoom;
|
2023-07-26 16:52:58 -04:00
|
|
|
|
// Snap the camera to the follow point immediately.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
FlxG.camera.focusOn(cameraFollowPoint.getPosition());
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#if debug
|
2023-01-22 19:55:30 -05:00
|
|
|
|
/**
|
2023-06-22 01:41:01 -04:00
|
|
|
|
* Jumps forward or backward a number of sections in the song.
|
|
|
|
|
* Accounts for BPM changes, does not prevent death from skipped notes.
|
|
|
|
|
* @param sections The number of sections to jump, negative to go backwards.
|
2023-01-22 19:55:30 -05:00
|
|
|
|
*/
|
2023-06-22 01:41:01 -04:00
|
|
|
|
function changeSection(sections:Int):Void
|
2023-01-22 19:55:30 -05:00
|
|
|
|
{
|
2023-06-22 01:41:01 -04:00
|
|
|
|
FlxG.sound.music.pause();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
var targetTimeSteps:Float = Conductor.currentStepTime + (Conductor.timeSignatureNumerator * Constants.STEPS_PER_BEAT * sections);
|
|
|
|
|
var targetTimeMs:Float = Conductor.getStepTimeInMs(targetTimeSteps);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
FlxG.sound.music.time = targetTimeMs;
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
handleSkippedNotes();
|
|
|
|
|
// regenNoteData(FlxG.sound.music.time);
|
2023-06-02 15:35:01 -04:00
|
|
|
|
|
2023-07-26 20:03:31 -04:00
|
|
|
|
Conductor.update(FlxG.sound.music.time);
|
2023-01-22 19:55:30 -05:00
|
|
|
|
|
2023-06-22 01:41:01 -04:00
|
|
|
|
resyncVocals();
|
2023-01-22 19:55:30 -05:00
|
|
|
|
}
|
2023-06-22 01:41:01 -04:00
|
|
|
|
#end
|
2021-08-27 18:08:01 -04:00
|
|
|
|
}
|