Skip to content

Commit

Permalink
WEEK SCORE SHIT
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Nov 6, 2020
1 parent 054e9f4 commit cf7b871
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/data/dadbattle/dadbattle-hard.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions source/Highscore.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = [];
public static var storyDifficulty:Int = 1;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -825,6 +828,8 @@ class PlayState extends MusicBeatState

if (isStoryMode)
{
campaignScore += songScore;

storyPlaylist.remove(storyPlaylist[0]);

if (storyPlaylist.length <= 0)
Expand All @@ -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();
Expand Down
14 changes: 12 additions & 2 deletions source/StoryMenuState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,7 +150,7 @@ class StoryMenuState extends MusicBeatState
txtTracklist.color = 0xFFe55777;
add(txtTracklist);
// add(rankText);
// add(scoreText);
add(scoreText);

updateText();

Expand All @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -329,5 +337,7 @@ class StoryMenuState extends MusicBeatState

txtTracklist.screenCenter(X);
txtTracklist.x -= FlxG.width * 0.35;

intendedScore = Highscore.getWeekScore(curWeek, curDifficulty);
}
}
2 changes: 1 addition & 1 deletion source/TitleState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class TitleState extends MusicBeatState
}

#if SKIP_TO_PLAYSTATE
FlxG.switchState(new FreeplayState());
FlxG.switchState(new StoryMenuState());
#else
startIntro();
#end
Expand Down

0 comments on commit cf7b871

Please sign in to comment.