From c4fdb3295a2cf2495b0f3cc1fa6db25398a86329 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 4 Oct 2020 01:38:21 -0700 Subject: [PATCH] notes in da house --- source/Note.hx | 19 +++++--- source/PlayState.hx | 106 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 115 insertions(+), 10 deletions(-) diff --git a/source/Note.hx b/source/Note.hx index cc29980e0..d8420dc81 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -17,34 +17,41 @@ class Note extends FlxSprite public var noteScore:Float = 1; + public static var swagWidth:Float = 160 * 0.7; + public function new(strumTime:Float, noteData:Int) { super(); - x += 100; + x += 50; this.strumTime = strumTime; this.noteData = noteData; var tex = FlxAtlasFrames.fromSparrow(AssetPaths.NOTE_assets__png, AssetPaths.NOTE_assets__xml); frames = tex; + animation.addByPrefix('greenScroll', 'green0'); + animation.addByPrefix('redScroll', 'red0'); + animation.addByPrefix('blueScroll', 'blue0'); + animation.addByPrefix('purpleScroll', 'purple0'); - var swagWidth:Float = 55; + setGraphicSize(Std.int(width * 0.7)); + updateHitbox(); switch (Math.abs(noteData)) { case 1: x += swagWidth * 2; - color = FlxColor.GREEN; + animation.play('greenScroll'); case 2: x += swagWidth * 3; - color = FlxColor.RED; + animation.play('redScroll'); case 3: x += swagWidth * 1; - color = FlxColor.BLUE; + animation.play('blueScroll'); case 4: x += swagWidth * 0; - color = FlxColor.PURPLE; + animation.play('purpleScroll'); } if (noteData < 0) diff --git a/source/PlayState.hx b/source/PlayState.hx index b02666a67..bbfda0a5e 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -4,6 +4,7 @@ import flixel.FlxG; import flixel.FlxObject; import flixel.FlxSprite; import flixel.FlxState; +import flixel.graphics.atlas.FlxAtlas; import flixel.graphics.frames.FlxAtlasFrames; import flixel.group.FlxGroup.FlxTypedGroup; import flixel.system.FlxSound; @@ -42,6 +43,8 @@ class PlayState extends FlxState private var sectionScores:Array = [[], []]; private var camFollow:FlxObject; + private var strumLineNotes:FlxTypedGroup; + private var playerStrums:FlxTypedGroup; override public function create() { @@ -68,13 +71,19 @@ class PlayState extends FlxState boyfriend.animation.play('idle'); add(boyfriend); + strumLine = new FlxSprite(0, 50).makeGraphic(FlxG.width, 10); + strumLine.scrollFactor.set(); + + strumLineNotes = new FlxTypedGroup(); + add(strumLineNotes); + + playerStrums = new FlxTypedGroup(); + generateSong('assets/data/bopeebo/bopeebo.json'); canHitText = new FlxText(10, 10, 0, "weed"); - strumLine = new FlxSprite(0, 50).makeGraphic(FlxG.width, 10); - strumLine.scrollFactor.set(); - add(strumLine); + // add(strumLine); camFollow = new FlxObject(0, 0, 1, 1); add(camFollow); @@ -85,6 +94,8 @@ class PlayState extends FlxState FlxG.worldBounds.set(0, 0, FlxG.width, FlxG.height); + FlxG.fixedTimestep = false; + super.create(); } @@ -94,6 +105,9 @@ class PlayState extends FlxState { // FlxG.log.add(ChartParser.parse()); + generateStaticArrows(0); + generateStaticArrows(1); + var songData = Json.parse(Assets.getText(dataPath)); FlxG.sound.playMusic("assets/music/" + songData.song + "_Inst.mp3"); @@ -165,6 +179,58 @@ class PlayState extends FlxState } } + private function generateStaticArrows(player:Int):Void + { + for (i in 0...4) + { + FlxG.log.add(i); + var babyArrow:FlxSprite = new FlxSprite(0, strumLine.y); + var arrTex = FlxAtlasFrames.fromSparrow(AssetPaths.NOTE_assets__png, AssetPaths.NOTE_assets__xml); + babyArrow.frames = arrTex; + babyArrow.animation.addByPrefix('green', 'arrowUP'); + babyArrow.animation.addByPrefix('blue', 'arrowDOWN'); + babyArrow.animation.addByPrefix('purple', 'arrowLEFT'); + babyArrow.animation.addByPrefix('red', 'arrowRIGHT'); + + babyArrow.scrollFactor.set(); + babyArrow.setGraphicSize(Std.int(babyArrow.width * 0.7)); + babyArrow.updateHitbox(); + + babyArrow.ID = i + 1; + + if (player == 1) + { + playerStrums.add(babyArrow); + } + + switch (Math.abs(i + 1)) + { + case 1: + babyArrow.x += Note.swagWidth * 2; + babyArrow.animation.addByPrefix('static', 'arrowUP'); + babyArrow.animation.addByPrefix('pressed', 'up press', 24, false); + case 2: + babyArrow.x += Note.swagWidth * 3; + babyArrow.animation.addByPrefix('static', 'arrowRIGHT'); + babyArrow.animation.addByPrefix('pressed', 'right press', 24, false); + case 3: + babyArrow.x += Note.swagWidth * 1; + babyArrow.animation.addByPrefix('static', 'arrowDOWN'); + babyArrow.animation.addByPrefix('pressed', 'down press', 24, false); + case 4: + babyArrow.x += Note.swagWidth * 0; + babyArrow.animation.addByPrefix('static', 'arrowLEFT'); + babyArrow.animation.addByPrefix('pressed', 'left press', 24, false); + } + + babyArrow.animation.play('static'); + babyArrow.x += 50; + babyArrow.x += ((FlxG.width / 2) * player); + + strumLineNotes.add(babyArrow); + } + } + var sectionScored:Bool = false; override public function update(elapsed:Float) @@ -242,7 +308,7 @@ class PlayState extends FlxState daNote.kill(); } - daNote.y = (strumLine.y + 5 - (daNote.height / 2)) - ((Conductor.songPosition - daNote.strumTime) * 0.4); + daNote.y = (strumLine.y - (Conductor.songPosition - daNote.strumTime) * 0.45); }); keyShit(); @@ -283,6 +349,38 @@ class PlayState extends FlxState var downP = FlxG.keys.anyJustPressed([S, DOWN]); var leftP = FlxG.keys.anyJustPressed([A, LEFT]); + var upR = FlxG.keys.anyJustReleased([W, UP]); + var rightR = FlxG.keys.anyJustReleased([D, RIGHT]); + var downR = FlxG.keys.anyJustReleased([S, DOWN]); + var leftR = FlxG.keys.anyJustReleased([A, LEFT]); + + playerStrums.forEach(function(spr:FlxSprite) + { + switch (spr.ID) + { + case 1: + if (upP) + spr.animation.play('pressed'); + if (upR) + spr.animation.play('static'); + case 2: + if (rightP) + spr.animation.play('pressed'); + if (rightR) + spr.animation.play('static'); + case 3: + if (downP) + spr.animation.play('pressed'); + if (downR) + spr.animation.play('static'); + case 4: + if (leftP) + spr.animation.play('pressed'); + if (leftR) + spr.animation.play('static'); + } + }); + if (up || right || down || left) { notes.forEach(function(daNote:Note)