From 36b0302ac42d5c734af20f23dd9da61409d844d8 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 20 Nov 2020 04:21:04 -0800 Subject: [PATCH] cool pause music --- source/MusicBeatState.hx | 5 +++-- source/PauseSubState.hx | 20 ++++++++++++++++++++ source/PlayState.hx | 5 ++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index 23d2b6b91..029a495b8 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -34,7 +34,8 @@ class MusicBeatState extends FlxUIState everyStep(); updateCurStep(); - curBeat = Math.floor(curStep / 4); + // Needs to be ROUNED, rather than ceil or floor + curBeat = Math.round(curStep / 4); super.update(elapsed); } @@ -68,7 +69,7 @@ class MusicBeatState extends FlxUIState if (Conductor.songPosition > lastStep + (Conductor.stepCrochet * 3)) { lastStep = Conductor.songPosition; - totalSteps = Math.round(lastStep / Conductor.stepCrochet); + totalSteps = Math.ceil(lastStep / Conductor.stepCrochet); } if (totalSteps % 4 == 0) diff --git a/source/PauseSubState.hx b/source/PauseSubState.hx index efc9a716c..1c7297043 100644 --- a/source/PauseSubState.hx +++ b/source/PauseSubState.hx @@ -6,6 +6,7 @@ import flixel.FlxSprite; import flixel.FlxSubState; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.input.keyboard.FlxKey; +import flixel.system.FlxSound; import flixel.util.FlxColor; class PauseSubState extends MusicBeatSubstate @@ -15,9 +16,18 @@ class PauseSubState extends MusicBeatSubstate var menuItems:Array = ['Resume', 'Restart Song', 'Exit to menu']; var curSelected:Int = 0; + var pauseMusic:FlxSound; + public function new(x:Float, y:Float) { super(); + + pauseMusic = new FlxSound().loadEmbedded('assets/music/breakfast' + TitleState.soundExt, true, true); + pauseMusic.volume = 0; + pauseMusic.play(false, FlxG.random.int(0, Std.int(pauseMusic.length / 2))); + + FlxG.sound.list.add(pauseMusic); + var bg:FlxSprite = new FlxSprite().makeGraphic(FlxG.width, FlxG.height, FlxColor.BLACK); bg.alpha = 0.6; bg.scrollFactor.set(); @@ -41,6 +51,9 @@ class PauseSubState extends MusicBeatSubstate override function update(elapsed:Float) { + if (pauseMusic.volume < 0.5) + pauseMusic.volume += 0.01 * elapsed; + super.update(elapsed); var upP = controls.UP_P; @@ -78,6 +91,13 @@ class PauseSubState extends MusicBeatSubstate } } + override function destroy() + { + pauseMusic.destroy(); + + super.destroy(); + } + function changeSelection(change:Int = 0):Void { curSelected += change; diff --git a/source/PlayState.hx b/source/PlayState.hx index 71297289e..0aaba0112 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -588,6 +588,7 @@ class PlayState extends MusicBeatState private var paused:Bool = false; var startedCountdown:Bool = false; + var canPause:Bool = true; override public function update(elapsed:Float) { @@ -595,7 +596,7 @@ class PlayState extends MusicBeatState scoreTxt.text = "Score:" + songScore; - if (FlxG.keys.justPressed.ENTER && startedCountdown) + if (FlxG.keys.justPressed.ENTER && startedCountdown && canPause) { persistentUpdate = false; persistentDraw = true; @@ -830,6 +831,8 @@ class PlayState extends MusicBeatState function endSong():Void { + canPause = false; + Highscore.saveScore(SONG.song, songScore, storyDifficulty); if (isStoryMode)