changeset 6:be0bf7544069

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 28 Jan 2011 18:42:16 +0200
parents 4890020bf856
children 70714c229e23
files Ristipolku.java game/Piece.java game/PieceType.java
diffstat 3 files changed, 52 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/Ristipolku.java	Fri Jan 28 18:00:18 2011 +0200
+++ b/Ristipolku.java	Fri Jan 28 18:42:16 2011 +0200
@@ -7,8 +7,10 @@
 import java.awt.*;
 import java.awt.geom.*;
 import java.awt.event.*;
-import javax.swing.*;
+//import javax.swing.*;
+import javax.imageio.*;
 import java.util.*;
+import java.io.*;
 import game.*;
 
 
@@ -52,10 +54,14 @@
         for (int x = 0; x < boardSize; x++)
         if (board[x][y] != null)
         {
+            AffineTransform save = g.getTransform();
+
             board[x][y].paint(g,
                 sx + (x * scale),
                 sy + (y * scale),
                 scale - scale / 10);
+
+            g.setTransform(save);
         }
     }
    
@@ -84,7 +90,7 @@
     public void pieceFinishTurn()
     {
         if (current != null)
-            current.setType(PieceType.NORMAL);
+            current.setType(PieceType.LOCKED);
       
         if (isEmpty(cx, cy))
         {
--- a/game/Piece.java	Fri Jan 28 18:00:18 2011 +0200
+++ b/game/Piece.java	Fri Jan 28 18:42:16 2011 +0200
@@ -5,10 +5,8 @@
 package game;
 
 import java.awt.*;
-import java.awt.geom.*;
-import java.awt.event.*;
-import javax.swing.*;
 import java.util.*;
+import java.math.*;
 
 
 public class Piece
@@ -22,7 +20,9 @@
 
     boolean rotationChanged, rotationActive,
             typeChanged, typeActive;
-    double currAngle, newAngle;
+    double currAngle, newAngle, rotationTime, typeTime;
+    double throb;
+
 
     public Piece(PieceType ptype)
     {
@@ -31,18 +31,21 @@
         type = ptype;
 
         rotationChanged = false;
+        rotationActive = false;
+        currRotation = 0;
+        currAngle = 0;
+
         typeChanged = false;
-        rotationActive = false;
         typeActive = false;
       
-        currRotation = 0;
-        currAngle = 0;
+        throb = 0;
 
 
         // Initialize connections between endpoints of the paths inside the piece
         for (int i = 0; i < numConnections; i++)
             connections[i] = -1;
 
+        // Randomize connections in the piece
         Random rnd = new Random();
         for (int i = 0; i < numConnections; i++)
         {
@@ -77,7 +80,8 @@
 
     public void rotate(boolean dir)
     {
-        if (type != PieceType.NORMAL)
+        // Only normal 
+        if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
             return;
 
         newRotation = currRotation + (dir ? 1 : -1);
@@ -87,7 +91,7 @@
         else if (currRotation > maxRotation)
             newRotation = minRotation;
 
-        rotationDir = dir;
+        newAngle = 
         rotationChanged = true;
     }
 
@@ -122,25 +126,37 @@
 
         if (rotationActive)
         {
-            double t = time - rotationTime;
-            rotationAngle = 
+            double t = (time - rotationTime) / 10.0f;
+            
+            if (t < Math.PI)
         }
-      
+        
+        if (typeChanged)
+        {
+            typeTime = time;
+            typeActive = true;
+        }
+        
+        if (typeActive)
+        {
+            
+        }
+        
+        throb = ((time / 10.0f) % 100) / 100.0f;
     }
 
     public void paint(Graphics2D g, double x, double y, double dim)
     {
-        AffineTransform save = g.getTransform();
-
         AffineTransform tf = new AffineTransform();
-        tf.rotate(Math.toRadians(rotationAngle));
+        tf.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
         g.transform(tf);
 
         switch (type) {
-            case NORMAL:  g.setPaint(Color.green); break;
+            case LOCKED:  g.setPaint(Color.green); break;
             case ACTIVE:  g.setPaint(Color.red); break;
             case START:   g.setPaint(Color.orange); break;
         }
+
         g.fill(new RoundRectangle2D.Double(x, y, dim, dim, dim / 10, dim / 10));
 
         g.setPaint(Color.black);
@@ -150,6 +166,13 @@
         if (type == PieceType.START)
             return;
 
+        if (type == PieceType.ACTIVE)
+        {
+            g.setPaint(Color(0, 0, 0, 1.0f - throb));
+            g.setStroke(new BasicStroke(2.0f + throb * 2.0f));
+            g.draw(new RoundRectangle2D.Double(x - throb * 10.0f, y - throb * 10.0f, dim + throb * 20.0f, dim + throb * 20.0f, dim / 10, dim / 10));
+        }
+
         g.setStroke(new BasicStroke(6.0f));
 //      CubicCurve2D c = new CubicCurve2D.Double();
         QuadCurve2D c = new QuadCurve2D.Double();
@@ -157,15 +180,13 @@
         for (int i = 0; i < numConnections / 2; i++)
         {
             Point2D start, cp1, cp2, end;
-            start = getPoint(x, y, dim, i);
-            end   = getPoint(x, y, dim, connections[i]);
-//         cp1   = getPoint(x, y, dim, (i + 4) % 8);
-//         cp2   = getPoint(x, y, dim, (connections[i] + 4) % 8);
-            cp1 = getPoint(x, y, dim, -1);
+
+            start = getPointCoords(x, y, dim, i);
+            end   = getPointCoords(x, y, dim, connections[i]);
+            cp1   = getPointCoords(x, y, dim, -1);
 
            c.setCurve(start, cp1, end);
            g.draw(c);
         }
-        g.setTransform(save);
     }
 }
--- a/game/PieceType.java	Fri Jan 28 18:00:18 2011 +0200
+++ b/game/PieceType.java	Fri Jan 28 18:42:16 2011 +0200
@@ -4,5 +4,5 @@
  */
 package game;
 
-public enum PieceType { START, NORMAL, ACTIVE, NONE }
+public enum PieceType { START, LOCKED, ACTIVE, NONE }