commit 38802b333c65c25d41a0f62364d12718c0d99d6e Author: Cameron Taylor Date: Fri Oct 2 23:50:15 2020 -0700 INIT COMMIT diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..5f82e547e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +export/ +.vscode/ \ No newline at end of file diff --git a/Project.xml b/Project.xml new file mode 100644 index 000000000..12f749f18 --- /dev/null +++ b/Project.xml @@ -0,0 +1,82 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hxformat.json b/hxformat.json new file mode 100644 index 000000000..66cb3869e --- /dev/null +++ b/hxformat.json @@ -0,0 +1,15 @@ +{ + "lineEnds": { + "leftCurly": "both", + "rightCurly": "both", + "objectLiteralCurly": { + "leftCurly": "after" + } + }, + "sameLine": { + "ifElse": "next", + "doWhile": "next", + "tryBody": "next", + "tryCatch": "next" + } +} diff --git a/source/AssetPaths.hx b/source/AssetPaths.hx new file mode 100644 index 000000000..db7ef4445 --- /dev/null +++ b/source/AssetPaths.hx @@ -0,0 +1,4 @@ +package; + +@:build(flixel.system.FlxAssets.buildFileReferences("assets", true)) +class AssetPaths {} diff --git a/source/BeatBattle.hx b/source/BeatBattle.hx new file mode 100644 index 000000000..e69de29bb diff --git a/source/Conductor.hx b/source/Conductor.hx new file mode 100644 index 000000000..808d10804 --- /dev/null +++ b/source/Conductor.hx @@ -0,0 +1,16 @@ +package; + +/** + * ... + * @author + */ +class Conductor +{ + public static var bpm:Int = 100; + public static var crochet:Float = ((60 / bpm) * 1000); // beats in milliseconds + public static var stepCrochet:Float = crochet / 4; // steps in milliseconds + public static var songPosition:Float; + public static var offset:Float = 0; + + public function new() {} +} diff --git a/source/Main.hx b/source/Main.hx new file mode 100644 index 000000000..efa0e2d46 --- /dev/null +++ b/source/Main.hx @@ -0,0 +1,13 @@ +package; + +import flixel.FlxGame; +import openfl.display.Sprite; + +class Main extends Sprite +{ + public function new() + { + super(); + addChild(new FlxGame(0, 0, PlayState)); + } +} diff --git a/source/Note.hx b/source/Note.hx new file mode 100644 index 000000000..c073c9e50 --- /dev/null +++ b/source/Note.hx @@ -0,0 +1,37 @@ +package; + +import flixel.FlxSprite; +import flixel.util.FlxColor; + +class Note extends FlxSprite +{ + public var strumTime:Float = 0; + + public var mustPress:Bool = false; + public var noteData:Int = 0; + + public function new(strumTime:Float, noteData:Int) + { + super(); + + this.strumTime = strumTime; + this.noteData = noteData; + + makeGraphic(50, 50); + + switch (Math.abs(noteData)) + { + case 1: + color = FlxColor.GREEN; + case 2: + color = FlxColor.RED; + case 3: + color = FlxColor.BLUE; + case 4: + color = FlxColor.PURPLE; + } + + if (noteData < 0) + alpha = 0.6; + } +} diff --git a/source/PlayState.hx b/source/PlayState.hx new file mode 100644 index 000000000..d68ff2539 --- /dev/null +++ b/source/PlayState.hx @@ -0,0 +1,162 @@ +package; + +import flixel.FlxG; +import flixel.FlxSprite; +import flixel.FlxState; +import flixel.group.FlxGroup.FlxTypedGroup; +import flixel.system.FlxSound; +import flixel.text.FlxText; +import haxe.Json; +import lime.utils.Assets; + +class PlayState extends FlxState +{ + private var lastBeat:Float = 0; + private var lastStep:Float = 0; + private var safeFrames:Int = 5; + private var safeZoneOffset:Float = 0; // is calculated in create(), is safeFrames in milliseconds + private var canHit:Bool = false; + + private var canHitText:FlxText; + + private var dad:FlxSprite; + private var boyfriend:FlxSprite; + + private var notes:FlxTypedGroup; + + private var strumLine:FlxSprite; + + override public function create() + { + dad = new FlxSprite(100, 100).loadGraphic(AssetPaths.DADDY_DEAREST__png); + add(dad); + + boyfriend = new FlxSprite(470, 100).loadGraphic(AssetPaths.BOYFRIEND__png); + add(boyfriend); + + generateSong('assets/data/bopeebo.json'); + + safeZoneOffset = (safeFrames / 60) * 1000; + + canHitText = new FlxText(10, 10, 0, "weed"); + + strumLine = new FlxSprite(0, 50).makeGraphic(FlxG.width, 10); + add(strumLine); + + super.create(); + } + + var debugNum:Int = 0; + + private function generateSong(dataPath:String):Void + { + var songData = Json.parse(Assets.getText(dataPath)); + FlxG.sound.playMusic("assets/music/" + songData.song + ".mp3"); + + notes = new FlxTypedGroup(); + add(notes); + + var noteData:Array = songData.data; + + var playerCounter:Int = 0; + + while (playerCounter < 2) + { + var daBeats:Int = 0; // Not exactly representative of 'daBeats' lol, just how much it has looped + for (section in noteData) + { + var dumbassSection:Array = section; + + var daStep:Int = 0; + + for (songNotes in dumbassSection) + { + if (songNotes != 0) + { + var daStrumTime:Float = (daStep * Conductor.stepCrochet) + ((Conductor.crochet * 4) * playerCounter); + + var swagNote:Note = new Note(daStrumTime, songNotes); + + var swagWidth:Float = 40; + + swagNote.x += (swagWidth * (Math.abs(songNotes))) + ((FlxG.width / 2) * playerCounter); + + if (playerCounter == 2) // is the player + { + swagNote.mustPress = true; + } + + notes.add(swagNote); + } + + daStep += 1; + } + + daBeats += 1; + } + + playerCounter += 1; + } + } + + override public function update(elapsed:Float) + { + super.update(elapsed); + + Conductor.songPosition = FlxG.sound.music.time; + + if (dad.scale.x > 1) + { + dad.setGraphicSize(Std.int(dad.width - (FlxG.elapsed * 2))); + } + + canHitText.visible = canHit; + canHitText.text = 'WWEED' + debugNum; + + if (canHit) + { + debugNum += 1; + } + else + debugNum = 0; + + everyBeat(); + everyStep(); + + notes.forEach(function(daNote:Note) + { + daNote.y = (strumLine.y + 5 - (daNote.height / 2)) - ((Conductor.songPosition - daNote.strumTime) * 0.4); + }); + } + + function everyBeat():Void + { + if (Conductor.songPosition > lastBeat + Conductor.crochet - safeZoneOffset || Conductor.songPosition < lastBeat + safeZoneOffset) + { + if (Conductor.songPosition > lastBeat + Conductor.crochet) + { + lastBeat += Conductor.crochet; + canHitText.text += "\nWEED\nWEED"; + + dad.setGraphicSize(Std.int(dad.width * 1.1)); + } + } + } + + function everyStep() + { + if (Conductor.songPosition > lastStep + Conductor.stepCrochet - safeZoneOffset + || Conductor.songPosition < lastStep + safeZoneOffset) + { + canHit = true; + + if (Conductor.songPosition > lastStep + Conductor.stepCrochet) + { + lastStep += Conductor.stepCrochet; + canHitText.text += "\nWEED\nWEED"; + } + } + else + canHit = false; + } +}