changeset 40:a69103644bf6

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Feb 2011 23:34:47 +0200
parents e682b623aea9
children a5fd4f74a767
files game/Engine.java game/Piece.java game/ResourceLoader.java
diffstat 3 files changed, 35 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/game/Engine.java	Fri Feb 18 15:47:15 2011 +0200
+++ b/game/Engine.java	Fri Feb 18 23:34:47 2011 +0200
@@ -35,7 +35,7 @@
     public void print()
     {
         System.out.print("PathInfo: inP="+in+", inX="+inX+", inY="+inY+"\n");
-        System.out.print("          outP="+out+", outX="+outX+", outY="+outY+"\n");
+        System.out.print("          outP="+out+", outX="+outX+", outY="+outY+"\n\n");
     }
 }
 
@@ -200,11 +200,11 @@
                     if (mark)
                     {
                         curr.setType(PieceType.LOCKED);
-                        curr.setActiveConnection(point);
+                        curr.setConnectionState(curr.getRotatedPoint(point), true);
                     }
                     
                     // Get next piece
-                    point = curr.getConnection(point);
+                    point = curr.getConnection(curr.getRotatedPoint(point));
                     switch (point)
                     {
                         case 0: y--; point = 5; break;
@@ -237,14 +237,11 @@
         // Do we have a piece?
         if (current != null)
         {
-            // Yes, place and lock it
-            current.setType(PieceType.LOCKED);
+            // Yes, start resolving path to next piece placement
             PathInfo i = resolvePath(moveX, moveY, movePoint, true);
-            
+
             if (i != null)
             {
-                System.out.print("moveX="+moveX+", moveY="+moveY+", movePoint="+movePoint+"\n");
-                i.print();
                 moveX = i.outX;
                 moveY = i.outY;
                 movePoint = i.out;
@@ -265,7 +262,10 @@
             // Resolve path
             PathInfo i = resolvePath(moveX, moveY, movePoint, true);
             if (i != null)
+            {
+                // Path found, place the piece
                 board[moveX][moveY] = current;
+            }
             else
             {
                 // Path ended up center/gameboard walls - it's game over, man
--- 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);
--- a/game/ResourceLoader.java	Fri Feb 18 15:47:15 2011 +0200
+++ b/game/ResourceLoader.java	Fri Feb 18 23:34:47 2011 +0200
@@ -27,7 +27,6 @@
     
     public InputStream getStream()
     {
-        System.out.print("ResourceLoader('"+ name +"').getStream()\n");
         return stream;
     }