Mercurial > hg > ristipolku
diff game/Piece.java @ 9:a7751971c2a3
More work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 29 Jan 2011 00:30:00 +0200 |
parents | 70714c229e23 |
children | 4bacc98973f5 |
line wrap: on
line diff
--- a/game/Piece.java Fri Jan 28 22:21:45 2011 +0200 +++ b/game/Piece.java Sat Jan 29 00:30:00 2011 +0200 @@ -13,14 +13,16 @@ public class Piece { static final int numConnections = 8; - static final int minRotation = 0; - static final int maxRotation = 3; + static final float maxTime = 50.0f; + int currRotation; int[] connections; + boolean[] active; PieceType type, oldType; boolean rotationChanged, rotationActive, - typeChanged, typeActive; + typeChanged, typeActive, + activeChanged, activeActive; float currAngle, newAngle, rotationTime, typeTime; float throb; @@ -30,6 +32,7 @@ { // Initialize connections = new int[numConnections]; + active = new boolean[numConnections]; type = ptype; rotationChanged = false; @@ -86,16 +89,11 @@ if (type != PieceType.LOCKED && type != PieceType.ACTIVE) return; - currRotation = currRotation + (dir ? 1 : -1); + currRotation = currRotation + (dir ? -1 : 1); + newAngle = (float) (currRotation * Math.PI) / 2.0f; - if (currRotation < minRotation) - currRotation = maxRotation; - else if (currRotation > maxRotation) - currRotation = minRotation; - - newAngle = (float) (currRotation * Math.PI) / 2.0f; rotationChanged = true; - lerpRotation = new Interpolate(currAngle, newAngle, 100); + lerpRotation = new Interpolate(currAngle, newAngle, maxTime); } public Point2D getPointCoords(float x, float y, float dim, int index) @@ -119,6 +117,12 @@ return new Point2D.Float(x + ox * step, y + oy * step); } + public void setActiveConnection(int index) + { + active[index] = true; + activeChanged = true; + } + public void animate(float time) { if (rotationChanged) @@ -130,9 +134,9 @@ if (rotationActive) { - float t = (time - rotationTime) / 10.0f; + float t = (time - rotationTime); - if (t < 100) + if (t < maxTime) currAngle = lerpRotation.getValue(t); else { @@ -152,7 +156,12 @@ { } - throb = ((time / 10.0f) % 100) / 100.0f; + if (activeChanged) + { + + } + + throb = (time % 100) / 100.0f; } public void paint(Graphics2D g, float x, float y, float dim) @@ -161,6 +170,9 @@ tf.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; case ACTIVE: g.setPaint(Color.red); break; @@ -183,20 +195,25 @@ g.draw(new RoundRectangle2D.Float(x - throb * 10.0f, y - throb * 10.0f, dim + throb * 20.0f, dim + throb * 20.0f, dim / 10, dim / 10)); } + g.setPaint(Color.black); g.setStroke(new BasicStroke(6.0f)); // CubicCurve2D c = new CubicCurve2D.Float(); QuadCurve2D c = new QuadCurve2D.Float(); - - for (int i = 0; i < numConnections / 2; i++) + boolean[] drawn = new boolean[numConnections]; + for (int i = 0; i < numConnections; i++) + if (!drawn[i]) { Point2D start, cp1, cp2, end; - + start = getPointCoords(x, y, dim, i); end = getPointCoords(x, y, dim, connections[i]); cp1 = getPointCoords(x, y, dim, -1); - c.setCurve(start, cp1, end); - g.draw(c); + c.setCurve(start, cp1, end); + g.draw(c); + + drawn[i] = true; + drawn[connections[i]] = true; } } }