From 4d4a724d72474759d37633d8cee139499ca560f9 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Oct 2020 19:39:52 -0700 Subject: [PATCH] redoing and replacing some of the music logic --- source/ChartingState.hx | 11 +++++++++ source/MusicBeatState.hx | 53 ++++++++++++++++++++++++++++++++++++++++ source/PlayState.hx | 49 +++++++++---------------------------- 3 files changed, 75 insertions(+), 38 deletions(-) create mode 100644 source/ChartingState.hx create mode 100644 source/MusicBeatState.hx diff --git a/source/ChartingState.hx b/source/ChartingState.hx new file mode 100644 index 000000000..766622f91 --- /dev/null +++ b/source/ChartingState.hx @@ -0,0 +1,11 @@ +package; + +import flixel.FlxState; + +class ChartingState extends FlxState +{ + override function create() + { + super.create(); + } +} diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx new file mode 100644 index 000000000..f09fad7ea --- /dev/null +++ b/source/MusicBeatState.hx @@ -0,0 +1,53 @@ +package; + +import flixel.addons.transition.FlxTransitionableState; + +class MusicBeatState extends FlxTransitionableState +{ + private var lastBeat:Float = 0; + private var lastStep:Float = 0; + + private var totalBeats:Int = 0; + private var totalSteps:Int = 0; + + override function create() + { + super.create(); + } + + private function everyBeat():Void + { + if (Conductor.songPosition > lastBeat + Conductor.crochet - Conductor.safeZoneOffset + || Conductor.songPosition < lastBeat + Conductor.safeZoneOffset) + { + if (Conductor.songPosition > lastBeat + Conductor.crochet) + { + beatHit(); + } + } + } + + private function everyStep():Void + { + if (Conductor.songPosition > lastStep + Conductor.stepCrochet - Conductor.safeZoneOffset + || Conductor.songPosition < lastStep + Conductor.safeZoneOffset) + { + if (Conductor.songPosition > lastStep + Conductor.stepCrochet) + { + stepHit(); + } + } + } + + public function stepHit():Void + { + totalSteps += 1; + lastStep += Conductor.stepCrochet; + } + + public function beatHit():Void + { + lastBeat += Conductor.crochet; + totalBeats += 1; + } +} diff --git a/source/PlayState.hx b/source/PlayState.hx index 54d61a1b3..12ef5c76a 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -26,17 +26,12 @@ import lime.utils.Assets; using StringTools; -class PlayState extends FlxTransitionableState +class PlayState extends MusicBeatState { public static var curLevel:String = 'Bopeebo'; - private var lastBeat:Float = 0; - private var lastStep:Float = 0; private var vocals:FlxSound; - private var totalBeats:Int = 0; - private var totalSteps:Int = 0; - private var dad:Dad; private var gf:Girlfriend; private var boyfriend:Boyfriend; @@ -1026,42 +1021,20 @@ class PlayState extends FlxTransitionableState } } - private function everyBeat():Void + override function beatHit() { - if (Conductor.songPosition > lastBeat + Conductor.crochet - Conductor.safeZoneOffset - || Conductor.songPosition < lastBeat + Conductor.safeZoneOffset) - { - if (Conductor.songPosition > lastBeat + Conductor.crochet) - { - lastBeat += Conductor.crochet; + super.beatHit(); - if (camZooming && FlxG.camera.zoom < 1.35 && totalBeats % 4 == 0) - FlxG.camera.zoom += 0.025; + if (camZooming && FlxG.camera.zoom < 1.35 && totalBeats % 4 == 0) + FlxG.camera.zoom += 0.025; - totalBeats += 1; + dad.playAnim('idle'); + healthHeads.setGraphicSize(Std.int(healthHeads.width + 20)); - dad.playAnim('idle'); - healthHeads.setGraphicSize(Std.int(healthHeads.width + 20)); + if (totalBeats % gfSpeed == 0) + gf.dance(); - if (totalBeats % gfSpeed == 0) - gf.dance(); - - if (!boyfriend.animation.curAnim.name.startsWith("sing")) - boyfriend.playAnim('idle'); - } - } - } - - private function everyStep():Void - { - if (Conductor.songPosition > lastStep + Conductor.stepCrochet - Conductor.safeZoneOffset - || Conductor.songPosition < lastStep + Conductor.safeZoneOffset) - { - if (Conductor.songPosition > lastStep + Conductor.stepCrochet) - { - totalSteps += 1; - lastStep += Conductor.stepCrochet; - } - } + if (!boyfriend.animation.curAnim.name.startsWith("sing")) + boyfriend.playAnim('idle'); } }