diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-11-14 20:54:51 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-11-15 00:27:11 +0300 |
commit | 4d5842888ebd8a8da3fcbc94904116544f2e7de6 (patch) | |
tree | cb9e03d39aad151b0308d1c17d3385a8197a5f61 /src/touchactions.cpp | |
parent | 13642a6cddd8657ec84a2bfa94c6ac7d34545dba (diff) | |
download | mv-4d5842888ebd8a8da3fcbc94904116544f2e7de6.tar.gz mv-4d5842888ebd8a8da3fcbc94904116544f2e7de6.tar.bz2 mv-4d5842888ebd8a8da3fcbc94904116544f2e7de6.tar.xz mv-4d5842888ebd8a8da3fcbc94904116544f2e7de6.zip |
Improve screen joystick handling.
Diffstat (limited to 'src/touchactions.cpp')
-rw-r--r-- | src/touchactions.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/touchactions.cpp b/src/touchactions.cpp index e201a7efb..20d008eda 100644 --- a/src/touchactions.cpp +++ b/src/touchactions.cpp @@ -51,16 +51,40 @@ static void moveChar(int x, int y) if (!game) return; - static const int lim = 10; + static const int lim1 = 10; + static const int diff = 20; + + // set center at (0,0) x -= 50; y -= 50; - if (x > lim) + // some magic for checking at what sector was click + if (abs(x) < lim1) + x = 0; + + if (abs(y) < lim1) + y = 0; + + const int x2 = abs(x); + const int y2 = abs(y); + if (x2 > y2) + { + if (y2 && x2 * 10 / y2 > diff) + y = 0; + } + else + { + if (x2 && y2 * 10 / x2 > diff) + x = 0; + } + + // detecting direction + if (x > 0) { touchManager.setActionActive(Input::KEY_MOVE_LEFT, false); touchManager.setActionActive(Input::KEY_MOVE_RIGHT, true); } - else if (x < -lim) + else if (x < 0) { touchManager.setActionActive(Input::KEY_MOVE_LEFT, true); touchManager.setActionActive(Input::KEY_MOVE_RIGHT, false); @@ -70,12 +94,12 @@ static void moveChar(int x, int y) touchManager.setActionActive(Input::KEY_MOVE_LEFT, false); touchManager.setActionActive(Input::KEY_MOVE_RIGHT, false); } - if (y > lim) + if (y > 0) { touchManager.setActionActive(Input::KEY_MOVE_DOWN, true); touchManager.setActionActive(Input::KEY_MOVE_UP, false); } - else if (y < -lim) + else if (y < 0) { touchManager.setActionActive(Input::KEY_MOVE_DOWN, false); touchManager.setActionActive(Input::KEY_MOVE_UP, true); |