# HG changeset patch # User Matti Hamalainen # Date 1298483688 -7200 # Node ID cc7943cd7f2dd114838edc7b13d602d102015dfd # Parent 6bf4675e2d969848aad825a7eb74aabb80b73a46 Moar work. diff -r 6bf4675e2d96 -r cc7943cd7f2d game/Engine.java --- a/game/Engine.java Wed Feb 23 16:58:21 2011 +0200 +++ b/game/Engine.java Wed Feb 23 19:54:48 2011 +0200 @@ -63,8 +63,8 @@ Piece[][] board; public boolean flagGameOver; - - Piece currPiece; + + public Piece currPiece, nextPiece; int currX, currY, currPoint; int score; @@ -82,6 +82,7 @@ currY = boardMiddle; currPoint = 0; + nextPiece = new Piece(PieceType.ACTIVE); pieceFinishTurn(); flagGameOver = false; @@ -142,6 +143,20 @@ } } + public void pieceCreateNew() + { + currPiece = nextPiece; + nextPiece = new Piece(PieceType.ACTIVE); + } + + public void pieceSwapCurrent() + { + Piece tmp = currPiece; + currPiece = nextPiece; + nextPiece = tmp; + board[currX][currY] = currPiece; + } + public boolean pieceCheck(Piece piece) { if (piece == null) @@ -164,7 +179,7 @@ { // Start piece as first piece means game is starting pieceMoveTo(currPoint); - currPiece = new Piece(PieceType.ACTIVE); + pieceCreateNew(); board[currX][currY] = currPiece; return true; } @@ -213,6 +228,9 @@ public boolean keyPressed(KeyEvent e) { + if (flagGameOver) + return false; + switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: @@ -356,6 +374,7 @@ // Background image, pieces g2.drawImage(lautaBGScaled, 0, 0, null); lauta.paint(g2, 90, 140, 65); + lauta.nextPiece.paint(g2, 830, 325, 90); widgets.paint(g2); // Scores, etc @@ -442,6 +461,7 @@ // Animate components lauta.animate(gameClock); + lauta.nextPiece.animate(gameClock); // Repaint with a frame limiter if (gameClock % 3 == 1) @@ -481,6 +501,7 @@ public void clicked() { + lauta.pieceSwapCurrent(); } } } diff -r 6bf4675e2d96 -r cc7943cd7f2d game/Piece.java --- a/game/Piece.java Wed Feb 23 16:58:21 2011 +0200 +++ b/game/Piece.java Wed Feb 23 19:54:48 2011 +0200 @@ -25,7 +25,7 @@ boolean rotationChanged, rotationActive, typeChanged, typeActive, stateChanged, stateActive; - float currAngle, newAngle, rotationTime, typeTime; + float currAngle, newAngle, rotationTime, typeTime, rotationSpeed; float throbTime; Interpolate lerpRotation; @@ -195,11 +195,17 @@ rotationTime = time; rotationActive = true; rotationChanged = false; + rotationSpeed = 0.5f; + } + + if (typeChanged && type == PieceType.LOCKED) + { + rotationSpeed = 1.0f; } if (rotationActive) { - float t = (time - rotationTime) / 2; + float t = (time - rotationTime) * rotationSpeed; if (t < maxTime) currAngle = lerpRotation.getValue(t); @@ -209,7 +215,7 @@ rotationActive = false; } } - + if (typeChanged) { typeTime = time; @@ -225,6 +231,8 @@ { } + + throbTime = (time % 100) / 100.0f; }