From 7a288a43340489501b8db84dbc28c5c8e6338196 Mon Sep 17 00:00:00 2001 From: "v.tarantik" <v.tarantik@gmail.com> Date: Tue, 27 Oct 2015 13:35:11 +0100 Subject: [PATCH] #56 added comments for new PursuitGame features --- .../game/games/pursuit/helper/ArithmeticsHelper.java | 7 ++++++- .../tablexia/util/listener/DragAndRotateActorListener.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/helper/ArithmeticsHelper.java b/core/src/cz/nic/tablexia/game/games/pursuit/helper/ArithmeticsHelper.java index 3166fcc26..8ebc001e4 100644 --- a/core/src/cz/nic/tablexia/game/games/pursuit/helper/ArithmeticsHelper.java +++ b/core/src/cz/nic/tablexia/game/games/pursuit/helper/ArithmeticsHelper.java @@ -9,6 +9,7 @@ import cz.nic.tablexia.util.Point; * Created by Václav TarantĂk on 2.7.15. */ public class ArithmeticsHelper { + private static final float SUFFICIENT_ROTATION_AMOUNT_DEGREES = 15; public static final int CARDINAL_POINTS_COUNT = 4; public static double getAngleBetweenTwoPoints(Point firstPoint, Point secondPoint) { @@ -19,12 +20,16 @@ public class ArithmeticsHelper { return recalcAngle; } + /* + calculates the angle according to rotation direction, if rotation of piece exceeds the + SUFFICIENT_ROTATION_AMOUNT_DEGREES, piece will be rotated to closest right angle after drop + */ public static float getAngleInRotationDirection(float originalRotation, float currentAngle) { float rotationAmount = currentAngle - originalRotation; int numOfNinetyDegreesPassed = (int) (rotationAmount / 90); //original angle added with number of ninety degrees which we rotated piece over float baseAngle = originalRotation + (numOfNinetyDegreesPassed * 90); - if ((Math.abs(rotationAmount) % 90) > 15) { + if ((Math.abs(rotationAmount) % 90) > SUFFICIENT_ROTATION_AMOUNT_DEGREES) { baseAngle+= (getRotationDirection(originalRotation, currentAngle) * 90); } return baseAngle; diff --git a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java index d91d21fad..c07144f8b 100644 --- a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java +++ b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java @@ -112,13 +112,16 @@ public class DragAndRotateActorListener extends InputListener { public void touchUp(InputEvent event, final float x, final float y, int pointer, int button) { if (button != 1) { if (draggedActor != null && !performingAction) { + //storing original fingers positions and deciding which finger was released boolean draggingFingerLifted = ((Integer) (activePointers.keySet().toArray()[0]) == pointer); boolean rotatingFingerLifted = false; if (activePointers.size() > 1) { rotatingFingerLifted = (Integer) activePointers.keySet().toArray()[1] == pointer; } + //removing lifted finger pointer after storing its position activePointers.remove(pointer); if (activePointers.size() == 0) { + //if user removed all fingers before animation finished, piece is stopped and animated back to its original position if (!isPieceAnimationDone()) { pieceTranslationAction.interrupt(); Point pieceOriginalPosition = ((Grid) parentActor).getPieceGridPositionInPixels(((PuzzlePiece) draggedActor).getActualPosition()); -- GitLab