changeset 104:eb2e72dd8cae

Change how piece rotation works.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 18:46:41 +0200
parents 8d5cb9e58301
children 75015dfd47ef
files game/Piece.java
diffstat 1 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/game/Piece.java	Thu Mar 03 18:36:16 2011 +0200
+++ b/game/Piece.java	Thu Mar 03 18:46:41 2011 +0200
@@ -15,7 +15,7 @@
     public enum RotateDir { LEFT, RIGHT }
     
     static final int numConnections = 8;
-    static final float maxTime = 35.0f;
+    static final float maxTime = 50.0f;
 
     int currRotation;
     int[] connections;
@@ -42,8 +42,8 @@
 
         rotationChanged = false;
         rotationActive = false;
-        currRotation = 0;
-        currAngle = 0;
+        currRotation = 4 * 5000;
+        currAngle = getAngle(currRotation);
 
         typeChanged = false;
         typeActive = false;
@@ -91,16 +91,21 @@
         stateChanged = true;
     }
 
+    public int getRotation()
+    {
+        return currRotation % 4;
+    }
+
     public int getRotatedPoint(int in)
     {
-        int point = (in - (currRotation * 2)) % 8;
+        int point = (in - (getRotation() * 2)) % 8;
         if (point < 0) point = 8 + point;
         return point;
     }
 
     public int getAntiRotatedPoint(int in)
     {
-        int point = (in + (currRotation * 2)) % 8;
+        int point = (in + (getRotation() * 2)) % 8;
         if (point < 0) point = 8 + point;
         return point;
     }
@@ -135,6 +140,11 @@
     {
         return connections[point];
     }
+
+    private float getAngle(float rotation)
+    {
+        return (float) ((rotation * Math.PI) / 2.0f);
+    }
     
     public void rotate(RotateDir dir)
     {
@@ -142,8 +152,8 @@
         if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
             return;
 
-        currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)) % 4;
-        newAngle = (float) ((currRotation * Math.PI) / 2.0f);
+        currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1));
+        newAngle = getAngle(currRotation);
         lerpRotation = new Interpolate(newAngle, currAngle, maxTime);
         rotationChanged = true;
     }
@@ -197,12 +207,12 @@
             rotationTime = time;
             rotationActive = true;
             rotationChanged = false;
-            rotationSpeed = 0.5f;
+            rotationSpeed = 1.0f;
         }
 
         if (typeChanged && type == PieceType.LOCKED)
         {
-            rotationSpeed = 1.0f;
+            rotationSpeed = 1.5f;
         }
 
         if (rotationActive)