# HG changeset patch # User Matti Hamalainen # Date 1299180095 -7200 # Node ID 41c6cca69d6023aa79bba7ee596ca5908621273b # Parent 75015dfd47efa841e82be2201a1c7af415c31578 Make new pieces appear gradually, and same effect for swapping. diff -r 75015dfd47ef -r 41c6cca69d60 game/Engine.java --- a/game/Engine.java Thu Mar 03 18:48:17 2011 +0200 +++ b/game/Engine.java Thu Mar 03 21:21:35 2011 +0200 @@ -308,6 +308,7 @@ public void pieceCreateNew() { currPiece = nextPiece; + currPiece.changed(); nextPiece = new Piece(PieceType.ACTIVE); } @@ -319,6 +320,8 @@ currPiece = nextPiece; nextPiece = tmp; board[currX][currY] = currPiece; + currPiece.changed(); + nextPiece.changed(); } } @@ -471,7 +474,7 @@ System.out.print("Engine() constructor\n"); // Sound system - G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 2); + G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1); // Load resources try diff -r 75015dfd47ef -r 41c6cca69d60 game/G.java --- a/game/G.java Thu Mar 03 18:48:17 2011 +0200 +++ b/game/G.java Thu Mar 03 21:21:35 2011 +0200 @@ -15,7 +15,7 @@ public class G { - public static final String version = "0.66"; + public static final String version = "0.70"; public static final int numFonts = 4; public static Font fonts[]; diff -r 75015dfd47ef -r 41c6cca69d60 game/Interpolate.java --- a/game/Interpolate.java Thu Mar 03 18:48:17 2011 +0200 +++ b/game/Interpolate.java Thu Mar 03 21:21:35 2011 +0200 @@ -8,7 +8,7 @@ public class Interpolate { - float start, end, steps; + public float start, end, steps; public Interpolate(float start, float end, float steps) { diff -r 75015dfd47ef -r 41c6cca69d60 game/Piece.java --- a/game/Piece.java Thu Mar 03 18:48:17 2011 +0200 +++ b/game/Piece.java Thu Mar 03 21:21:35 2011 +0200 @@ -26,11 +26,11 @@ typeChanged, typeActive, stateChanged, stateActive; - float currAngle, newAngle, - rotationTime, rotationSpeed, - typeTime, throbTime; + float currAngle, rotationTime, rotationSpeed, + typeTime, typeValue, throbTime; - Interpolate lerpRotation; + Interpolate lerpRotation, + lerpType; public Piece(PieceType ptype) @@ -50,6 +50,7 @@ throbTime = 0; + lerpType = new Interpolate(1.0f, 0.0f, maxTime); // Initialize connections between endpoints of the paths inside the piece for (int i = 0; i < numConnections; i++) @@ -77,9 +78,15 @@ this(PieceType.NONE); } + + public void changed() + { + typeChanged = true; + } + public void setType(PieceType ptype) { - typeChanged = (prevType != ptype); +// typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED); prevType = type; type = ptype; } @@ -153,8 +160,7 @@ return; currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)); - newAngle = getAngle(currRotation); - lerpRotation = new Interpolate(newAngle, currAngle, maxTime); + lerpRotation = new Interpolate(getAngle(currRotation), currAngle, maxTime); rotationChanged = true; } @@ -223,7 +229,7 @@ currAngle = lerpRotation.getValue(t); else { - currAngle = newAngle; + currAngle = lerpRotation.start; rotationActive = false; } } @@ -237,6 +243,15 @@ if (typeActive) { + float t = (time - typeTime) * 2.0f; + + if (t < maxTime) + typeValue = lerpType.getValue(t); + else + { + typeValue = lerpType.start; + typeActive = false; + } } if (stateChanged) @@ -249,6 +264,15 @@ public void paint(Graphics2D g, float x, float y, float dim) { AffineTransform save = g.getTransform(); + Composite csave = g.getComposite(); + + // Change compositing alpha for the whole piece drawing + // when the piece is being "introduced". + if (typeActive) + { + g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, typeValue)); + } + // Transform drawing by current angle g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); @@ -320,5 +344,6 @@ } // !PieceType.START g.setTransform(save); + g.setComposite(csave); } }