# HG changeset patch # User Matti Hamalainen # Date 1298484986 -7200 # Node ID 974ec36c562e98a0503cbe8b10e27809b918cd83 # Parent cc7943cd7f2dd114838edc7b13d602d102015dfd Updates. diff -r cc7943cd7f2d -r 974ec36c562e game/Engine.java --- a/game/Engine.java Wed Feb 23 19:54:48 2011 +0200 +++ b/game/Engine.java Wed Feb 23 20:16:26 2011 +0200 @@ -63,11 +63,11 @@ Piece[][] board; public boolean flagGameOver; + public int gameScore; public Piece currPiece, nextPiece; int currX, currY, currPoint; - int score; SoundManager soundManager; Sound sndPlaced; @@ -86,7 +86,7 @@ pieceFinishTurn(); flagGameOver = false; - score = 0; + gameScore = 0; soundManager = smgr; // sndPlaced = soundManager.getSound("sounds/placed.wav"); @@ -205,10 +205,13 @@ public void pieceFinishTurn() { boolean finished = false; + int connections = 0; + while (!finished) { if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) { + connections++; finished = pieceCheck(board[currX][currY]); } else @@ -219,6 +222,8 @@ } } + gameScore += connections * connections; + if (flagGameOver) { currPiece = null; @@ -262,6 +267,8 @@ boolean animEnable = false; Font fontMain, font1, font2; + FontMetrics metrics1, metrics2; + GameBoard lauta = null; BufferedImage lautaBG = null, lautaBGScaled = null; Dimension lautaDim; @@ -289,15 +296,16 @@ try { res = new ResourceLoader("graphics/font.ttf"); fontMain = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); + font1 = fontMain.deriveFont(24f); - font2 = fontMain.deriveFont(32f); + font2 = fontMain.deriveFont(64f); } catch (FontFormatException e) { System.out.print("Could not initialize fonts.\n"); } -// musa = smgr.getSound("sounds/gamemusic.wav"); + musa = soundManager.getSound("sounds/gamemusic.wav"); } catch (IOException e) { @@ -371,16 +379,43 @@ System.out.print("scale changed\n"); } + if (metrics1 == null) + metrics1 = g2.getFontMetrics(font1); + + if (metrics2 == null) + metrics2 = g2.getFontMetrics(font2); + // Background image, pieces g2.drawImage(lautaBGScaled, 0, 0, null); lauta.paint(g2, 90, 140, 65); - lauta.nextPiece.paint(g2, 830, 325, 90); + + if (!lauta.flagGameOver) + { + lauta.nextPiece.paint(g2, 830, 325, 90); + } + else + { + String text = "Game Over!"; + int textWidth = metrics2.stringWidth(text); + g2.setFont(font2); + + 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); + } + widgets.paint(g2); // Scores, etc - g2.setFont(font1); + g2.setFont(font2); g2.setPaint(Color.white); + g2.drawString(""+ String.format("%05d", lauta.gameScore), dim.width - 230, 220); + + g2.setFont(font1); long currTime = new Date().getTime(); g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); } @@ -460,8 +495,11 @@ gameClock++; // Animate components - lauta.animate(gameClock); - lauta.nextPiece.animate(gameClock); + if (!lauta.flagGameOver) + { + lauta.animate(gameClock); + lauta.nextPiece.animate(gameClock); + } // Repaint with a frame limiter if (gameClock % 3 == 1)