From c2b17d4e3ec380fef272dbbc1d7e457a0c4c5845 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 6 Nov 2020 02:56:45 -0800 Subject: [PATCH] WEEK SCORE SHIT --- source/Highscore.hx | 23 +++++++++++++++++++++++ source/PlayState.hx | 6 ++++++ source/StoryMenuState.hx | 14 ++++++++++++-- source/TitleState.hx | 2 +- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/source/Highscore.hx b/source/Highscore.hx index f587a3a17..b57870518 100644 --- a/source/Highscore.hx +++ b/source/Highscore.hx @@ -21,6 +21,21 @@ class Highscore setScore(daSong, score); } + public static function saveWeekScore(week:Int = 1, score:Int = 0, ?diff:Int = 0):Void + { + NGio.postScore(score, "Week " + week); + + var daWeek:String = formatSong('week' + week, diff); + + if (songScores.exists(daWeek)) + { + if (songScores.get(daWeek) < score) + setScore(daWeek, score); + } + else + setScore(daWeek, score); + } + /** * YOU SHOULD FORMAT SONG WITH formatSong() BEFORE TOSSING IN SONG VARIABLE */ @@ -52,6 +67,14 @@ class Highscore return songScores.get(formatSong(song, diff)); } + public static function getWeekScore(week:Int, diff:Int):Int + { + if (!songScores.exists(formatSong('week' + week, diff))) + setScore(formatSong('week' + week, diff), 0); + + return songScores.get(formatSong('week' + week, diff)); + } + public static function load():Void { if (FlxG.save.data.songScores != null) diff --git a/source/PlayState.hx b/source/PlayState.hx index 9ca8723a5..f22548a7e 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -37,6 +37,7 @@ class PlayState extends MusicBeatState public static var curLevel:String = 'Tutorial'; public static var SONG:SwagSong; public static var isStoryMode:Bool = false; + public static var storyWeek:Int = 0; public static var storyPlaylist:Array = []; public static var storyDifficulty:Int = 1; @@ -83,6 +84,8 @@ class PlayState extends MusicBeatState var talking:Bool = true; var songScore:Int = 0; + public static var campaignScore:Int = 0; + override public function create() { // var gameCam:FlxCamera = FlxG.camera; @@ -825,6 +828,8 @@ class PlayState extends MusicBeatState if (isStoryMode) { + campaignScore += songScore; + storyPlaylist.remove(storyPlaylist[0]); if (storyPlaylist.length <= 0) @@ -836,6 +841,7 @@ class PlayState extends MusicBeatState StoryMenuState.weekUnlocked[1] = true; NGio.unlockMedal(60961); + Highscore.saveWeekScore(storyWeek, campaignScore, storyDifficulty); FlxG.save.data.weekUnlocked = StoryMenuState.weekUnlocked; FlxG.save.flush(); diff --git a/source/StoryMenuState.hx b/source/StoryMenuState.hx index a12af46f0..1a0c50c5d 100644 --- a/source/StoryMenuState.hx +++ b/source/StoryMenuState.hx @@ -5,6 +5,7 @@ import flixel.FlxSprite; import flixel.graphics.frames.FlxAtlasFrames; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.group.FlxGroup; +import flixel.math.FlxMath; import flixel.text.FlxText; import flixel.tweens.FlxTween; import flixel.util.FlxTimer; @@ -149,7 +150,7 @@ class StoryMenuState extends MusicBeatState txtTracklist.color = 0xFFe55777; add(txtTracklist); // add(rankText); - // add(scoreText); + add(scoreText); updateText(); @@ -159,7 +160,9 @@ class StoryMenuState extends MusicBeatState override function update(elapsed:Float) { // scoreText.setFormat('VCR OSD Mono', 32); - // scoreText.text = "Score SHIT"; + lerpScore = Math.floor(FlxMath.lerp(lerpScore, intendedScore, 0.5)); + + scoreText.text = "WEEK SCORE:" + lerpScore; // FlxG.watch.addQuick('font', scoreText.font); difficultySelectors.visible = weekUnlocked[curWeek]; @@ -244,6 +247,7 @@ class StoryMenuState extends MusicBeatState PlayState.storyDifficulty = curDifficulty; PlayState.SONG = Song.loadFromJson(PlayState.storyPlaylist[0].toLowerCase() + diffic, PlayState.storyPlaylist[0].toLowerCase()); + PlayState.storyWeek = curWeek; new FlxTimer().start(1, function(tmr:FlxTimer) { if (FlxG.sound.music != null) @@ -281,10 +285,14 @@ class StoryMenuState extends MusicBeatState // USING THESE WEIRD VALUES SO THAT IT DOESNT FLOAT UP sprDifficulty.y = leftArrow.y - 15; + intendedScore = Highscore.getWeekScore(curWeek, curDifficulty); FlxTween.tween(sprDifficulty, {y: leftArrow.y + 15, alpha: 1}, 0.07); } + var lerpScore:Int = 0; + var intendedScore:Int = 0; + function changeWeek(change:Int = 0):Void { curWeek += change; @@ -329,5 +337,7 @@ class StoryMenuState extends MusicBeatState txtTracklist.screenCenter(X); txtTracklist.x -= FlxG.width * 0.35; + + intendedScore = Highscore.getWeekScore(curWeek, curDifficulty); } } diff --git a/source/TitleState.hx b/source/TitleState.hx index b3d81eac7..0c7a870e8 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -74,7 +74,7 @@ class TitleState extends MusicBeatState } #if SKIP_TO_PLAYSTATE - FlxG.switchState(new FreeplayState()); + FlxG.switchState(new StoryMenuState()); #else startIntro(); #end