diff game/Engine.java @ 134:4c0dec72e2f0

Whitespace cosmetic cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Nov 2011 21:51:54 +0200
parents 881deac2daf8
children a33fdb1de11c
line wrap: on
line diff
--- a/game/Engine.java	Thu Nov 24 21:50:41 2011 +0200
+++ b/game/Engine.java	Thu Nov 24 21:51:54 2011 +0200
@@ -29,7 +29,7 @@
     Paint textPaint;
     Font textFont;
     FontMetrics textMetrics;
-    
+
 
     public AboutBox()
     {
@@ -42,7 +42,7 @@
         }
 
         aboutSecret = false;
-        
+
         setPos(150f, 150f);
         setSize(675f, 420f);
     }
@@ -52,7 +52,7 @@
         textFont = font;
         textMetrics = metrics;
     }
-    
+
     public void setTextPaint(Paint paint)
     {
         textPaint = paint;
@@ -63,18 +63,18 @@
         currPos = npos;
         currOffs = new IDMPoint(0, 0);
     }
-    
+
     public void setCurrPos(float x, float y)
     {
         setCurrPos(new IDMPoint(x, y));
     }
-    
+
     public void drawString(Graphics2D g, String text)
     {
         Paint savePaint = g.getPaint();
         g.setPaint(textPaint);
         g.setFont(textFont);
-        
+
         int i = 0;
         while (i < text.length())
         {
@@ -95,7 +95,7 @@
             }
 
             g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y);
-            
+
             if (linefeed)
             {
                 currOffs.x = 0;
@@ -120,7 +120,7 @@
 
         setTextFont(G.fonts[3], G.metrics[3]);
         setTextPaint(Color.white);
-        
+
         setCurrPos(x + 20, y + 30);
         drawString(g, "RistiPolku (CrossPaths) v"+ G.version +"\n");
 
@@ -128,14 +128,14 @@
         if (aboutSecret)
         {
             g.drawImage(aboutImg, x + 20, y + 55,
-                aboutImg.getWidth(), aboutImg.getHeight(), null); 
+                aboutImg.getWidth(), aboutImg.getHeight(), null);
 
             setCurrPos(x + 225, y + 75);
             drawString(g,
                 "Dedicated to my\n" +
                 "favorite woman\n" +
                 "in the world.");
-            
+
             setCurrPos(x + 370, y + 175);
             drawString(g, "- Matti");
         }
@@ -153,7 +153,7 @@
             drawString(g, "Controls:\n");
 
             IDMPoint old = currOffs.copy();
-            
+
             setTextPaint(Color.white);
             drawString(g,
             "Arrow keys / mouse wheel\n"+
@@ -166,7 +166,7 @@
             "- Rotate piece\n" +
             "- Place/lock piece\n" +
             "- Swap piece\n");
-            
+
             currPos.x -= 330;
             setTextPaint(Color.green);
             drawString(g,
@@ -190,7 +190,7 @@
         }
         return true;
     }
-    
+
     public void clicked()
     {
         parent.remove(this);
@@ -204,7 +204,7 @@
     static final int boardMiddle = 4;
     Piece[][] board;
     float pscale, ptime;
-    
+
     public boolean flagGameOver;
     int gameScore;
 
@@ -215,7 +215,7 @@
 
     private final ReentrantReadWriteLock pointLock = new ReentrantReadWriteLock();
     private ArrayList<AnimatedPointElement> pointElems;
-    
+
     public GameBoard(IDMPoint pos, float ps)
     {
         super(pos);
@@ -227,10 +227,10 @@
 
         startNewGame();
     }
-    
+
     public void startNewGame()
     {
-    
+
         board = new Piece[boardSize][boardSize];
         board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
 
@@ -254,7 +254,7 @@
             boardSize * pscale, boardSize * pscale,
             pscale / 5, pscale / 5));
     }
-    
+
     public void paint(Graphics2D g)
     {
         for (int y = 0; y < boardSize; y++)
@@ -280,7 +280,7 @@
         {
             read.unlock();
         }
-        
+
 
         if (!flagGameOver)
         {
@@ -306,14 +306,14 @@
             g.setPaint(Color.white);
             g.drawString(text, (G.screenDim.width - textWidth) / 2 + (float) f, G.screenDim.height / 2 + (float) f);
         }
-        
+
         // Score
         g.setFont(G.fonts[2]);
         g.setPaint(Color.white);
         g.drawString(""+ String.format("%05d", gameScore), G.screenDim.width - 230, 220);
 
     }
-    
+
     public boolean contains(float x, float y)
     {
         return (x >= getScaledX() &&
@@ -321,7 +321,7 @@
                 x < getScaledX() + boardSize * pscale &&
                 y < getScaledY() + boardSize * pscale);
     }
-    
+
     public void animate(float time)
     {
         ptime = time;
@@ -331,7 +331,7 @@
         {
             board[x][y].animate(time);
         }
-    
+
         Lock write = pointLock.writeLock();
         write.lock();
         try
@@ -344,7 +344,7 @@
                 if (elem.active)
                     tmp.add(elem);
             }
-            
+
             pointElems = tmp;
         }
         finally
@@ -352,7 +352,7 @@
             write.unlock();
         }
     }
