From d219cd2e3d86d1e66f2446b859e771d2db2b2732 Mon Sep 17 00:00:00 2001
From: "v.tarantik" <v.tarantik@gmail.com>
Date: Thu, 13 Aug 2015 11:55:19 +0200
Subject: [PATCH] #32 removed car for testing purposes, German and Slovak texts
 for Pursuit

---
 .../nightwatch/night_watch_cs.properties~     |  8 -----
 .../text/game/pursuit/pursuit_cs.properties   |  8 +++++
 .../text/game/pursuit/pursuit_de.properties   |  5 +++
 .../text/game/pursuit/pursuit_sk.properties   |  5 +++
 .../game/games/pursuit/PursuitGame.java       | 33 +++++++++++++++----
 .../pursuit/helper/ArithmeticsHelper.java     |  6 ++--
 .../pursuit/listener/VehicleDragListener.java | 12 +++++--
 .../listener/DragAndRotateActorListener.java  |  2 +-
 8 files changed, 57 insertions(+), 22 deletions(-)
 delete mode 100644 android/assets/text/game/nightwatch/night_watch_cs.properties~
 create mode 100644 android/assets/text/game/pursuit/pursuit_cs.properties
 create mode 100644 android/assets/text/game/pursuit/pursuit_de.properties
 create mode 100644 android/assets/text/game/pursuit/pursuit_sk.properties

diff --git a/android/assets/text/game/nightwatch/night_watch_cs.properties~ b/android/assets/text/game/nightwatch/night_watch_cs.properties~
deleted file mode 100644
index 069847691..000000000
--- a/android/assets/text/game/nightwatch/night_watch_cs.properties~
+++ /dev/null
@@ -1,8 +0,0 @@
-<string name="game_nocnisledovani_btncontinue_text">Hotovo</string>
-<string name="victory_text_window_mistakes">Chybně označená okna: </string>
-<string name="victory_text_time_mistakes">ChybnÄ› nastavenĂ˝ ÄŤas: </string>
-<string name="game_nocnisledovani_loadingtext">Dávej pozor, která okna se po setmění rozsvítí  a v kolik hodin.\nPo rozednění nastav na hodinách čas a označ okna, která byla rozsvícená.</string>
-<string name="game_nocnisledovani_victory_text_0">To vypadá, že tady někdo usnul na hlídce.</string>
-<string name="game_nocnisledovani_victory_text_1">U soudu by tyhle důkazy neuspěly. To ale neznamená, že se nemůže zadařit příště!</string>
-<string name="game_nocnisledovani_victory_text_2">Tohle nebylo vůbec špatné! Stačilo málo a důkazy by byly neprůstřelné.</string>
-<string name="game_nocnisledovani_victory_text_3">Před tebou se musí obávat i Měsíc páchat nepravosti.</string>
diff --git a/android/assets/text/game/pursuit/pursuit_cs.properties b/android/assets/text/game/pursuit/pursuit_cs.properties
new file mode 100644
index 000000000..2ed959e6d
--- /dev/null
+++ b/android/assets/text/game/pursuit/pursuit_cs.properties
@@ -0,0 +1,8 @@
+game_pronasledovani_loadingtext=Sestav mapu přemisťováním a otáčením jednotlivých dílků.
+game_pronasledovani_victorytext_threestars=Počkat si na lupiče v jejich doupěti, tak to je povedený kousek!
+game_pronasledovani_victorytext_twostars=Začínající dektiv by se za takový výkon nemusel stydět!
+game_pronasledovani_victorytext_onestar=To bylo teda na poslední chvíli! Zapracuj na sobě ještě.
+game_pronasledovani_victorytext_gameover=Lupiči už si rozdělují kořist a ty ještě skládáš. To bude chtít ještě trénink!
+
+
+
diff --git a/android/assets/text/game/pursuit/pursuit_de.properties b/android/assets/text/game/pursuit/pursuit_de.properties
new file mode 100644
index 000000000..2afd62aee
--- /dev/null
+++ b/android/assets/text/game/pursuit/pursuit_de.properties
@@ -0,0 +1,5 @@
+game_pronasledovani_loadingtext=Stelle die Karte zusammen, indem du einzelne Teile verschiebst und drehst.
+game_pronasledovani_victorytext_threestars=Auf die Einbrecher in ihrem Unterschlupf warten, das ist ein MeisterstĂĽck!
+game_pronasledovani_victorytext_twostars=Ein angehender Detektiv muss sich für eine solche Leistung nicht schämen!
+game_pronasledovani_victorytext_onestar=Das war aber in letzter Sekunde! Du musst noch an dir arbeiten.
+game_pronasledovani_victorytext_gameover=Die Einbrecher teilen die Beute auf und du legst noch die Karte zusammen. Da ist noch Training nötig!
diff --git a/android/assets/text/game/pursuit/pursuit_sk.properties b/android/assets/text/game/pursuit/pursuit_sk.properties
new file mode 100644
index 000000000..88ea78687
--- /dev/null
+++ b/android/assets/text/game/pursuit/pursuit_sk.properties
@@ -0,0 +1,5 @@
+game_pronasledovani_loadingtext=Zostav mapu premiestňovania a otáčania jednotlivých dielcov.
+game_pronasledovani_victorytext_threestars=Počkať si na lupiča v jeho skrýši, tak to bol podarený kúsok!
+game_pronasledovani_victorytext_twostars=Začínajúci detektív by sa za taký výkon nemusel hanbiť!
+game_pronasledovani_victorytext_onestar=To teda bolo na poslednú chvíľu. Zapracuj ešte na sebe!
+game_pronasledovani_victorytext_gameover=Lupiči si už rozdelili korisť a ty ešte skladáš. To bude chcieť ešte tréning!
diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java
index e259eb9cd..519d7cd34 100644
--- a/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java
+++ b/core/src/cz/nic/tablexia/game/games/pursuit/PursuitGame.java
@@ -132,8 +132,11 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
                                 }
                                 if (grid.allPiecesInCorrectPositions()) {
                                     backgroundImage.removeListener(dragAndRotateActorListener);
-                                    vehicle.setVisible(true);
-                                    finishFlag.setVisible(true);
+                                    //showCheckpoints();
+                                    endTime = System.currentTimeMillis();
+                                    Log.info(getClass(), "Moves : " + movesCounter);
+                                    int starsCount = GameRulesHelper.getNumberOfStarsForMoves(getGameDifficulty().ordinal(), endTime - startTime);
+                                    gameComplete(starsCount);
                                 }
                                 return true;
                             }
