diff game/Piece.java @ 40:a69103644bf6

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Feb 2011 23:34:47 +0200
parents e682b623aea9
children 951a4d669af0
line wrap: on
line diff
--- a/game/Piece.java	Fri Feb 18 15:47:15 2011 +0200
+++ b/game/Piece.java	Fri Feb 18 23:34:47 2011 +0200
@@ -19,25 +19,23 @@
 
     int currRotation;
     int[] connections;
-    boolean[] active;
+    boolean[] states;
     PieceType type, prevType;
 
     boolean rotationChanged, rotationActive,
             typeChanged, typeActive,
-            activeChanged, activeActive;
+            stateChanged, stateActive;
     float currAngle, newAngle, rotationTime, typeTime;
 
     float throbTime;
     Interpolate lerpRotation;
 
-    int point;
-
 
     public Piece(PieceType ptype)
     {
         // Initialize
         connections = new int[numConnections];
-        active = new boolean[numConnections];
+        states = new boolean[numConnections];
         type = ptype;
 
         rotationChanged = false;
@@ -84,13 +82,30 @@
         type = ptype;
     }
 
-    public int getConnection(int in)
+    public void clearStates()
+    {
+        for (int i = 0; i < numConnections; i++)
+            states[i] = false;
+        stateChanged = true;
+    }
+
+    public int getRotatedPoint(int in)
     {
-        int offs = (in + (currRotation * 2)) % 8;
-        if (offs < 0)
-            offs = 8 + offs;
+        int point = (in + (currRotation * 2)) % 8;
+        if (point < 0) point = 8 + point;
+        return point;
+    }
 
-        return connections[offs];
+    public void setConnectionState(int point, boolean state)
+    {
+        states[point] = state;
+        states[connections[point]] = state;
+        stateChanged = true;
+    }
+
+    public int getConnection(int point)
+    {
+        return connections[point];
     }
     
     public void rotate(RotateDir dir)
@@ -142,22 +157,6 @@
         return new Point2D.Float(x + ox * step, y + oy * step);
     }
     
-    public void clearActiveConnections()
-    {
-        for (int i = 0; i < numConnections; i++)
-            active[i] = false;
-
-        activeChanged = true;
-    }
-
-    public void setActiveConnection(int index)
-    {
-        active[index] = true;
-        active[connections[index]] = true;
-
-        activeChanged = true;
-    }
-    
     public PieceType getType()
     {
         return type;
@@ -196,7 +195,7 @@
         {
         }
         
-        if (activeChanged)
+        if (stateChanged)
         {
         }
         
@@ -237,8 +236,8 @@
         if (!drawn[i])
         {
             Point2D start, cp1, cp2, end;
+            boolean isActive = states[i] || states[connections[i]];
 
-            boolean isActive = active[i] || active[connections[i]];
             g.setPaint(isActive ? Color.white : Color.black);
             
             start = getPointCoords(x, y, dim, i);