-   
+
     public void pieceRotate(Piece.RotateDir dir)
     {
         if (currPiece != null && !flagGameOver)
@@ -387,7 +387,7 @@
         currPiece.changed();
         nextPiece = new Piece(PieceType.ACTIVE);
     }
-    
+
     public void pieceSwapCurrent()
     {
         if (!flagGameOver)
@@ -400,7 +400,7 @@
             nextPiece.changed();
         }
     }
-    
+
     // Check one piece, set connections, find the new placement
     // based on piece rotations etc.
     private boolean pieceCheck(Piece piece)
@@ -459,14 +459,14 @@
         {
             G.smgr.play(sndPlaced);
         }
-        
+
         while (!finished)
         {
             if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize)
             {
                 connections++;
                 finished = pieceCheck(board[currX][currY]);
-                
+
                 if (!finished)
                 {
                     Lock write = pointLock.writeLock();
@@ -492,10 +492,10 @@
                 flagGameOver = true;
             }
         }
-        
+
         // Compute and add score
         gameScore += connections * connections;
-        
+
         // If game over, clear the game
         if (flagGameOver)
         {
@@ -514,7 +514,7 @@
 
         return true;
     }
-    
+
     public void clicked()
     {
         if (!flagGameOver)
@@ -566,7 +566,7 @@
     {
         // Initialize globals
         System.out.print("Engine() constructor\n");
-        
+
         // Sound system
         G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1);
 
@@ -575,10 +575,10 @@
         {
             ResourceLoader res = new ResourceLoader("graphics/board.jpg");
             G.lautaBG = ImageIO.read(res.getStream());
-            
+
             try {
                 res = new ResourceLoader("graphics/font.ttf");
-                
+
                 G.fonts = new Font[G.numFonts];
                 G.fonts[0] = Font.createFont(Font.TRUETYPE_FONT, res.getStream());
                 G.fonts[1] = G.fonts[0].deriveFont(24f);
@@ -589,7 +589,7 @@
             {
                 System.out.print("Could not initialize fonts.\n");
             }
-            
+
             res = new ResourceLoader("sounds/gamemusic.wav");
             musa = res.getStream();
         }
@@ -614,10 +614,10 @@
         widgets.add(new BtnNewGame  (767f, 630f));
 
         aboutBox = new AboutBox();
-        
+
         // Game
         startNewGame();
-        
+
         // Initialize event listeners
         addKeyListener(this);
         addMouseListener(this);
@@ -647,14 +647,14 @@
     {
         Graphics2D g2 = (Graphics2D) g;
         boolean scaleChanged = false;
-        
+
         // Rescale if parent component size has changed
         Dimension dim = getSize();
         if (G.screenDim == null || !dim.equals(G.screenDim))
         {
             float dw = dim.width / 1024.0f,
                   dh = dim.height / 768.0f;
-            
+
             // Rescale IDM GUI widgets
             widgets.setScale(dw, dh);
             G.screenDim = dim;
@@ -665,18 +665,18 @@
             gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                   RenderingHints.VALUE_INTERPOLATION_BICUBIC);
 
-            gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null); 
+            gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null);
             lauta.paintBackPlate(gimg);
 
             // Rescale fonts
             G.fonts[1] = G.fonts[0].deriveFont(24f * dw);
             G.fonts[2] = G.fonts[0].deriveFont(64f * dw);
             G.fonts[3] = G.fonts[0].deriveFont(32f * dw);
-            
+
             System.out.print("scale changed\n");
             scaleChanged = true;
         }
-        
+
         // Get font metrics against current Graphics2D context
         if (G.metrics == null || scaleChanged)
         {
@@ -684,7 +684,7 @@
             for (int i = 0; i < G.numFonts; i++)
                 G.metrics[i] = g2.getFontMetrics(G.fonts[i]);
         }
-        
+
         // Draw background image, pieces, widgets
         g2.drawImage(G.lautaBGScaled, 0, 0, null);
 
@@ -702,7 +702,7 @@
         g2.setFont(G.fonts[1]);
         long currTime = new Date().getTime();
         g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20);
-        
+
         gameFrames++;
     }
 
@@ -716,11 +716,11 @@
             animThread.start();
         }
     }
-    
+
     public void stopThreads()
     {
         System.out.print("stopThreads()\n");
-        
+
         // Stop animations
         if (animThread != null)
         {
@@ -774,7 +774,7 @@
 
     public void keyTyped(KeyEvent e) { }
     public void keyReleased(KeyEvent e) { }
-   
+
     public void keyPressed(KeyEvent e)
     {
         // Handle keyboard input
@@ -783,7 +783,7 @@
         else
             widgets.keyPressed(e);
     }
-    
+
     public void run()
     {
         while (animEnable)
@@ -795,11 +795,11 @@
             lauta.animate(gameClock);
             if (lauta.nextPiece != null)
                 lauta.nextPiece.animate(gameClock);
-            
+
             // Repaint with a frame limiter
             if (gameClock % 4 == 1)
                 repaint();
-            
+
             // Sleep for a moment
             try {
                 Thread.sleep(10);
@@ -808,7 +808,7 @@
             }
         }
     }
-    
+
     class BtnNewGame extends IDMButton
     {
         public BtnNewGame(float x, float y)