Mercurial > hg > ristipolku
changeset 26:3d4cc47df31a
Cleanups, fix piece rendering and rotation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 01 Feb 2011 19:18:25 +0200 |
parents | bbac3e4a4b9b |
children | 26adc2827983 |
files | Makefile game/Engine.java game/Piece.java |
diffstat | 3 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- 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
--- 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) { } }
--- 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;