From 65036334d2108d6a962e397dd2b708e3d4ca0354 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Fri, 9 Oct 2020 00:29:00 -0700 Subject: [PATCH] baby shit controller support --- source/GameOverState.hx | 13 +++++- source/PlayState.hx | 89 +++++++++++++++++++++++++++++++++++++++++ source/TitleState.hx | 13 +++++- 3 files changed, 113 insertions(+), 2 deletions(-) diff --git a/source/GameOverState.hx b/source/GameOverState.hx index a7acade61..d3de48311 100644 --- a/source/GameOverState.hx +++ b/source/GameOverState.hx @@ -4,6 +4,7 @@ import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.transition.FlxTransitionableState; import flixel.graphics.frames.FlxAtlasFrames; +import flixel.input.gamepad.FlxGamepad; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; @@ -37,7 +38,17 @@ class GameOverState extends FlxTransitionableState override function update(elapsed:Float) { - if (FlxG.keys.justPressed.ANY && !fading) + var pressed:Bool = FlxG.keys.justPressed.ANY; + + var gamepad:FlxGamepad = FlxG.gamepads.lastActive; + + if (gamepad != null) + { + if (gamepad.justPressed.ANY) + pressed = true; + } + + if (pressed && !fading) { fading = true; FlxG.sound.music.fadeOut(0.5, 0, function(twn:FlxTween) diff --git a/source/PlayState.hx b/source/PlayState.hx index 684b58c09..a05d63571 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -686,6 +686,70 @@ class PlayState extends FlxTransitionableState var downR = FlxG.keys.anyJustReleased([S, DOWN]); var leftR = FlxG.keys.anyJustReleased([A, LEFT]); + var gamepad = FlxG.gamepads.lastActive; + if (gamepad != null) + { + if (gamepad.anyPressed(["DPAD_LEFT", "LEFT_STICK_DIGITAL_LEFT", X])) + { + left = true; + } + + if (gamepad.anyPressed(["DPAD_RIGHT", "LEFT_STICK_DIGITAL_RIGHT", B])) + { + right = true; + } + + if (gamepad.anyPressed(['DPAD_UP', "LEFT_STICK_DIGITAL_UP", Y])) + { + up = true; + } + + if (gamepad.anyPressed(["DPAD_DOWN", "LEFT_STICK_DIGITAL_DOWN", A])) + { + down = true; + } + + if (gamepad.anyJustPressed(["DPAD_LEFT", "LEFT_STICK_DIGITAL_LEFT", X])) + { + leftP = true; + } + + if (gamepad.anyJustPressed(["DPAD_RIGHT", "LEFT_STICK_DIGITAL_RIGHT", B])) + { + rightP = true; + } + + if (gamepad.anyJustPressed(['DPAD_UP', "LEFT_STICK_DIGITAL_UP", Y])) + { + upP = true; + } + + if (gamepad.anyJustPressed(["DPAD_DOWN", "LEFT_STICK_DIGITAL_DOWN", A])) + { + downP = true; + } + + if (gamepad.anyJustReleased(["DPAD_LEFT", "LEFT_STICK_DIGITAL_LEFT", X])) + { + leftR = true; + } + + if (gamepad.anyJustReleased(["DPAD_RIGHT", "LEFT_STICK_DIGITAL_RIGHT", B])) + { + rightR = true; + } + + if (gamepad.anyJustReleased(['DPAD_UP', "LEFT_STICK_DIGITAL_UP", Y])) + { + upR = true; + } + + if (gamepad.anyJustReleased(["DPAD_DOWN", "LEFT_STICK_DIGITAL_DOWN", A])) + { + downR = true; + } + } + FlxG.watch.addQuick('asdfa', upP); if ((upP || rightP || downP || leftP) && !boyfriend.stunned && generatedMusic) { @@ -835,11 +899,36 @@ class PlayState extends FlxTransitionableState function badNoteCheck() { // just double pasting this shit cuz fuk u + // REDO THIS SYSTEM! var upP = FlxG.keys.anyJustPressed([W, UP]); var rightP = FlxG.keys.anyJustPressed([D, RIGHT]); var downP = FlxG.keys.anyJustPressed([S, DOWN]); var leftP = FlxG.keys.anyJustPressed([A, LEFT]); + var gamepad = FlxG.gamepads.lastActive; + if (gamepad != null) + { + if (gamepad.anyJustPressed(["DPAD_LEFT", "LEFT_STICK_DIGITAL_LEFT", X])) + { + leftP = true; + } + + if (gamepad.anyJustPressed(["DPAD_RIGHT", "LEFT_STICK_DIGITAL_RIGHT", B])) + { + rightP = true; + } + + if (gamepad.anyJustPressed(['DPAD_UP', "LEFT_STICK_DIGITAL_UP", Y])) + { + upP = true; + } + + if (gamepad.anyJustPressed(["DPAD_DOWN", "LEFT_STICK_DIGITAL_DOWN", A])) + { + downP = true; + } + } + if (leftP) noteMiss(4); if (upP) diff --git a/source/TitleState.hx b/source/TitleState.hx index 03f93b391..7be9ca07f 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -8,6 +8,7 @@ import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond; import flixel.addons.transition.FlxTransitionableState; import flixel.addons.transition.TransitionData; import flixel.graphics.FlxGraphic; +import flixel.input.gamepad.FlxGamepad; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.tweens.FlxEase; @@ -78,7 +79,17 @@ class TitleState extends FlxTransitionableState override function update(elapsed:Float) { - if (FlxG.keys.justPressed.ENTER && !transitioning) + var pressedEnter:Bool = FlxG.keys.justPressed.ENTER; + + var gamepad:FlxGamepad = FlxG.gamepads.lastActive; + + if (gamepad != null) + { + if (gamepad.justPressed.START) + pressedEnter = true; + } + + if (pressedEnter && !transitioning) { FlxG.camera.flash(FlxColor.WHITE, 1);