@@ -163,7 +166,7 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
 
     private void prepareVehicle() {
         VehicleType vehicleType = TextureHelper.getVehicleTextureName(getRandom(), mapNumber);
-        Point vehiclePosition = TextureHelper.getVehicleStartPosition(grid.getWidth(), mapNumber);
+        Point vehiclePosition = new Point(0,0);
         Point vehicleSize = new Point(vehicleType.getVehicleSize().x, vehicleType.getVehicleSize().y);
         vehicle = new Vehicle(getScreenTextureRegion(vehicleType.getTextureName()), vehiclePosition, vehicleSize);
         vehicle.addListener(new VehicleDragListener(vehicle, getData(), new Point(roadMap.getRegionWidth(), roadMap.getRegionHeight()), finishFlag, new VehicleDragListener.OnVehicleDragCompleteListener() {
@@ -175,21 +178,37 @@ public class PursuitGame extends AbstractTablexiaGame<int[][]> {
                 gameComplete(starsCount);
             }
         }));
+        vehicle.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
         grid.addActor(vehicle);
         vehicle.setVisible(false);
     }
 
     private void prepareFinishFlag() {
         finishFlag = new Image(getScreenTextureRegion(TextureHelper.getFinishFlagTextureName()));
-        Point flagPosition = TextureHelper.getFinishFlagPosition(grid.getWidth(), mapNumber);
-        Point gridRotationCenter = new Point(grid.getOriginX(),grid.getOriginY());
-        Point flagPositonConsideringMapRotation =ArithmeticsHelper.translatePositionAccordingToRotation(flagPosition,grid.getRotation(),gridRotationCenter);
-        finishFlag.setPosition(flagPositonConsideringMapRotation.x, flagPositonConsideringMapRotation.y);
         finishFlag.setSize(FINISH_FLAG_SIZE.x, FINISH_FLAG_SIZE.y);
         finishFlag.setOrigin(finishFlag.getWidth() / 2, finishFlag.getHeight() / 2);
+        finishFlag.setDebug(TablexiaSettings.getInstance().isShowBoundingBoxes());
         grid.addActor(finishFlag);
         finishFlag.setVisible(false);
 
     }
 
