diff --git a/source/Conductor.hx b/source/Conductor.hx index 710b13584..a182070b0 100644 --- a/source/Conductor.hx +++ b/source/Conductor.hx @@ -1,9 +1,19 @@ package; +import Song.SwagSong; + /** * ... * @author */ + +typedef BPMChangeEvent = +{ + var stepTime:Int; + var songTime:Float; + var bpm:Int; +} + class Conductor { public static var bpm:Int = 100; @@ -16,10 +26,39 @@ class Conductor public static var safeFrames:Int = 10; public static var safeZoneOffset:Float = (safeFrames / 60) * 1000; // is calculated in create(), is safeFrames in milliseconds + public static var bpmChangeMap:Array = []; + public function new() { } + public static function mapBPMChanges(song:SwagSong) + { + bpmChangeMap = []; + + var curBPM:Int = song.bpm; + var totalSteps:Int = 0; + var totalPos:Float = 0; + for (i in 0...song.notes.length) + { + if(song.notes[i].changeBPM && song.notes[i].bpm != curBPM) + { + curBPM = song.notes[i].bpm; + var event:BPMChangeEvent = { + stepTime: totalSteps, + songTime: totalPos, + bpm: curBPM + }; + bpmChangeMap.push(event); + } + + var deltaSteps:Int = song.notes[i].lengthInSteps; + totalSteps += deltaSteps; + totalPos += ((60 / curBPM) * 1000 / 4) * deltaSteps; + } + trace("new BPM map BUDDY " + bpmChangeMap); + } + public static function changeBPM(newBpm:Int) { bpm = newBpm; diff --git a/source/MusicBeatState.hx b/source/MusicBeatState.hx index bda503128..1be91a32f 100644 --- a/source/MusicBeatState.hx +++ b/source/MusicBeatState.hx @@ -1,5 +1,6 @@ package; +import Conductor.BPMChangeEvent; import flixel.FlxG; import flixel.addons.transition.FlxTransitionableState; import flixel.addons.ui.FlxUIState; @@ -38,7 +39,7 @@ class MusicBeatState extends FlxUIState everyStep(); updateCurStep(); - // Needs to be ROUNED, rather than ceil or floor + // Needs to be FLOOR idk why it was rounded but that dont make sense updateBeat(); super.update(elapsed); @@ -46,7 +47,7 @@ class MusicBeatState extends FlxUIState private function updateBeat():Void { - curBeat = Math.round(curStep / 4); + curBeat = Math.floor(curStep / 4); } /** @@ -66,7 +67,18 @@ class MusicBeatState extends FlxUIState private function updateCurStep():Void { - curStep = Math.floor(Conductor.songPosition / Conductor.stepCrochet); + var lastChange:BPMChangeEvent = { + stepTime: 0, + songTime: 0, + bpm: 0 + } + for (i in 0...Conductor.bpmChangeMap.length) + { + if (Conductor.songPosition >= Conductor.bpmChangeMap[i].songTime) + lastChange = Conductor.bpmChangeMap[i]; + } + + curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); } public function stepHit():Void diff --git a/source/MusicBeatSubstate.hx b/source/MusicBeatSubstate.hx index 511f597a7..90c3824e5 100644 --- a/source/MusicBeatSubstate.hx +++ b/source/MusicBeatSubstate.hx @@ -1,5 +1,6 @@ package; +import Conductor.BPMChangeEvent; import flixel.FlxG; import flixel.FlxSubState; @@ -37,7 +38,7 @@ class MusicBeatSubstate extends FlxSubState everyStep(); updateCurStep(); - curBeat = Math.round(curStep / 4); + curBeat = Math.floor(curStep / 4); super.update(elapsed); } @@ -59,7 +60,18 @@ class MusicBeatSubstate extends FlxSubState private function updateCurStep():Void { - curStep = Math.floor(Conductor.songPosition / Conductor.stepCrochet); + var lastChange:BPMChangeEvent = { + stepTime: 0, + songTime: 0, + bpm: 0 + } + for (i in 0...Conductor.bpmChangeMap.length) + { + if (Conductor.songPosition > Conductor.bpmChangeMap[i].songTime) + lastChange = Conductor.bpmChangeMap[i]; + } + + curStep = lastChange.stepTime + Math.floor((Conductor.songPosition - lastChange.songTime) / Conductor.stepCrochet); } public function stepHit():Void diff --git a/source/PlayState.hx b/source/PlayState.hx index 93d98cab0..1bdfb7215 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -140,6 +140,7 @@ class PlayState extends MusicBeatState if (SONG == null) SONG = Song.loadFromJson('tutorial'); + Conductor.mapBPMChanges(SONG); Conductor.changeBPM(SONG.bpm); switch (SONG.song.toLowerCase()) @@ -1446,6 +1447,8 @@ class PlayState extends MusicBeatState } FlxG.watch.addQuick("beatShit", totalBeats); + FlxG.watch.addQuick("stepShit", totalSteps); + if (curSong == 'Fresh') { @@ -2283,7 +2286,7 @@ class PlayState extends MusicBeatState // FlxG.log.add('change bpm' + SONG.notes[Std.int(curStep / 16)].changeBPM); // HARDCODING FOR MILF ZOOMS! - if (curSong.toLowerCase() == 'milf' && curBeat >= 168 && curBeat <= 200 && camZooming && FlxG.camera.zoom < 1.35) + if (curSong.toLowerCase() == 'milf' && curBeat >= 168 && curBeat < 200 && camZooming && FlxG.camera.zoom < 1.35) { FlxG.camera.zoom += 0.015; camHUD.zoom += 0.03; diff --git a/source/Song.hx b/source/Song.hx index 55827e79b..e9f3dc20f 100644 --- a/source/Song.hx +++ b/source/Song.hx @@ -12,8 +12,6 @@ typedef SwagSong = var song:String; var notes:Array; var bpm:Int; - var sections:Int; - var sectionLengths:Array; var needsVoices:Bool; var speed:Float; @@ -27,25 +25,17 @@ class Song public var song:String; public var notes:Array; public var bpm:Int; - public var sections:Int; - public var sectionLengths:Array = []; public var needsVoices:Bool = true; public var speed:Float = 1; public var player1:String = 'bf'; public var player2:String = 'dad'; - public function new(song, notes, bpm, sections) + public function new(song, notes, bpm) { this.song = song; this.notes = notes; this.bpm = bpm; - this.sections = sections; - - for (i in 0...notes.length) - { - this.sectionLengths.push(notes[i]); - } } public static function loadFromJson(jsonInput:String, ?folder:String):SwagSong @@ -72,9 +62,7 @@ class Song daNotes = songData.notes; daSong = songData.song; - daSections = songData.sections; - daBpm = songData.bpm; - daSectionLengths = songData.sectionLengths; */ + daBpm = songData.bpm; */ return parseJSONshit(rawJson); }