Permalink
Browse files

change movement to analog

  • Loading branch information...
1 parent f9222ec commit e926349ec133f1c32ef06be73d595610b011bd2b @jonasb jonasb committed Feb 16, 2012
@@ -115,8 +115,8 @@ public void run() {
buffer.put((byte) 0); //padding
buffer.putInt(0); //mx
buffer.putInt(0); //my
- buffer.putInt(0); //dx
- buffer.putInt(0); //dy
+ buffer.putInt((int) (mNavigator.moveX * 128)); //dx -1..1 -> -127..127
+ buffer.putInt((int) (mNavigator.moveY * 128)); //dy -1..1 -> -127..127
buffer.put(kb);
buffer.put((byte) 0); //padding
buffer.put((byte) 0); //padding
@@ -39,14 +39,20 @@ public boolean onTouchEvent(MotionEvent event) {
final float x = event.getX();
final float y = event.getY();
+
+ mNavigator.moveX = (x - width / 2) / (width / 2);
+ mNavigator.moveY = (y - height / 2) / (height / 2);
+ /*
+ // wasd
mNavigator.left = (x < width / 3);
mNavigator.right = (x > width * 2 / 3);
mNavigator.up = (y < height / 3);
mNavigator.down = (y > height * 2 / 3);
+ */
return true;
case ACTION_CANCEL:
case ACTION_UP:
- mNavigator.up = mNavigator.down = mNavigator.left = mNavigator.right = false;
+ mNavigator.reset();
return true;
default:
return false;
@@ -5,4 +5,12 @@
public boolean right = false;
public boolean up = false;
public boolean down = false;
+
+ public float moveX = 0; // -1.0..1.0
+ public float moveY = 0; // -1.0..1.0
+
+ public void reset() {
+ up = down = left = right = false;
+ moveX = moveY = 0;
+ }
}

0 comments on commit e926349

Please sign in to comment.