changeset 117:973f567c7b9d dev-0_75

Change how gameboard is rendered, make it more OO-sensible.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 31 May 2011 18:53:37 +0300
parents 858b9644a61e
children f5614b5d4aaa
files game/Engine.java
diffstat 1 files changed, 37 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/game/Engine.java	Tue May 31 18:44:58 2011 +0300
+++ b/game/Engine.java	Tue May 31 18:53:37 2011 +0300
@@ -201,7 +201,7 @@
     static final int boardSize = 9;
     static final int boardMiddle = 4;
     Piece[][] board;
-    float pscale;
+    float pscale, ptime;
 
     public boolean flagGameOver;
     public int gameScore;
@@ -258,6 +258,37 @@
                 getScaledY() + (y * pscale),
                 pscale - pscale / 10);
         }
+
+        if (!flagGameOver)
+        {
+            if (nextPiece != null)
+            {
+                // Draw next piece
+                AffineTransform save = g.getTransform();
+                nextPiece.paint(g, 830, 325, 90);
+                g.setTransform(save);
+            }
+        }
+        else
+        {
+            // Game over text
+            String text = "Game Over!";
+            int textWidth = G.metrics[2].stringWidth(text);
+            g.setFont(G.fonts[2]);
+
+            g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f));
+            g.drawString(text, (G.screenDim.width - textWidth) / 2 + 5, G.screenDim.height / 2 + 5);
+
+            double f = Math.sin(ptime * 0.1) * 4.0;
+            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)
@@ -270,6 +301,7 @@
     
     public void animate(float time)
     {
+        ptime = time;
         for (int y = 0; y < boardSize; y++)
         for (int x = 0; x < boardSize; x++)
         if (board[x][y] != null)
@@ -486,7 +518,6 @@
             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);
@@ -515,13 +546,13 @@
         // Create IDM GUI widgets
         widgets = new IDMContainer();
 
+        lauta = new GameBoard(new IDMPoint(95, 130), 63);
+        widgets.add(lauta);
+
         widgets.add(new BtnSwapPiece(767f, 450f));
         widgets.add(new BtnAbout    (767f, 570f));
         widgets.add(new BtnNewGame  (767f, 650f));
 
-        lauta = new GameBoard(new IDMPoint(95, 130), 63);
-        widgets.add(lauta);
-
         aboutBox = new AboutBox();
         
         // Game
@@ -596,41 +627,11 @@
 
         widgets.paint(g2);
 
-        if (!lauta.flagGameOver)
-        {
-            if (lauta.nextPiece != null)
-            {
-                // Draw next piece
-                AffineTransform save = g2.getTransform();
-                lauta.nextPiece.paint(g2, 830, 325, 90);
-                g2.setTransform(save);
-            }
-        }
-        else
-        {
-            // Game over text
-            String text = "Game Over!";
-            int textWidth = G.metrics[2].stringWidth(text);
-            g2.setFont(G.fonts[2]);
-
-            g2.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f));
-            g2.drawString(text, (dim.width - textWidth) / 2 + 5, dim.height / 2 + 5);
-
-            double f = Math.sin(gameClock * 0.1) * 4.0;
-            g2.setPaint(Color.white);
-            g2.drawString(text, (dim.width - textWidth) / 2 + (float) f, dim.height / 2 + (float) f);
-        }
-        
-        // Score
-        g2.setFont(G.fonts[2]);
-        g2.setPaint(Color.white);
-        g2.drawString(""+ String.format("%05d", lauta.gameScore), dim.width - 230, 220);
-
 
         // Frames per second counter
         g2.setFont(G.fonts[1]);
         long currTime = new Date().getTime();
-        g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20);
+        g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20);
         
         gameFrames++;
     }