@@ -75,9 +75,6 @@ public abstract class GameStage extends Stage {
7575 private float animationTimeout = 0 ;
7676 public static float maximumScrollDistance = 1.5f ;
7777 public static float minimumScrollDistance = 0.3f ;
78- private final Vector2 keyboardInput = new Vector2 ();
79- private final Vector2 controllerInput = new Vector2 ();
80- private final Vector2 touchInput = new Vector2 ();
8178
8279 private String extraAnnouncement = "" ;
8380
@@ -251,11 +248,16 @@ public void showDeckAwardDialog(String message, Deck deck, Runnable runnable) {
251248 showDialog ();
252249 }
253250
251+
254252 public boolean axisMoved (Controller controller , int axisIndex , float value ) {
255253 if (MapStage .getInstance ().isDialogOnlyInput () || isPaused ()) {
256254 return true ;
257255 }
258- controllerInput .set (controller .getAxis (0 ), -controller .getAxis (1 ));
256+ player .getMovementDirection ().x = controller .getAxis (0 );
257+ player .getMovementDirection ().y = -controller .getAxis (1 );
258+ if (player .getMovementDirection ().len () < 0.2 ) {
259+ player .stop ();
260+ }
259261 return true ;
260262 }
261263
@@ -266,6 +268,7 @@ enum PlayerModification {
266268
267269 }
268270
271+
269272 HashMap <PlayerModification , Float > currentModifications = new HashMap <>();
270273
271274 public void modifyPlayer (PlayerModification mod , float value ) {
@@ -357,7 +360,6 @@ public final void act(float delta) {
357360 animationTimeout -= delta ;
358361 return ;
359362 }
360-
361363 Array <PlayerModification > modsToRemove = new Array <>();
362364 for (Map .Entry <PlayerModification , Float > mod : currentModifications .entrySet ()) {
363365 mod .setValue (mod .getValue () - delta );
@@ -369,66 +371,28 @@ public final void act(float delta) {
369371 onRemoveEffect (mod );
370372 }
371373
372- if (onEndAction != null ) {
373- onEndAction .run ();
374- onEndAction = null ;
374+ if (isPaused ()) {
375+ return ;
375376 }
376377
377- if (isPaused () || isDialogOnlyInput () || Forge .advFreezePlayerControls ) {
378- keyboardInput .setZero ();
379- controllerInput .setZero ();
380- touchInput .setZero ();
381- player .getMovementDirection ().setZero ();
382- player .stop ();
383- } else {
384- keyboardInput .setZero ();
385- if (KeyBinding .Left .isPressed ()) {
386- keyboardInput .x -= 1 ;
387- }
388-
389- if (KeyBinding .Right .isPressed ()) {
390- keyboardInput .x += 1 ;
391- }
392-
393- if (KeyBinding .Up .isPressed ()) {
394- keyboardInput .y += 1 ;
395- }
396378
397- if (KeyBinding .Down .isPressed ()) {
398- keyboardInput .y -= 1 ;
399- }
379+ if (onEndAction != null ) {
400380
401- // Input priority: touch > controller > keyboard
402- Vector2 dir = new Vector2 ();
403- if (touchX >= 0 && touchInput .len () > 0.2f ) {
404- dir .set (touchInput );
381+ onEndAction .run ();
382+ onEndAction = null ;
383+ }
405384
406- } else if (controllerInput .len () > 0.2f ) {
407- dir .set (controllerInput );
385+ if (touchX >= 0 ) {
386+ Vector2 target = this .screenToStageCoordinates (new Vector2 (touchX , touchY ));
387+ target .x -= player .getWidth () / 2f ;
388+ Vector2 diff = target .sub (player .pos ());
408389
409- } else {
410- dir .set (keyboardInput );
411- }
412- if (dir .len () < 0.01f ) {
390+ if (diff .len () < 2 ) {
391+ diff .setZero ();
413392 player .stop ();
414- } else {
415- player .getMovementDirection ().set (dir );
416- }
417-
418- if (touchX >= 0 ) {
419- Vector2 target = this .screenToStageCoordinates (new Vector2 (touchX , touchY ));
420- target .x -= player .getWidth () / 2f ;
421- Vector2 diff = target .sub (player .pos ());
422-
423- if (diff .len () < 2 ) {
424- touchInput .setZero ();
425- player .stop ();
426- } else {
427- touchInput .set (diff );
428- }
429393 }
394+ player .setMovementDirection (diff );
430395 }
431-
432396 camera .position .x = Math .min (Math .max (Scene .getIntendedWidth () / 2f , player .pos ().x ), getViewport ().getWorldWidth () - Scene .getIntendedWidth () / 2f );
433397 camera .position .y = Math .min (Math .max (Scene .getIntendedHeight () / 2f , player .pos ().y ), getViewport ().getWorldHeight () - Scene .getIntendedHeight () / 2f );
434398
@@ -451,22 +415,23 @@ private void onRemoveEffect(PlayerModification mod) {
451415
452416 abstract protected void onActing (float delta );
453417
418+
454419 @ Override
455420 public boolean keyDown (int keycode ) {
456421 super .keyDown (keycode );
457422 if (isPaused ())
458423 return true ;
459424 if (KeyBinding .Left .isPressed (keycode )) {
460- keyboardInput .x = -1 ;
425+ player . getMovementDirection () .x = -1 ;
461426 }
462427 if (KeyBinding .Right .isPressed (keycode )) {
463- keyboardInput .x = +1 ;
428+ player . getMovementDirection () .x = +1 ;
464429 }
465430 if (KeyBinding .Up .isPressed (keycode )) {
466- keyboardInput .y = +1 ;
431+ player . getMovementDirection () .y = +1 ;
467432 }
468433 if (KeyBinding .Down .isPressed (keycode )) {
469- keyboardInput .y = -1 ;
434+ player . getMovementDirection () .y = -1 ;
470435 }
471436 if (keycode == Input .Keys .F5 )//todo config
472437 {
@@ -577,9 +542,6 @@ public boolean touchDown(int screenX, int screenY, int pointer, int button) {
577542 public void stop () {
578543 WorldStage .getInstance ().getPlayerSprite ().setMovementDirection (Vector2 .Zero );
579544 MapStage .getInstance ().getPlayerSprite ().setMovementDirection (Vector2 .Zero );
580- touchInput .setZero ();
581- keyboardInput .setZero ();
582- controllerInput .setZero ();
583545 touchX = -1 ;
584546 touchY = -1 ;
585547 player .stop ();
0 commit comments