comparison game/Piece.java @ 26:3d4cc47df31a

Cleanups, fix piece rendering and rotation.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 01 Feb 2011 19:18:25 +0200
parents df494a65bf8c
children 26adc2827983
comparison
equal deleted inserted replaced
25:bbac3e4a4b9b 26:3d4cc47df31a
48 48
49 // Initialize connections between endpoints of the paths inside the piece 49 // Initialize connections between endpoints of the paths inside the piece
50 for (int i = 0; i < numConnections; i++) 50 for (int i = 0; i < numConnections; i++)
51 connections[i] = -1; 51 connections[i] = -1;
52 52
53
53 // Randomize connections in the piece 54 // Randomize connections in the piece
54 Random rnd = new Random(); 55 Random rnd = new Random();
55 for (int i = 0; i < numConnections; i++) 56 for (int i = 0; i < numConnections; i++)
56 { 57 {
57 while (connections[i] < 0) 58 while (connections[i] < 0)
58 { 59 {
59 int tmp = rnd.nextInt(numConnections); 60 int tmp = rnd.nextInt(numConnections);
60 if (connections[tmp] < 0) 61 if (tmp != i && connections[tmp] < 0)
61 { 62 {
62 connections[i] = tmp; 63 connections[i] = tmp;
63 connections[tmp] = i; 64 connections[tmp] = i;
64 } 65 }
65 } 66 }
87 { 88 {
88 // Only normal 89 // Only normal
89 if (type != PieceType.LOCKED && type != PieceType.ACTIVE) 90 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
90 return; 91 return;
91 92
92 currRotation = (currRotation + (dir ? -1 : 1)) % 4; 93 currRotation = (currRotation + (dir ? 1 : -1)) % 4;
93 newAngle = (float) ((currRotation * Math.PI) / 2.0f); 94 newAngle = (float) ((currRotation * Math.PI) / 2.0f);
94 lerpRotation = new Interpolate(currAngle, newAngle, maxTime); 95 lerpRotation = new Interpolate(newAngle, currAngle, maxTime);
95 rotationChanged = true; 96 rotationChanged = true;
96 } 97 }
97 98
98 public Point2D getPointCoords(float x, float y, float dim, int index) 99 public Point2D getPointCoords(float x, float y, float dim, int index)
99 { 100 {
162 throb = (time % 100) / 100.0f; 163 throb = (time % 100) / 100.0f;
163 } 164 }
164 165
165 public void paint(Graphics2D g, float x, float y, float dim) 166 public void paint(Graphics2D g, float x, float y, float dim)
166 { 167 {
167 // AffineTransform tf = new AffineTransform();
168 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); 168 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
169 // g.transform(tf);
170
171 // if (type == PieceType.ACTIVE) System.out.print("angle = " + currAngle + "\n");
172 169
173 switch (type) { 170 switch (type) {
174 case LOCKED: g.setPaint(Color.green); break; 171 case LOCKED: g.setPaint(Color.green); break;
175 case ACTIVE: g.setPaint(Color.red); break; 172 case ACTIVE: g.setPaint(Color.red); break;
176 case START: g.setPaint(Color.orange); break; 173 case START: g.setPaint(Color.orange); break;