From f4176616681e752ca8df757872611376748e91d2 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 10 Oct 2020 02:28:44 -0700 Subject: [PATCH] charting tool WIP shit --- source/ChartingState.hx | 67 ++++++++++++++++++++++++++++++++++++----- source/DisplayNote.hx | 14 +++++++++ 2 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 source/DisplayNote.hx diff --git a/source/ChartingState.hx b/source/ChartingState.hx index 6bb596ec5..dd36771d2 100644 --- a/source/ChartingState.hx +++ b/source/ChartingState.hx @@ -1,8 +1,10 @@ package; import flixel.FlxG; +import flixel.FlxSprite; import flixel.FlxState; import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.text.FlxText; import flixel.ui.FlxButton; import flixel.ui.FlxSpriteButton; import flixel.util.FlxColor; @@ -16,11 +18,18 @@ import openfl.net.FileReference; class ChartingState extends MusicBeatState { var _file:FileReference; - var sequencer:FlxTypedGroup; + var sequencer:FlxTypedGroup; var notes:Array = []; + var bpmTxt:FlxText; + + var strumLine:FlxSprite; override function create() { + FlxG.sound.playMusic('assets/music/Fresh.mp3', 0.6); + FlxG.sound.music.pause(); + Conductor.changeBPM(120); + var saveButton:FlxButton = new FlxButton(0, 0, "Save", function() { saveLevel(); @@ -28,6 +37,12 @@ class ChartingState extends MusicBeatState saveButton.screenCenter(); add(saveButton); + bpmTxt = new FlxText(20, 20); + add(bpmTxt); + + strumLine = new FlxSprite(0, 50).makeGraphic(Std.int(FlxG.width / 2), 4); + add(strumLine); + createStepChart(); super.create(); @@ -35,20 +50,24 @@ class ChartingState extends MusicBeatState function createStepChart() { - sequencer = new FlxTypedGroup(); + sequencer = new FlxTypedGroup(); add(sequencer); - for (r in 0...2) + for (r in 0...4) { notes.push([]); for (i in 0...16) { notes[r].push(false); - var seqBtn:FlxSpriteButton = new FlxSpriteButton((35 * r) + 10, (35 * i) + 50, null, function() + var seqBtn:DisplayNote = new DisplayNote((35 * r) + 10, (35 * i) + 50, null, function() { - notes[r][i] = !notes[r][i]; + if (notes[r][i] == 0) + notes[r][i] = 1; + else + notes[r][i] = 0; }); + seqBtn.strumTime = Conductor.stepCrochet * i; seqBtn.makeGraphic(30, 30, FlxColor.WHITE); seqBtn.ID = i + (16 * r); sequencer.add(seqBtn); @@ -58,17 +77,51 @@ class ChartingState extends MusicBeatState override function update(elapsed:Float) { - sequencer.forEach(function(spr:FlxSpriteButton) + Conductor.songPosition = FlxG.sound.music.time; + + if (FlxG.sound.music.playing) { - if (notes[Std.int(spr.ID / 16)][spr.ID % 16]) + } + else + { + if (FlxG.keys.pressed.W) + FlxG.sound.music.time -= 900 * FlxG.elapsed; + if (FlxG.keys.pressed.S) + FlxG.sound.music.time += 900 * FlxG.elapsed; + } + + if (FlxG.keys.justPressed.SPACE) + { + if (FlxG.sound.music.playing) + { + FlxG.sound.music.pause(); + } + else + FlxG.sound.music.play(); + } + + if (FlxG.keys.justPressed.UP) + Conductor.changeBPM(Conductor.bpm + 1); + if (FlxG.keys.justPressed.DOWN) + Conductor.changeBPM(Conductor.bpm - 1); + + bpmTxt.text = "BPM: " + Conductor.bpm; + + sequencer.forEach(function(spr:DisplayNote) + { + if (notes[Std.int(spr.ID / 16)][spr.ID % 16] != 0) spr.alpha = 1; else spr.alpha = 0.5; + + spr.y = (strumLine.y - (Conductor.songPosition - spr.strumTime) * daSpacing); }); super.update(elapsed); } + private var daSpacing:Float = 0.3; + private function saveLevel() { var json = { diff --git a/source/DisplayNote.hx b/source/DisplayNote.hx new file mode 100644 index 000000000..171e98c41 --- /dev/null +++ b/source/DisplayNote.hx @@ -0,0 +1,14 @@ +package; + +import flixel.FlxSprite; +import flixel.ui.FlxSpriteButton; + +class DisplayNote extends FlxSpriteButton +{ + public var strumTime:Float = 0; + + public function new(x:Float, y:Float, label:FlxSprite, onClick:Void->Void) + { + super(x, y, label, onClick); + } +}