# HG changeset patch # User Matti Hamalainen # Date 1322164314 -7200 # Node ID 4c0dec72e2f04ad29f5b246901d2e4a0f01ef76a # Parent 881deac2daf8f3f44903efb3e07783f631872cc3 Whitespace cosmetic cleanup. diff -r 881deac2daf8 -r 4c0dec72e2f0 game/AnimatedPointElement.java --- a/game/AnimatedPointElement.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/AnimatedPointElement.java Thu Nov 24 21:51:54 2011 +0200 @@ -17,7 +17,7 @@ private Interpolate lerpV, lerpX, lerpY; boolean active, first; String text; - + public AnimatedPointElement(IDMPoint start, String text) { Random rnd = new Random(); @@ -32,7 +32,7 @@ first = true; this.text = text; } - + public void animate(float time) { if (first) @@ -41,7 +41,7 @@ active = true; stime = time; } - + if (active) { float t = (time - stime); @@ -56,12 +56,12 @@ pos.y = lerpY.getValue(t); } } - + public void paint(Graphics2D g) { if (!active) return; - + Paint psave = g.getPaint(); AffineTransform tsave = g.getTransform(); Composite csave = g.getComposite(); diff -r 881deac2daf8 -r 4c0dec72e2f0 game/Engine.java --- 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 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) diff -r 881deac2daf8 -r 4c0dec72e2f0 game/IDMButton.java --- a/game/IDMButton.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/IDMButton.java Thu Nov 24 21:51:54 2011 +0200 @@ -21,7 +21,7 @@ FontMetrics metrics; String text; boolean active; - + public IDMButton(IDMPoint pos, int keyCode, Font font, String text) { super(pos); @@ -35,12 +35,12 @@ state = State.NORMAL; active = false; } - + public IDMButton(float x, float y, int keyCode, Font font, String text) { this(new IDMPoint(x, y), keyCode, font, text); } - + private static void loadImages() { if (imgUp != null && imgPressed != null) @@ -63,7 +63,7 @@ public void scale() { } - + public void paint(Graphics2D g) { BufferedImage img; @@ -82,7 +82,7 @@ if (metrics == null) metrics = g.getFontMetrics(font); - + int textWidth = metrics.stringWidth(text); g.drawImage(img, getScaledX() + xoffs, getScaledY() + yoffs, null); @@ -92,8 +92,8 @@ getScaledX() + xoffs + (getScaledWidth() - textWidth) / 2, getScaledY() + yoffs + getScaledHeight() / 2); } - - + + public boolean mousePressed(MouseEvent e) { state = State.PRESSED; diff -r 881deac2daf8 -r 4c0dec72e2f0 game/IDMContainer.java --- a/game/IDMContainer.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/IDMContainer.java Thu Nov 24 21:51:54 2011 +0200 @@ -23,7 +23,7 @@ iterated = 0; modified = false; } - + synchronized public void add(IDMWidget widget) { widget.setParent(this); @@ -35,7 +35,7 @@ else children.add(widget); } - + synchronized public void remove(IDMWidget widget) { widget.setParent(null); @@ -81,7 +81,7 @@ widget.paint(g); } } - + synchronized public boolean mousePressed(MouseEvent e) { try { diff -r 881deac2daf8 -r 4c0dec72e2f0 game/IDMPoint.java --- a/game/IDMPoint.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/IDMPoint.java Thu Nov 24 21:51:54 2011 +0200 @@ -7,7 +7,7 @@ public class IDMPoint { public float x, y; - + public IDMPoint(float x, float y) { this.x = x; diff -r 881deac2daf8 -r 4c0dec72e2f0 game/IDMWidget.java --- a/game/IDMWidget.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/IDMWidget.java Thu Nov 24 21:51:54 2011 +0200 @@ -13,7 +13,7 @@ IDMWidget parent; IDMPoint pos, size, scale; int keyCode; - + public IDMWidget() { keyCode = -1; @@ -43,7 +43,7 @@ public void add(IDMWidget widget) { } - + public void remove(IDMWidget widget) { } @@ -57,12 +57,12 @@ { this.pos = new IDMPoint(x, y); } - + public void setSize(IDMPoint size) { this.size = size; } - + public void setSize(float w, float h) { this.size = new IDMPoint(w, h); @@ -72,7 +72,7 @@ { this.scale = scale; } - + public void setScale(float x, float y) { this.setScale(new IDMPoint(x, y)); @@ -115,11 +115,11 @@ { return contains(where.x, where.y); } - + public void paint(Graphics2D g) { } - + public boolean mousePressed(MouseEvent e) { return false; @@ -156,7 +156,7 @@ else return false; } - + public void clicked() { } diff -r 881deac2daf8 -r 4c0dec72e2f0 game/Interpolate.java --- a/game/Interpolate.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/Interpolate.java Thu Nov 24 21:51:54 2011 +0200 @@ -16,7 +16,7 @@ this.end = end; this.steps = steps; } - + public float getValue(float step) { float n = step / steps; diff -r 881deac2daf8 -r 4c0dec72e2f0 game/Piece.java --- a/game/Piece.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/Piece.java Thu Nov 24 21:51:54 2011 +0200 @@ -13,7 +13,7 @@ public class Piece { public enum RotateDir { LEFT, RIGHT } - + static final int numConnections = 8; static final float maxTime = 50.0f; @@ -47,7 +47,7 @@ typeChanged = false; typeActive = false; - + throbTime = 0; lerpType = new Interpolate(1.0f, 0.0f, maxTime); @@ -83,7 +83,7 @@ { typeChanged = true; } - + public void setType(PieceType ptype) { // typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED); @@ -116,7 +116,7 @@ if (point < 0) point = 8 + point; return point; } - + public int getMatchingPoint(int point) { switch (point) @@ -152,10 +152,10 @@ { return (float) ((rotation * Math.PI) / 2.0f); } - + public void rotate(RotateDir dir) { - // Only normal + // Only normal if (type != PieceType.LOCKED && type != PieceType.ACTIVE) return; @@ -168,7 +168,7 @@ { float ox = 0, oy = 0; float step = dim / 10; - + switch (index) { // Normal line starting and ending points case 0: ox = 3.0f; oy = 0.4f; break; @@ -200,7 +200,7 @@ return new Point2D.Float(x + ox * step, y + oy * step); } - + public PieceType getType() { return type; @@ -240,7 +240,7 @@ typeActive = true; typeChanged = false; } - + if (typeActive) { float t = (time - typeTime) * 2.0f; @@ -253,11 +253,11 @@ typeActive = false; } } - + if (stateChanged) { } - + throbTime = (time % 100) / 100.0f; } @@ -340,7 +340,7 @@ drawn[i] = true; drawn[connections[i]] = true; } - + } // !PieceType.START g.setTransform(save); diff -r 881deac2daf8 -r 4c0dec72e2f0 game/ResourceLoader.java --- a/game/ResourceLoader.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/ResourceLoader.java Thu Nov 24 21:51:54 2011 +0200 @@ -21,15 +21,15 @@ resourceURL = getClass().getClassLoader().getResource(name); if (resourceURL != null) stream = getClass().getClassLoader().getResourceAsStream(name); - + System.out.print("ResourceLoader('"+ name +"'): "+ resourceURL +" - "+ stream +"\n"); } - + public InputStream getStream() { return stream; } - + public URL getURL() { return resourceURL; diff -r 881deac2daf8 -r 4c0dec72e2f0 game/SoundManager.java --- a/game/SoundManager.java Thu Nov 24 21:50:41 2011 +0200 +++ b/game/SoundManager.java Thu Nov 24 21:51:54 2011 +0200 @@ -35,9 +35,9 @@ super("SoundManagerPool-" + (poolID++)); int numThreads = Math.min(maxSounds, getMaxSimultaneousSounds(playbackFormat)); - + System.out.print("SMGR.SoundManager() initializing with " + numThreads +" max sounds\n"); - + setDaemon(true); alive = true; @@ -250,7 +250,7 @@ // create, open, and start the line SourceDataLine line; DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat); - + System.out.print("SMGR.threadStarted(): "+lineInfo.toString()+"\n"); try { @@ -264,7 +264,7 @@ Thread.currentThread().interrupt(); return; } - + // Change volume Control.Type ct = FloatControl.Type.MASTER_GAIN; if (line.isControlSupported(ct)) @@ -310,7 +310,7 @@ // get line and buffer from ThreadLocals SourceDataLine line = (SourceDataLine) localLine.get(); byte[] buffer = (byte[])localBuffer.get(); - + if (line == null || buffer == null) return; @@ -330,7 +330,7 @@ } } } - + // copy data int bufPos = 0; while (bufPos < buffer.length && playing)