changeset 10:4bacc98973f5

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 29 Jan 2011 01:54:28 +0200
parents a7751971c2a3
children b89ecc8d5557
files game/Engine.java game/Piece.java
diffstat 2 files changed, 19 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/game/Engine.java	Sat Jan 29 00:30:00 2011 +0200
+++ b/game/Engine.java	Sat Jan 29 01:54:28 2011 +0200
@@ -80,6 +80,8 @@
     Piece current;
     public boolean flagGameOver;
     
+    
+    
     int moveX, moveY, movePoint;
 
     public GameBoard()
@@ -122,6 +124,7 @@
         {
             board[x][y].animate(time);
         }
+
     }
    
     private boolean isEmpty(int x, int y)
@@ -227,6 +230,7 @@
         
         lauta = new GameBoard();
         addKeyListener(this);
+
     }
 
     public void startThreads()
@@ -254,10 +258,12 @@
     public void paintComponent(Graphics g)
     {
         Graphics2D g2 = (Graphics2D) g;
-
+        
+        // Use antialiasing when rendering the game elements
         g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
 
+        // Rescale background if component size has changed
         Dimension dim = getSize();
         if (oldDim == null || !dim.equals(oldDim))
         {
@@ -265,17 +271,24 @@
             Graphics2D gimg = lautaBGScaled.createGraphics();
             gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                   RenderingHints.VALUE_INTERPOLATION_BICUBIC);
-            AffineTransform xform = AffineTransform.getScaleInstance(0.5f, 0.5f);
-            gimg.drawImage(lautaBG, xform, null);
+
+            gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); 
             oldDim = dim;
             System.out.print("scale changed\n");
         }
         
+        // Background, pieces
         g2.drawImage(lautaBGScaled, 0, 0, null);
         lauta.paint(g2, 100, 150, 60);
 
+        // Other elements
+        
+        // Request focus to keep keyboard input coming
         if (!hasFocus())
+        {
+            System.out.print(".\n");
             requestFocus();
+        }
     }
 
     public void keyTyped(KeyEvent e)
@@ -317,7 +330,8 @@
 
             lauta.animate(clock);
             
-            repaint();
+            if (clock % 2 == 1)
+                repaint();
             
             try {
                 Thread.sleep(10);
--- a/game/Piece.java	Sat Jan 29 00:30:00 2011 +0200
+++ b/game/Piece.java	Sat Jan 29 01:54:28 2011 +0200
@@ -92,8 +92,8 @@
         currRotation = currRotation + (dir ? -1 : 1);
         newAngle = (float) (currRotation * Math.PI) / 2.0f;
 
+        lerpRotation = new Interpolate(currAngle, newAngle, maxTime);
         rotationChanged = true;
-        lerpRotation = new Interpolate(currAngle, newAngle, maxTime);
     }
 
     public Point2D getPointCoords(float x, float y, float dim, int index)
@@ -158,7 +158,6 @@
         
         if (activeChanged)
         {
-            
         }
         
         throb = (time % 100) / 100.0f;
@@ -170,9 +169,6 @@
         tf.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
         g.transform(tf);
 
-        if (type == PieceType.ACTIVE)
-            System.out.print("angle = " + currAngle + "\n");
-
         switch (type) {
             case LOCKED:  g.setPaint(Color.green); break;
             case ACTIVE:  g.setPaint(Color.red); break;