# HG changeset patch # User Matti Hamalainen # Date 1296580705 -7200 # Node ID 3d4cc47df31a8c11b3e65b4284dd53e6cd84efa7 # Parent bbac3e4a4b9baba68d84a9dd21a1a89c806795b1 Cleanups, fix piece rendering and rotation. diff -r bbac3e4a4b9b -r 3d4cc47df31a Makefile --- a/Makefile Tue Feb 01 18:05:19 2011 +0200 +++ b/Makefile Tue Feb 01 19:18:25 2011 +0200 @@ -3,7 +3,7 @@ RESOURCES=graphics/*.png graphics/*.jpg graphics/font.ttf sounds/*.wav -CLASSES=game/Piece.java game/PieceType.java game/Engine.java game/Interpolate.java game/ResourceLoader.java +CLASSES=game/Piece.class game/PieceType.class game/Engine.class game/Interpolate.class game/ResourceLoader.class # Utils JAVAC=javac -g @@ -16,6 +16,8 @@ all: $(TARGETS) +game/%.class: game/%.java + $(JAVAC) $< Ristipolku.class: Ristipolku.java $(CLASSES) $(JAVAC) $< @@ -29,7 +31,7 @@ ### Package ### Ristipolku.jar: $(RUN) $(CLASSES) $(RESOURCES) - jar cvfm $@ manifest.txt $(RUN) game/*.class $(RESOURCES) + jar cvfm $@ manifest.txt $+ upload: Ristipolku.jar diff -r bbac3e4a4b9b -r 3d4cc47df31a game/Engine.java --- a/game/Engine.java Tue Feb 01 18:05:19 2011 +0200 +++ b/game/Engine.java Tue Feb 01 19:18:25 2011 +0200 @@ -365,6 +365,7 @@ public void keyPressed(KeyEvent e) { + // Handle keyboard input switch (e.getKeyCode()) { case KeyEvent.VK_LEFT: @@ -389,20 +390,23 @@ { while (animEnable) { + // Progress game animation clock gameClock++; + // Animate components lauta.animate(gameClock); + // Repaint with a frame limiter if (gameClock % 3 == 1) { repaint(); gameFrames++; } - + + // Sleep for a moment try { Thread.sleep(10); } - catch (InterruptedException x) { } } diff -r bbac3e4a4b9b -r 3d4cc47df31a game/Piece.java --- a/game/Piece.java Tue Feb 01 18:05:19 2011 +0200 +++ b/game/Piece.java Tue Feb 01 19:18:25 2011 +0200 @@ -50,6 +50,7 @@ for (int i = 0; i < numConnections; i++) connections[i] = -1; + // Randomize connections in the piece Random rnd = new Random(); for (int i = 0; i < numConnections; i++) @@ -57,7 +58,7 @@ while (connections[i] < 0) { int tmp = rnd.nextInt(numConnections); - if (connections[tmp] < 0) + if (tmp != i && connections[tmp] < 0) { connections[i] = tmp; connections[tmp] = i; @@ -89,9 +90,9 @@ if (type != PieceType.LOCKED && type != PieceType.ACTIVE) return; - currRotation = (currRotation + (dir ? -1 : 1)) % 4; + currRotation = (currRotation + (dir ? 1 : -1)) % 4; newAngle = (float) ((currRotation * Math.PI) / 2.0f); - lerpRotation = new Interpolate(currAngle, newAngle, maxTime); + lerpRotation = new Interpolate(newAngle, currAngle, maxTime); rotationChanged = true; } @@ -164,11 +165,7 @@ public void paint(Graphics2D g, float x, float y, float dim) { -// AffineTransform tf = new AffineTransform(); g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); -// g.transform(tf); - -// if (type == PieceType.ACTIVE) System.out.print("angle = " + currAngle + "\n"); switch (type) { case LOCKED: g.setPaint(Color.green); break;