From 61ba71d3dbece4cbc912107f889149a01a0d4ef1 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 22 Aug 2021 10:37:06 -0400 Subject: [PATCH] touch controls in progres --- source/Controls.hx | 20 +++++++++++++++++++ source/GameOverSubstate.hx | 10 ++++++++++ source/PlayState.hx | 39 ++++++++++++++++++++++++++++++++++++++ source/TitleState.hx | 6 ++++++ 4 files changed, 75 insertions(+) diff --git a/source/Controls.hx b/source/Controls.hx index 7738ba158..342721780 100644 --- a/source/Controls.hx +++ b/source/Controls.hx @@ -3,12 +3,17 @@ package; import flixel.input.FlxInput; import flixel.input.actions.FlxAction; import flixel.input.actions.FlxActionInput; +import flixel.input.actions.FlxActionInputAnalog.FlxActionInputAnalogClickAndDragMouseMotion; import flixel.input.actions.FlxActionInputDigital; import flixel.input.actions.FlxActionManager; import flixel.input.actions.FlxActionSet; import flixel.input.gamepad.FlxGamepadButton; import flixel.input.gamepad.FlxGamepadInputID; import flixel.input.keyboard.FlxKey; +import flixel.input.mouse.FlxMouseButton.FlxMouseButtonID; +import flixel.ui.FlxVirtualPad; +import flixel.util.FlxColor; +import flixel.util.FlxTimer; /** * Since, in many cases multiple actions should use similar keys, we don't want the @@ -611,8 +616,15 @@ class Controls extends FlxActionSet case None: // nothing case Custom: // nothing } + + trace('added virtual controls!?'); + trace(virutalPad); + + if (FlxG.onMobile) {} } + var virutalPad:FlxVirtualPad; + function removeKeyboard() { for (action in this.digitalActions) @@ -689,6 +701,14 @@ class Controls extends FlxActionSet forEachBound(control, function(action, state) addButtons(action, buttons, state, id)); } + public function touchShit(control:Control, id) + { + forEachBound(control, function(action, state) + { + // action + }); + } + /** * Sets all actions that pertain to the binder to trigger when the supplied keys are used. * If binder is a literal you can inline this diff --git a/source/GameOverSubstate.hx b/source/GameOverSubstate.hx index 2ba6fbe67..7ddb1a0d2 100644 --- a/source/GameOverSubstate.hx +++ b/source/GameOverSubstate.hx @@ -74,6 +74,16 @@ class GameOverSubstate extends MusicBeatSubstate super.update(elapsed); + if (FlxG.onMobile) + { + var touch = FlxG.touches.getFirst(); + if (touch != null) + { + if (touch.overlaps(bf)) + endBullshit(); + } + } + if (controls.ACCEPT) { endBullshit(); diff --git a/source/PlayState.hx b/source/PlayState.hx index 309a3e74a..9304fd9f3 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -36,6 +36,7 @@ import flixel.util.FlxSort; import flixel.util.FlxStringUtil; import flixel.util.FlxTimer; import haxe.Json; +import lime.ui.Haptic; import lime.utils.Assets; import openfl.Lib; import openfl.display.BitmapData; @@ -2656,6 +2657,42 @@ class PlayState extends MusicBeatState controls.NOTE_RIGHT_R ]; + var widHalf = FlxG.width / 2; + var heightHalf = FlxG.height / 2; + + if (FlxG.onMobile) + { + for (touch in FlxG.touches.list) + { + if (touch.justPressed) + { + if (touch.justPressedPosition.x >= widHalf) + { + if (touch.justPressedPosition.y >= heightHalf) + pressArray[3] = true; + else + pressArray[2] = true; + } + else if (touch.justPressedPosition.y >= heightHalf) + pressArray[1] = true; + else + pressArray[0] = true; + } + + if (touch.justPressedPosition.x >= widHalf) + { + if (touch.justPressedPosition.y >= heightHalf) + holdArray[3] = true; + else + holdArray[2] = true; + } + else if (touch.justPressedPosition.y >= heightHalf) + holdArray[1] = true; + else + holdArray[0] = true; + } + } + // HOLDS, check for sustain notes if (holdArray.contains(true) && /*!boyfriend.stunned && */ generatedMusic) { @@ -2669,6 +2706,8 @@ class PlayState extends MusicBeatState // PRESSES, check for note hits if (pressArray.contains(true) && /*!boyfriend.stunned && */ generatedMusic) { + Haptic.vibrate(400, 70); + boyfriend.holdTimer = 0; var possibleNotes:Array = []; // notes that can be hit diff --git a/source/TitleState.hx b/source/TitleState.hx index 00ce021a6..b8cd96027 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -24,6 +24,7 @@ import lime.graphics.Image; import lime.media.AudioContext; import lime.ui.Window; import openfl.Assets; +import openfl.display.BitmapData; import openfl.display.Sprite; import openfl.events.AsyncErrorEvent; import openfl.events.AsyncErrorEvent; @@ -80,6 +81,11 @@ class TitleState extends MusicBeatState override public function create():Void { + FlxG.debugger.addButton(LEFT, new BitmapData(200, 200), function() + { + FlxG.debugger.visible = false; + }); + startedIntro = false; FlxG.game.focusLostFramerate = 60;