diff --git a/source/LatencyState.hx b/source/LatencyState.hx new file mode 100644 index 000000000..8ff4fab95 --- /dev/null +++ b/source/LatencyState.hx @@ -0,0 +1,74 @@ +package; + +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.FlxState; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.text.FlxText; + +class LatencyState extends FlxState +{ + var offsetText:FlxText; + var noteGrp:FlxTypedGroup; + var strumLine:FlxSprite; + + override function create() + { + FlxG.sound.playMusic('assets/sounds/soundTest' + TitleState.soundExt); + + noteGrp = new FlxTypedGroup(); + add(noteGrp); + + for (i in 0...32) + { + var note:Note = new Note(Conductor.crochet * i, 1); + noteGrp.add(note); + } + + offsetText = new FlxText(); + offsetText.screenCenter(); + add(offsetText); + + strumLine = new FlxSprite(FlxG.width / 2, 100).makeGraphic(FlxG.width, 5); + add(strumLine); + + Conductor.changeBPM(120); + + super.create(); + } + + override function update(elapsed:Float) + { + offsetText.text = "Offset: " + Conductor.offset + "ms"; + + Conductor.songPosition = FlxG.sound.music.time - Conductor.offset; + + var multiply:Float = 1; + + if (FlxG.keys.pressed.SHIFT) + multiply = 10; + + if (FlxG.keys.justPressed.RIGHT) + Conductor.offset += 1 * multiply; + if (FlxG.keys.justPressed.LEFT) + Conductor.offset -= 1 * multiply; + + if (FlxG.keys.justPressed.SPACE) + { + FlxG.sound.music.stop(); + + FlxG.resetState(); + } + + noteGrp.forEach(function(daNote:Note) + { + daNote.y = (strumLine.y - (Conductor.songPosition - daNote.strumTime) * 0.45); + daNote.x = strumLine.x + 30; + + if (daNote.y < strumLine.y) + daNote.kill(); + }); + + super.update(elapsed); + } +} diff --git a/source/Note.hx b/source/Note.hx index 84a952b41..4b14e10b5 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -19,10 +19,13 @@ class Note extends FlxSprite public static var swagWidth:Float = 160 * 0.7; - public function new(strumTime:Float, noteData:Int, prevNote:Note) + public function new(strumTime:Float, noteData:Int, ?prevNote:Note) { super(); + if (prevNote == null) + prevNote = this; + this.prevNote = prevNote; x += 50; diff --git a/source/TitleState.hx b/source/TitleState.hx index 4e8cac6ff..03f93b391 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -18,9 +18,14 @@ import flixel.util.FlxTimer; class TitleState extends FlxTransitionableState { static var initialized:Bool = false; + static public var soundExt:String = ".mp3"; override public function create():Void { + #if (!web) + TitleState.soundExt = '.ogg'; + #end + super.create(); if (!initialized) @@ -64,7 +69,7 @@ class TitleState extends FlxTransitionableState FlxTween.tween(logoBl, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG}); FlxTween.tween(logo, {y: logoBl.y + 50}, 0.6, {ease: FlxEase.quadInOut, type: PINGPONG, startDelay: 0.1}); - FlxG.sound.playMusic('assets/music/title.mp3', 0, false); + FlxG.sound.playMusic('assets/music/title' + TitleState.soundExt, 0, false); FlxG.sound.music.fadeIn(4, 0, 0.7); } @@ -84,7 +89,7 @@ class TitleState extends FlxTransitionableState { FlxG.switchState(new PlayState()); }); - FlxG.sound.play('assets/music/titleShoot.mp3', 0.7); + FlxG.sound.play('assets/music/titleShoot' + TitleState.soundExt, 0.7); } super.update(elapsed);