Commits

André Schnabel committed 1823e23

implemented multitouch

  • Participants
  • Parent commits 4932bab

Comments (0)

Files changed (1)

File src/com/andreschnabel/weltraumsoldat3d/Movement.java

 		if(input.isKeyPressed(Keys.DPAD_CENTER))
 			tryToShoot();
 		
-		boolean resetJoystickPos = true;
+		boolean resetJoystickPos = false;
 		
-		if(input.isTouched()) {
-			/*for(int i=0; i<4; i++) {
-				if(!input.isTouched(i))
-					continue;*/
-				
-			int x = input.getX(/*i*/), y = input.getY(/*i*/);
-			float rfx = scrW / 800.0f, rfy = scrH / 480.0f;  
-
-			if(ctrlScheme == AndroidControlScheme.SCHEME_1) {
-				if (x <= MARGIN)
-					rotateLeft(delta);
-				else if (x >= scrW - MARGIN && y < scrH - 230*rfy)
-					rotateRight(delta);
-
-				Vector3 oldCamPos = cam.position.cpy();
-
-				if (y <= MARGIN)
-					moveForward(delta);
-				else if (y >= scrH - MARGIN)
-					moveBackward(delta);
-
-				checkColl(oldCamPos);
-
-				if (x >= scrWH - MARGIN
-						&& x <= scrWH + MARGIN
-						&& y >= scrHH - MARGIN
-						&& y <= scrHH + MARGIN) {
-					return tryToOpenDoor();
+		if(input.isTouched()) {	
+			int x, y;
+			for(int i=0; i<4; i++) {
+				if(input.isTouched(i)) {
+					x = input.getX(i);
+					y = input.getY(i);
+					processTouch(delta, x, y);
 				}
-
-				if(x >= scrW - 300*rfx && y >= scrH - 230*rfy)
-					tryToShoot();
-			}
-			else if(ctrlScheme == AndroidControlScheme.SCHEME_2) {
-				boolean inJoyRect = joystickRect.containsPoint(x,y);
-
-				if(doorBtnRect.containsPoint(x, y)) { return tryToOpenDoor(); }
-				else if(gunBtnRect.containsPoint(x, y)) tryToShoot();					
-				else if(inJoyRect || draggingJoystick) {						
-					if(inJoyRect) {
-						deltaX = x - (int)(joystickRect.x + joystickRect.w / 2.0f);
-						deltaY = y - (int)(joystickRect.y + joystickRect.h / 2.0f);
-						joystickX = x;
-						joystickY = y;
-					}
-					else {
-						if(x >= 0 && x <= 128) {
-							deltaX = x - (int)(joystickRect.x + joystickRect.w / 2.0f);
-							joystickX = x;
-						}
-						if(y >= scrH - 128 && y <= scrH) {
-							deltaY = y - (int)(joystickRect.y + joystickRect.h / 2.0f);						
-							joystickY = y;
-						}
-					}
-					
-					float 	deltaXs = Math.abs(deltaX) / 50.0f,
-							deltaYs = Math.abs(deltaY) / 50.0f;
-
-					if(deltaX < -PAD_MARGIN) rotateLeft(delta * deltaXs);
-					else if(deltaX > PAD_MARGIN) rotateRight(delta * deltaXs);
-
-					Vector3 oldCamPos = cam.position.cpy();					
-
-					if(deltaY < -PAD_MARGIN) moveForward(delta * deltaYs);
-					else if(deltaY > PAD_MARGIN) moveBackward(delta * deltaYs);
-
-					checkColl(oldCamPos);
-
-					draggingJoystick = true;						
-					resetJoystickPos = false; // don't reset joy stick position
-				}
-			}		
+			}				
 		} else { // !input.isTouched
+			resetJoystickPos = true;
 			draggingJoystick = false;
 		}
 		
 		
 		return false;
 	}
+
+	private void processTouch(final float delta, int x, int y) {
+		float rfx = scrW / 800.0f, rfy = scrH / 480.0f;  
+
+		if(ctrlScheme == AndroidControlScheme.SCHEME_1) {
+			if (x <= MARGIN)
+				rotateLeft(delta);
+			else if (x >= scrW - MARGIN && y < scrH - 230*rfy)
+				rotateRight(delta);
+
+			Vector3 oldCamPos = cam.position.cpy();
+
+			if (y <= MARGIN)
+				moveForward(delta);
+			else if (y >= scrH - MARGIN)
+				moveBackward(delta);
+
+			checkColl(oldCamPos);
+
+			if (x >= scrWH - MARGIN
+					&& x <= scrWH + MARGIN
+					&& y >= scrHH - MARGIN
+					&& y <= scrHH + MARGIN) {
+				tryToOpenDoor();
+			}
+
+			if(x >= scrW - 300*rfx && y >= scrH - 230*rfy)
+				tryToShoot();
+		}
+		else if(ctrlScheme == AndroidControlScheme.SCHEME_2) {
+			boolean inJoyRect = joystickRect.containsPoint(x,y);
+
+			if(doorBtnRect.containsPoint(x, y)) { tryToOpenDoor(); }
+			else if(gunBtnRect.containsPoint(x, y)) { tryToShoot(); }					
+			else if(inJoyRect || draggingJoystick) {						
+				if(inJoyRect) {
+					deltaX = x - (int)(joystickRect.x + joystickRect.w / 2.0f);
+					deltaY = y - (int)(joystickRect.y + joystickRect.h / 2.0f);
+					joystickX = x;
+					joystickY = y;
+				}
+				else {
+					if(x >= 0 && x <= 128) {
+						deltaX = x - (int)(joystickRect.x + joystickRect.w / 2.0f);
+						joystickX = x;
+					}
+					if(y >= scrH - 128 && y <= scrH) {
+						deltaY = y - (int)(joystickRect.y + joystickRect.h / 2.0f);						
+						joystickY = y;
+					}
+				}
+				
+				float 	deltaXs = Math.abs(deltaX) / 50.0f,
+						deltaYs = Math.abs(deltaY) / 50.0f;
+
+				if(deltaX < -PAD_MARGIN) rotateLeft(delta * deltaXs);
+				else if(deltaX > PAD_MARGIN) rotateRight(delta * deltaXs);
+
+				Vector3 oldCamPos = cam.position.cpy();					
+
+				if(deltaY < -PAD_MARGIN) moveForward(delta * deltaYs);
+				else if(deltaY > PAD_MARGIN) moveBackward(delta * deltaYs);
+
+				checkColl(oldCamPos);
+
+				draggingJoystick = true;						
+			}
+		}
+	}
+	
 	public void processMouseLook(final float delta) {
 		if (Gdx.app.getType() == ApplicationType.Android || ANDROID_TEST)
 			return;