Update PlayState.hx

This commit is contained in:
Zyflx 2023-05-24 19:29:31 -04:00 committed by GitHub
parent 436bd98ffc
commit c8bf7f8053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 115 additions and 104 deletions

View File

@ -39,10 +39,15 @@ import openfl.display.BitmapData;
import openfl.display.BlendMode;
import openfl.display.StageQuality;
import openfl.filters.ShaderFilter;
#if (hxCodec >= "2.6.1") import hxcodec.flixel.VideoHandler as MP4Handler;
#elseif (hxCodec == "2.6.0") import VideoHandler as MP4Handler; #end
import game.data.backend.*;
import game.data.scripts.*;
import game.data.backend.Section.SwagSection;
import game.data.backend.Song.SwagSong;
import game.data.debug.AnimationDebug;
import game.objects.shaders.WiggleEffect;
import game.objects.shaders.WiggleEffect.WiggleEffectType;
import game.objects.shaders.ColorSwap;
@ -50,8 +55,10 @@ import game.objects.cutscene.FlxVideo;
import game.objects.stages.GameStage;
import game.objects.*;
import game.objects.stages.background.*;
import game.ui.gameplay.*;
import game.ui.gameplay.note.*;
import game.state.charting.*;
import game.state.subState.GameOverSubstate;
import game.state.subState.PauseSubState;
@ -69,17 +76,14 @@ class PlayState extends MusicBeatState
{
// Organized the vars to the best of my abilites
// Hope it suffices
// Song / Gameplay Variables
public var vocals:FlxSound;
public var generatedMusic:Bool = false;
public var startingSong:Bool = false;
public var gfSpeed:Int = 1;
public var combo:Int = 0;
public static var SONG:SwagSong;
private var vocals:FlxSound;
private var generatedMusic:Bool = false;
private var startingSong:Bool = false;
private var vocalsFinished:Bool = false;
private var curSong:String = "";
private var gfSpeed:Int = 1;
private var combo:Int = 0;
public static var health:Float = 1;
public static var songScore:Int = 0;
public static var songMisses:Int = 0;
@ -90,60 +94,61 @@ class PlayState extends MusicBeatState
public static var storyDifficulty:Int = 1;
public static var deathCounter:Int = 0;
public static var practiceMode:Bool = false;
private var curSong:String = "";
private var vocalsFinished:Bool = false;
///////////// Stage Variables ///////////
var gameStage:GameStage;
// Week 6
public static var daPixelZoom:Float = 6;
// Other
public static var curStage:String = '';
public static var isPixel:Bool = false;
///////////////////////////////////////
// Character Stuff
private var dad:Character;
private var gf:Character;
private var boyfriend:Boyfriend;
public var dad:Character;
public var gf:Character;
public var boyfriend:Boyfriend;
private var singAnims:Array<String> = ['singLEFT', 'singDOWN', 'singUP', 'singRIGHT'];
// Note Stuff
private var notes:FlxTypedGroup<Note>;
private var unspawnNotes:Array<Note> = [];
private var strumLineNotes:FlxTypedGroup<StaticNote>;
private var playerStrums:FlxTypedGroup<StaticNote>;
private var oppStrums:FlxTypedGroup<StaticNote>;
public var notes:FlxTypedGroup<Note>;
public var unspawnNotes:Array<Note> = [];
public var strumLineNotes:FlxTypedGroup<StaticNote>;
public var playerStrums:FlxTypedGroup<StaticNote>;
public var oppStrums:FlxTypedGroup<StaticNote>;
private var strumLine:FlxSprite;
var grpNoteSplashes:FlxTypedGroup<NoteSplash>;
public var grpNoteSplashes:FlxTypedGroup<NoteSplash>;
// UI Stuff
var UI:GameUI;
// Camera Stuff
private var camGame:FlxCamera;
private var camHUD:FlxCamera;
private var camOther:FlxCamera;
private var camFollow:FlxObject;
private var camZooming:Bool = false;
public var camGame:FlxCamera;
public var camHUD:FlxCamera;
public var camOther:FlxCamera;
public var camFollow:FlxObject;
public var camZooming:Bool = false;
private static var prevCamFollow:FlxObject;
public static var defaultCamZoom:Float = 1.05;
var camPos:FlxPoint;
// Cutscene / Dialogue Stuff
var dialogue:Array<String> = ['blah blah blah', 'coolswag'];
var talking:Bool = true;
public static var inCutscene:Bool = false;
public static var seenCutscene:Bool = false;
var gfCutsceneLayer:FlxGroup;
var bfTankCutsceneLayer:FlxGroup;
// Shaders
var wiggleShit:WiggleEffect = new WiggleEffect();
// Other
public static var instance:PlayState;
public static var scriptArray:Array<Script> = []; // For Scripts
// Discord RPC variables
#if discord_rpc
var storyDifficultyText:String = "";
@ -153,14 +158,22 @@ class PlayState extends MusicBeatState
var detailsPausedText:String = "";
#end
override public function create()
function resetStaticVars()
{
songScore = 0;
songMisses = 0;
health = 1;
scriptArray = [];
}
if (FlxG.sound.music != null)
FlxG.sound.music.stop();
override public function create()
{
// Reset any static variables
resetStaticVars();
instance = this;
if (FlxG.sound.music != null) FlxG.sound.music.stop();
FlxG.sound.cache(Paths.inst(PlayState.SONG.song));
FlxG.sound.cache(Paths.voices(PlayState.SONG.song));
@ -180,11 +193,12 @@ class PlayState extends MusicBeatState
persistentDraw = true;
if (SONG == null)
SONG = Song.loadFromJson('tutorial');
SONG = Song.loadFromJson('tutorial', 'tutorial');
Conductor.mapBPMChanges(SONG);
Conductor.changeBPM(SONG.bpm);
switch (SONG.song.toLowerCase())
{
case 'senpai':
@ -199,6 +213,9 @@ class PlayState extends MusicBeatState
initDiscord();
#end
// Run scripts
Script.runScripts(scriptArray, ['scripts', 'data/' + SONG.song.toLowerCase()]);
isPixel = false;
// Add the stage
@ -285,15 +302,13 @@ class PlayState extends MusicBeatState
add(bfTankCutsceneLayer);
// Shitty layering but whatev it works LOL
if (gameStage.getStage() == 'limo')
add(gameStage.limo);
if (gameStage.getStage() == 'limo') add(gameStage.limo);
add(dad);
add(boyfriend);
if (gameStage.getStage() == 'tank')
add(gameStage.foregroundSprites);
if (gameStage.getStage() == 'tank') add(gameStage.foregroundSprites);
add(gameStage.fgSprites);
var doof:DialogueBox = new DialogueBox(false, dialogue);
@ -363,11 +378,6 @@ class PlayState extends MusicBeatState
UI.cameras = [camHUD];
doof.cameras = [camHUD];
// if (SONG.song == 'South')
// FlxG.camera.alpha = 0.7;
// UI_camera.zoom = 1;
// cameras = [FlxG.cameras.list[1]];
startingSong = true;
if (isStoryMode && !seenCutscene)
@ -425,6 +435,8 @@ class PlayState extends MusicBeatState
startCountdown();
}
}
for (i in scriptArray) i.callFunction('createPost');
super.create();
}
@ -437,7 +449,7 @@ class PlayState extends MusicBeatState
blackShit.scrollFactor.set();
add(blackShit);
var vid:FlxVideo = new FlxVideo('music/ughCutscene.mp4');
var vid:FlxVideo = new FlxVideo(Paths.video('ughCutscene'));
vid.finishCallback = function()
{
remove(blackShit);
@ -471,17 +483,6 @@ class PlayState extends MusicBeatState
};
}
/**
* [
* [0, function(){blah;}],
* [4.6, function(){blah;}],
* [25.1, function(){blah;}],
* [30.7, function(){blah;}]
* ]
* SOMETHING LIKE THIS
*/
// var cutsceneFunctions:Array<Dynamic> = [];
function stressIntro()
{
inCutscene = true;
@ -618,6 +619,8 @@ class PlayState extends MusicBeatState
function startCountdown():Void
{
for (i in scriptArray) i.callFunction('startCountdown');
inCutscene = false;
camHUD.visible = true;
@ -657,10 +660,8 @@ class PlayState extends MusicBeatState
introSprPaths = ['weeb/pixelUI/ready-pixel', 'weeb/pixelUI/set-pixel', 'weeb/pixelUI/date-pixel'];
}
var introSndPaths:Array<String> = [
"intro3" + altSuffix, "intro2" + altSuffix,
"intro1" + altSuffix, "introGo" + altSuffix
];
var introSndPaths:Array<String> = ["intro3" + altSuffix, "intro2" + altSuffix,
"intro1" + altSuffix, "introGo" + altSuffix];
if (swagCounter > 0)
readySetGo(introSprPaths[swagCounter - 1]);
@ -675,8 +676,7 @@ class PlayState extends MusicBeatState
var spr:FlxSprite = new FlxSprite().loadGraphic(Paths.image(path));
spr.scrollFactor.set();
if (isPixel)
spr.setGraphicSize(Std.int(spr.width * daPixelZoom));
if (isPixel) spr.setGraphicSize(Std.int(spr.width * daPixelZoom));
spr.updateHitbox();
spr.screenCenter();
@ -695,6 +695,8 @@ class PlayState extends MusicBeatState
function startSong():Void
{
for (i in scriptArray) i.callFunction('songStart');
startingSong = false;
previousFrameTime = FlxG.game.ticks;
@ -831,10 +833,8 @@ class PlayState extends MusicBeatState
babyArrow.ID = i;
if (player == 1)
playerStrums.add(babyArrow);
if (player == 2)
oppStrums.add(babyArrow);
if (player == 1) playerStrums.add(babyArrow);
if (player == 2) oppStrums.add(babyArrow);
babyArrow.playStrumAnim('static');
babyArrow.x += 50;
@ -943,6 +943,8 @@ class PlayState extends MusicBeatState
// Update The Stages
gameStage.updateStage(elapsed, boyfriend, dad, gf);
for (i in scriptArray) i.callFunction('update', [elapsed]);
// do this BEFORE super.update() so songPosition is accurate
if (startingSong)
{
@ -1018,12 +1020,12 @@ class PlayState extends MusicBeatState
if (FlxG.keys.justPressed.EIGHT)
{
/* 8 for opponent char
SHIFT+8 for player char
CTRL+SHIFT+8 for gf */
SHIFT+8 for player char
CTRL+SHIFT+8 for gf */
if (FlxG.keys.pressed.SHIFT)
if (FlxG.keys.pressed.CONTROL)
FlxG.switchState(new AnimationDebug(gf.curCharacter));
else
else
FlxG.switchState(new AnimationDebug(SONG.player1));
else
FlxG.switchState(new AnimationDebug(SONG.player2));
@ -1068,8 +1070,7 @@ class PlayState extends MusicBeatState
{
switch (curBeat)
{
case 128, 129, 130:
vocals.volume = 0;
case 128, 129, 130: vocals.volume = 0;
}
}
// better streaming of shit
@ -1183,8 +1184,7 @@ class PlayState extends MusicBeatState
}
}
if (!daNote.mustPress && daNote.wasGoodHit)
opponentNoteHit(daNote);
if (!daNote.mustPress && daNote.wasGoodHit) opponentNoteHit(daNote);
// WIP interpolation shit? Need to fix the pause issue
// daNote.y = (strumLine.y - (songTime - daNote.strumTime) * (0.45 * SONG.speed));
@ -1193,7 +1193,7 @@ class PlayState extends MusicBeatState
// var noteMiss:Bool = daNote.y < -daNote.height;
// if (PreferencesMenu.getPref('downscroll'))
// noteMiss = daNote.y > FlxG.height;
// noteMiss = daNote.y > FlxG.height;
if (daNote.isSustainNote && daNote.wasGoodHit)
{
@ -1229,6 +1229,8 @@ class PlayState extends MusicBeatState
});
}
for (i in scriptArray) i.callFunction('updatePost', [elapsed]);
if (!inCutscene)
keyShit();
}
@ -1267,6 +1269,8 @@ class PlayState extends MusicBeatState
function endSong():Void
{
for (i in scriptArray) i.callFunction('songEnd');
seenCutscene = false;
deathCounter = 0;
canPause = false;
@ -1376,8 +1380,7 @@ class PlayState extends MusicBeatState
var isSick:Bool = true;
if (daRating != 'sick')
isSick = false;
if (daRating != 'sick') isSick = false;
if (isSick)
{
@ -1389,13 +1392,11 @@ class PlayState extends MusicBeatState
UI.updateAcc(UI.ratingMap.get(daRating));
// Only add the score if you're not on practice mode
if (!practiceMode)
songScore += Conductor.getRatingScore(noteDiff);
if (!practiceMode) songScore += Conductor.getRatingScore(noteDiff);
var ratingPath:String = daRating;
if (isPixel)
ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel";
if (isPixel) ratingPath = "weeb/pixelUI/" + ratingPath + "-pixel";
var rating = JudgeSpr.spawnJudgeSpr(ratingPath, isPixel);
add(rating);
@ -1408,18 +1409,16 @@ class PlayState extends MusicBeatState
startDelay: Conductor.crochet * 0.001
});
// if (combo >= 10 || combo == 0)
displayCombo();
displayCombo();
}
function displayCombo():Void
{
var imgPath:String = 'combo';
if (isPixel)
imgPath = 'weeb/pixelUI/combo-pixel';
if (isPixel) imgPath = 'weeb/pixelUI/combo-pixel';
var comboSpr = JudgeSpr.spawnComboSpr(imgPath, isPixel);
if (combo >= 10 || combo == 0)
add(comboSpr);
if (combo >= 10 || combo == 0) add(comboSpr);
FlxTween.tween(comboSpr, {alpha: 0}, 0.2, {
onComplete: function(tween:FlxTween)
@ -1446,8 +1445,7 @@ class PlayState extends MusicBeatState
for (i in seperatedScore)
{
var imgPath:String = 'num' + Std.int(i);
if (isPixel)
imgPath = 'weeb/pixelUI/num' + Std.int(i) + '-pixel';
if (isPixel) imgPath = 'weeb/pixelUI/num' + Std.int(i) + '-pixel';
var numScore = JudgeSpr.spawnComboNum(imgPath, isPixel);
add(numScore);
@ -1604,15 +1602,15 @@ class PlayState extends MusicBeatState
}
}
/*
Commented This Out To Enable Ghost Tapping.
Will be reused later when i add an option to enable / disable ghost tapping.
Commented This Out To Enable Ghost Tapping.
Will be reused later when i add an option to enable / disable ghost tapping.
- Zyflx
else
{
for (shit in 0...pressArray.length)
if (pressArray[shit])
noteMiss(shit);
- Zyflx
else
{
for (shit in 0...pressArray.length)
if (pressArray[shit])
noteMiss(shit);
}*/
}
@ -1626,15 +1624,15 @@ class PlayState extends MusicBeatState
playerStrums.forEach(function(spr:StaticNote)
{
if (pressArray[spr.ID] && spr.animation.curAnim.name != 'confirm')
spr.playStrumAnim('pressed', true);
if (!holdArray[spr.ID])
spr.playStrumAnim('static', true);
if (pressArray[spr.ID] && spr.animation.curAnim.name != 'confirm') spr.playStrumAnim('pressed', true);
if (!holdArray[spr.ID]) spr.playStrumAnim('static', true);
});
}
function noteMiss(direction:Int = 1):Void
{
for (i in scriptArray) i.callFunction('noteMiss', [direction]);
// whole function used to be encased in if (!boyfriend.stunned)
songMisses++;
health -= 0.04;
@ -1652,6 +1650,8 @@ class PlayState extends MusicBeatState
function goodNoteHit(note:Note):Void
{
for (i in scriptArray) i.callFunction('goodNoteHit', [notes.members.indexOf(note), note.noteData, note.isSustainNote]);
if (!note.wasGoodHit)
{
if (!note.isSustainNote)
@ -1683,6 +1683,8 @@ class PlayState extends MusicBeatState
function opponentNoteHit(note:Note)
{
for (i in scriptArray) i.callFunction('opponentNoteHit', [notes.members.indexOf(note), note.noteData, note.isSustainNote]);
if (SONG.song != 'Tutorial')
camZooming = true;
@ -1694,12 +1696,10 @@ class PlayState extends MusicBeatState
altAnim = '-alt';
}
if (note.altNote)
altAnim = '-alt';
if (note.altNote) altAnim = '-alt';
var time:Float = 0.15;
if (note.isSustainNote && !note.animation.curAnim.name.endsWith('end'))
time += 0.15;
if (note.isSustainNote && !note.animation.curAnim.name.endsWith('end')) time += 0.15;
strumAnim(note.noteData, true, time);
@ -1721,6 +1721,12 @@ class PlayState extends MusicBeatState
gameStage.stepHit(curStep, boyfriend, dad, gf);
for (i in scriptArray)
{
i.set('curStep', curStep);
i.callFunction('stepHit');
}
if (Math.abs(FlxG.sound.music.time - (Conductor.songPosition - Conductor.offset)) > 20
|| (SONG.needsVoices && Math.abs(vocals.time - (Conductor.songPosition - Conductor.offset)) > 20))
{
@ -1740,6 +1746,12 @@ class PlayState extends MusicBeatState
gameStage.beatHit(curBeat, boyfriend, dad, gf);
UI.iconBeat();
for (i in scriptArray)
{
i.set('curBeat', curBeat);
i.callFunction('beatHit');
}
if (generatedMusic)
{
notes.sort(sortNotes, FlxSort.DESCENDING);
@ -1811,8 +1823,7 @@ class PlayState extends MusicBeatState
else
strum = playerStrums.members[id];
if (strum != null)
{
if (strum != null) {
strum.playStrumAnim('confirm', true);
strum.animReset = time;
}