Skip to content

Commit

Permalink
cool pause music
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjamuffin99 committed Nov 20, 2020
1 parent f40b4df commit 5b46515
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
Binary file added assets/music/breakfast.mp3
Binary file not shown.
Binary file added assets/music/breakfast.ogg
Binary file not shown.
5 changes: 3 additions & 2 deletions source/MusicBeatState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions source/PauseSubState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,9 +16,18 @@ class PauseSubState extends MusicBeatSubstate
var menuItems:Array<String> = ['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();
Expand All @@ -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;
Expand Down Expand Up @@ -78,6 +91,13 @@ class PauseSubState extends MusicBeatSubstate
}
}

override function destroy()
{
pauseMusic.destroy();

super.destroy();
}

function changeSelection(change:Int = 0):Void
{
curSelected += change;
Expand Down
5 changes: 4 additions & 1 deletion source/PlayState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -588,14 +588,15 @@ class PlayState extends MusicBeatState

private var paused:Bool = false;
var startedCountdown:Bool = false;
var canPause:Bool = true;

override public function update(elapsed:Float)
{
super.update(elapsed);

scoreTxt.text = "Score:" + songScore;

if (FlxG.keys.justPressed.ENTER && startedCountdown)
if (FlxG.keys.justPressed.ENTER && startedCountdown && canPause)
{
persistentUpdate = false;
persistentDraw = true;
Expand Down Expand Up @@ -830,6 +831,8 @@ class PlayState extends MusicBeatState

function endSong():Void
{
canPause = false;

Highscore.saveScore(SONG.song, songScore, storyDifficulty);

if (isStoryMode)
Expand Down

0 comments on commit 5b46515

Please sign in to comment.