# HG changeset patch # User Matti Hamalainen # Date 1296750136 -7200 # Node ID e480579cc4609069d7f7b63a1e61913e8cddca9b # Parent 8dbc79294106874afabc0c049f49b1053051fa77 More work on debugging the path resolving. diff -r 8dbc79294106 -r e480579cc460 game/Engine.java --- a/game/Engine.java Thu Feb 03 00:00:09 2011 +0200 +++ b/game/Engine.java Thu Feb 03 18:22:16 2011 +0200 @@ -95,6 +95,8 @@ class IDMButton { + BufferedImage imgUp, imgPressed; + public IDMButton(float x, float y, String text) { } @@ -167,7 +169,7 @@ return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); } - public void pieceRotate(boolean dir) + public void pieceRotate(Piece.RotateDir dir) { if (current != null) current.rotate(dir); @@ -279,6 +281,8 @@ SoundElement[] sounds; + Piece testi; int con = 0; + public SoundElement snd(Sound snd) { return sounds[snd.ordinal()]; @@ -293,6 +297,8 @@ gameFrames = 0; startTime = new Date().getTime(); + testi = new Piece(PieceType.LOCKED); + // Load resources try @@ -374,6 +380,8 @@ g2.drawImage(lautaBGScaled, 0, 0, null); lauta.paint(g2, 100, 150, 60); + testi.paint(g2, 50f,50f,100f); + // Scores g2.setFont(font1); g2.setPaint(Color.white); @@ -381,7 +389,9 @@ // Other elements long currTime = new Date().getTime(); - g2.drawString("fps = "+ ((currTime - startTime) / gameFrames), dim.width - 120, 20); + g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); + + g2.drawString("con = "+ con, 20, 30); } public void startThreads() @@ -442,12 +452,12 @@ { case KeyEvent.VK_LEFT: case KeyEvent.VK_UP: - lauta.pieceRotate(false); + lauta.pieceRotate(Piece.RotateDir.LEFT); break; case KeyEvent.VK_RIGHT: case KeyEvent.VK_DOWN: - lauta.pieceRotate(true); + lauta.pieceRotate(Piece.RotateDir.RIGHT); break; case KeyEvent.VK_ENTER: @@ -474,6 +484,11 @@ repaint(); gameFrames++; } + + // debugataan + con = ((int) (gameClock / 100)) & 7; + testi.clearActiveConnections(); + testi.setActiveConnection(con); // Sleep for a moment try { diff -r 8dbc79294106 -r e480579cc460 game/Piece.java --- a/game/Piece.java Thu Feb 03 00:00:09 2011 +0200 +++ b/game/Piece.java Thu Feb 03 18:22:16 2011 +0200 @@ -12,22 +12,27 @@ public class Piece { + public enum RotateDir { LEFT, RIGHT } + static final int numConnections = 8; static final float maxTime = 50.0f; int currRotation; int[] connections; boolean[] active; - PieceType type, oldType; + PieceType type, prevType; boolean rotationChanged, rotationActive, typeChanged, typeActive, activeChanged, activeActive; float currAngle, newAngle, rotationTime, typeTime; - float throb; + float throbTime; Interpolate lerpRotation; + int point; + + public Piece(PieceType ptype) { // Initialize @@ -43,7 +48,7 @@ typeChanged = false; typeActive = false; - throb = 0; + throbTime = 0; // Initialize connections between endpoints of the paths inside the piece @@ -74,8 +79,8 @@ public void setType(PieceType ptype) { - typeChanged = (oldType != ptype); - oldType = type; + typeChanged = (prevType != ptype); + prevType = type; type = ptype; } @@ -83,14 +88,14 @@ { return connections[(in + (currRotation * 2)) % 8]; } - - public void rotate(boolean dir) + + public void rotate(RotateDir dir) { // Only normal if (type != PieceType.LOCKED && type != PieceType.ACTIVE) return; - currRotation = (currRotation + (dir ? 1 : -1)) % 4; + currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)) % 4; newAngle = (float) ((currRotation * Math.PI) / 2.0f); lerpRotation = new Interpolate(newAngle, currAngle, maxTime); rotationChanged = true; @@ -102,25 +107,41 @@ float step = dim / 10; switch (index) { - case 0: ox = 3.0f; oy = 0.5f; break; - case 1: ox = 7.0f; oy = 0.5f; break; - case 2: ox = 9.5f; oy = 3.0f; break; - case 3: ox = 9.5f; oy = 7.0f; break; - case 4: ox = 7.0f; oy = 9.5f; break; - case 5: ox = 3.0f; oy = 9.5f; break; - case 6: ox = 0.5f; oy = 7.0f; break; - case 7: ox = 0.5f; oy = 3.0f; break; + case 0: ox = 3.0f; oy = 0.4f; break; + case 1: ox = 7.0f; oy = 0.4f; break; + case 2: ox = 9.6f; oy = 3.0f; break; + case 3: ox = 9.6f; oy = 7.0f; break; + case 4: ox = 7.0f; oy = 9.6f; break; + case 5: ox = 3.0f; oy = 9.6f; break; + case 6: ox = 0.4f; oy = 7.0f; break; + case 7: ox = 0.4f; oy = 3.0f; break; - case -1: ox = 5.0f; oy = 5.0f; break; + case 8: ox = 3.0f; oy = 3.0f; break; + case 9: ox = 7.0f; oy = 3.0f; break; + case 10: ox = 7.0f; oy = 3.0f; break; + case 11: ox = 7.0f; oy = 7.0f; break; + case 12: ox = 7.0f; oy = 7.0f; break; + case 13: ox = 7.0f; oy = 7.0f; break; + case 14: ox = 3.0f; oy = 7.0f; break; + case 15: ox = 3.0f; oy = 3.0f; break; } return new Point2D.Float(x + ox * step, y + oy * step); } + + public void clearActiveConnections() + { + for (int i = 0; i < numConnections; i++) + active[i] = false; + + activeChanged = true; + } public void setActiveConnection(int index) { active[index] = true; active[connections[index]] = true; + activeChanged = true; } @@ -166,7 +187,7 @@ { } - throb = (time % 100) / 100.0f; + throbTime = (time % 100) / 100.0f; } public void paint(Graphics2D g, float x, float y, float dim) @@ -182,7 +203,7 @@ g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); g.setPaint(Color.black); - g.setStroke(new BasicStroke(4.0f)); + g.setStroke(new BasicStroke(5.0f)); g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); if (type == PieceType.START) @@ -190,31 +211,33 @@ if (type == PieceType.ACTIVE) { - float offs1 = throb * 10.0f, - offs2 = throb * 20.0f; + float offs1 = throbTime * 10.0f, + offs2 = throbTime * 20.0f; - g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throb) )); - g.setStroke(new BasicStroke(2.0f + throb * 2.0f)); + g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) )); + g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f)); g.draw(new RoundRectangle2D.Float(x - offs1, y - offs1, dim + offs2, dim + offs2, dim / 10, dim / 10)); } - g.setStroke(new BasicStroke(6.0f)); -// CubicCurve2D c = new CubicCurve2D.Float(); - QuadCurve2D c = new QuadCurve2D.Float(); + g.setStroke(new BasicStroke(5.0f)); + CubicCurve2D c = new CubicCurve2D.Float(); +// QuadCurve2D c = new QuadCurve2D.Float(); boolean[] drawn = new boolean[numConnections]; for (int i = 0; i < numConnections; i++) if (!drawn[i]) { Point2D start, cp1, cp2, end; - boolean act = active[i] || active[connections[i]]; - g.setPaint(act ? Color.white : Color.black); + boolean isActive = active[i] || active[connections[i]]; + g.setPaint(isActive ? Color.white : Color.black); start = getPointCoords(x, y, dim, i); end = getPointCoords(x, y, dim, connections[i]); - cp1 = getPointCoords(x, y, dim, -1); + + cp1 = getPointCoords(x, y, dim, i + 8); + cp2 = getPointCoords(x, y, dim, connections[i] + 8); - c.setCurve(start, cp1, end); + c.setCurve(start, cp1, cp2, end); g.draw(c); drawn[i] = true;