+    //sets the position according to completed map rotation
+    private void showCheckpoints(){
+        Point gridRotationCenter = new Point(grid.getWidth()/2,grid.getHeight()/2);
+        //flag
+        Point flagPosition = TextureHelper.getFinishFlagPosition(grid.getWidth(), mapNumber);
+        Point flagPositonConsideringMapRotation =ArithmeticsHelper.translatePositionAccordingToRotation(flagPosition,grid.getRotation(),gridRotationCenter);
+        finishFlag.setPosition(flagPositonConsideringMapRotation.x, flagPositonConsideringMapRotation.y);
+
+        //vehicle
+        Point vehiclePosition = TextureHelper.getVehicleStartPosition(grid.getWidth(), mapNumber);
+        Point vehiclePositonConsideringMapRotation =ArithmeticsHelper.translatePositionAccordingToRotation(vehiclePosition, grid.getRotation(), gridRotationCenter);
+        vehicle.setPosition(vehiclePositonConsideringMapRotation.x, vehiclePositonConsideringMapRotation.y);
+        vehicle.setRotation(grid.getRotation());
+        Log.info(getClass(),"Vehicle: "+vehiclePositonConsideringMapRotation+", Flag: "+flagPositonConsideringMapRotation);
+        vehicle.setVisible(true);
+        finishFlag.setVisible(true);
+    }
+
 }
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 ecc36f199..e5322c789 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
@@ -55,12 +55,12 @@ public class ArithmeticsHelper {
  * (y'-yc) = Ks*(x-xc) + Kc*(y-yc)
  */
     public static Point translatePositionAccordingToRotation(Point zeroRotationPosition, float rotation, Point rotationCenter) {
-        rotation = 360 - (rotation % 360);
+        //rotation = 360 - (rotation % 360);
         rotation = (float) Math.toRadians(rotation);
 
-        int x = (int) (Math.cos(rotation) * (zeroRotationPosition.x - rotationCenter.x)) - (int) (Math.sin(rotation) * (zeroRotationPosition.y - rotationCenter.y));
+        float x = (float) (Math.cos(rotation) * (zeroRotationPosition.x - rotationCenter.x)) - (float) (Math.sin(rotation) * (zeroRotationPosition.y - rotationCenter.y));
         x += rotationCenter.x;
-        int y = (int) (Math.sin(rotation) * (zeroRotationPosition.x - rotationCenter.x)) + (int) (Math.cos(rotation) * (zeroRotationPosition.y - rotationCenter.y));
+        float y = (float) (Math.sin(rotation) * (zeroRotationPosition.x - rotationCenter.x)) + (float) (Math.cos(rotation) * (zeroRotationPosition.y - rotationCenter.y));
         y += rotationCenter.y;
 
         return new Point(x, y);
diff --git a/core/src/cz/nic/tablexia/game/games/pursuit/listener/VehicleDragListener.java b/core/src/cz/nic/tablexia/game/games/pursuit/listener/VehicleDragListener.java
index e0d86d9ae..c2bedecac 100644
--- a/core/src/cz/nic/tablexia/game/games/pursuit/listener/VehicleDragListener.java
+++ b/core/src/cz/nic/tablexia/game/games/pursuit/listener/VehicleDragListener.java
@@ -39,6 +39,7 @@ public class VehicleDragListener extends DragActorListener {
 
     @Override
     public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
+        Log.info(getClass(), "Vehicle touch down");
         touchedPointsCache[currentTouchPointCacheElementPointer] = new Point(x, y);
         vehicleStillOnTheRoad = true;
         return super.touchDown(event, x, y, pointer, button);
@@ -51,6 +52,7 @@ public class VehicleDragListener extends DragActorListener {
         Point touchPoint = new Point(recalculatedCoords.x, recalculatedCoords.y);
         if (isPointOnMap(touchPoint)) {
             Color touchedColor = getTouchedColor(recalculatedCoords.x, recalculatedCoords.y);
+            Log.info(getClass(), "Touched Color: " + touchedColor);
             if (touchedColor.r == 1) {
                 currentTouchPointCacheElementPointer = (currentTouchPointCacheElementPointer + 1) % touchedPointsCache.length;
                 touchedPointsCache[currentTouchPointCacheElementPointer] = new Point(recalculatedCoords.x, recalculatedCoords.y);
@@ -67,10 +69,14 @@ public class VehicleDragListener extends DragActorListener {
     }
 
     private Color getTouchedColor(float x, float y) {
-        int clickX = (int) (x / actor.getParent().getWidth() * roadMapSize.x);
-        int clickY = (int) roadMapSize.y - (int) (y / actor.getParent().getHeight() * roadMapSize.y);
+        float clickX = (x / actor.getParent().getWidth() * roadMapSize.x);
+        float clickY = roadMapSize.y - (y / actor.getParent().getHeight() * roadMapSize.y);
+        Point clickedPoint = new Point(clickX,clickY);
+        Log.info(getClass(), "Point on roadmap: "+x+", "+y+" Road map size: " + roadMapSize+", "+" clicked point: "+clickedPoint);
         //considerating map rotation
-        Point pointOnRotatedMap = ArithmeticsHelper.translatePositionAccordingToRotation(new Point(clickX, clickY), actor.getParent().getRotation(), new Point(actor.getParent().getOriginX(), actor.getParent().getOriginY()));
+        Point mapRotationCenter = new Point(actor.getParent().getWidth() / 2, actor.getParent().getHeight() / 2);
+        Point pointOnRotatedMap = ArithmeticsHelper.translatePositionAccordingToRotation(clickedPoint, -actor.getParent().getRotation(), mapRotationCenter);
+        Log.info(getClass(), "POint on color map: " + pointOnRotatedMap);
         return new Color(roadColorData[(int) pointOnRotatedMap.x][(int) pointOnRotatedMap.y]);
     }
 
diff --git a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java
index 9c164f30e..fd68e2a38 100644
--- a/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java
+++ b/core/src/cz/nic/tablexia/util/listener/DragAndRotateActorListener.java
@@ -61,7 +61,7 @@ public class DragAndRotateActorListener extends InputListener {
             //mouse right button clicked
             if (button == 1) {
                 Log.info(getClass(), "Button 1 clicked");
-                draggedActor.setRotation((draggedActor.getRotation() + 90) % 360);
+                draggedActor.setRotation((draggedActor.getRotation() - 90) % 360);
             }
             if (activePointers.size() == 1) {
                 draggedActor.setZIndex(DRAGGED_PIECE_ZINDEX);
-- 
GitLab