changeset 58:cde170f2f980

Clean up the piece rendering.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Feb 2011 21:43:07 +0200
parents 1435e9d7fd1a
children fd10a9422b60
files game/Piece.java
diffstat 1 files changed, 49 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/game/Piece.java	Wed Feb 23 20:36:07 2011 +0200
+++ b/game/Piece.java	Wed Feb 23 21:43:07 2011 +0200
@@ -238,65 +238,69 @@
 
     public void paint(Graphics2D g, float x, float y, float dim)
     {
+        AffineTransform save = g.getTransform();
+
         // Transform drawing by current angle
         g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
 
         // Color piece by type
         switch (type) {
-            case LOCKED:  g.setPaint(Color.green); break;
-            case ACTIVE:  g.setPaint(Color.red); break;
-            case START:   g.setPaint(Color.orange); break;
+            case LOCKED:  g.setPaint(new Color(0.3f, 0.8f, 0.3f, 0.35f)); break;
+            case ACTIVE:  g.setPaint(new Color(0.9f, 0.3f, 0.3f, 0.35f)); break;
+            case START:   g.setPaint(new Color(1.0f, 0.8f, 0.0f, 0.95f)); break;
         }
 
         g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
 
         // Start pieces (center piece) do not have border, etc.
-        if (type == PieceType.START)
-            return;
-
-        // Active piece has a throbbing "ghost" border
-        if (type == PieceType.ACTIVE)
-        {
-            float offs1 = throbTime * 10.0f,
-                  offs2 = throbTime * 20.0f;
-
-            g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
-            g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
-            g.draw(new RoundRectangle2D.Float(
-                x - offs1, y - offs1,
-                dim + offs2, dim + offs2,
-                dim / 10, dim / 10));
-        }
-
-        // Draw the connections
-        g.setStroke(new BasicStroke(5.0f));
-        CubicCurve2D c = new CubicCurve2D.Float();
-        boolean[] drawn = new boolean[numConnections];
-        for (int i = 0; i < numConnections; i++)
-        if (!drawn[i])
+        if (type != PieceType.START)
         {
-            Point2D start, cp1, cp2, end;
-            boolean isActive = states[i] || states[connections[i]];
+            // Active piece has a throbbing "ghost" border
+            if (type == PieceType.ACTIVE)
+            {
+                float offs1 = throbTime * 10.0f,
+                      offs2 = throbTime * 20.0f;
 
-            g.setPaint(isActive ? Color.white : Color.black);
-            
-            start = getPointCoords(x, y, dim, i);
-            end   = getPointCoords(x, y, dim, connections[i]);
-            
-            cp1   = getPointCoords(x, y, dim, i + 8);
-            cp2   = getPointCoords(x, y, dim, connections[i] + 8);
+                g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
+                g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
+                g.draw(new RoundRectangle2D.Float(
+                    x - offs1, y - offs1,
+                    dim + offs2, dim + offs2,
+                    dim / 10, dim / 10));
+            }
+
+            // Draw piece border
+            g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f));
+            g.setStroke(new BasicStroke(5.0f));
+            g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
 
-            c.setCurve(start, cp1, cp2, end);
-            g.draw(c);
+            // Draw the connections
+            g.setStroke(new BasicStroke(5.5f));
+            CubicCurve2D curve = new CubicCurve2D.Float();
+            boolean[] drawn = new boolean[numConnections];
+            for (int i = 0; i < numConnections; i++)
+            if (!drawn[i])
+            {
+                Point2D start, cp1, cp2, end;
+                boolean isActive = states[i] || states[connections[i]];
+
+                g.setPaint(isActive ? Color.white : Color.black);
 
-            // Mark connection drawn, so we don't overdraw
-            drawn[i] = true;
-            drawn[connections[i]] = true;
-        }
+                start = getPointCoords(x, y, dim, i);
+                end   = getPointCoords(x, y, dim, connections[i]);
+                cp1   = getPointCoords(x, y, dim, i + 8);
+                cp2   = getPointCoords(x, y, dim, connections[i] + 8);
+
+                curve.setCurve(start, cp1, cp2, end);
+                g.draw(curve);
 
-        // Draw piece border
-        g.setPaint(Color.black);
-        g.setStroke(new BasicStroke(5.0f));
-        g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
+                // Mark connection drawn, so we don't overdraw
+                drawn[i] = true;
+                drawn[connections[i]] = true;
+            }
+        
+        } // !PieceType.START
+
+        g.setTransform(save);
     }
 }