comparison game/Piece.java @ 45:79185dababf2

Add comments.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 22 Feb 2011 06:30:11 +0200
parents 9664bbb9d613
children cc7943cd7f2d
comparison
equal deleted inserted replaced
44:698c6bcc4aec 45:79185dababf2
228 throbTime = (time % 100) / 100.0f; 228 throbTime = (time % 100) / 100.0f;
229 } 229 }
230 230
231 public void paint(Graphics2D g, float x, float y, float dim) 231 public void paint(Graphics2D g, float x, float y, float dim)
232 { 232 {
233 // Transform drawing by current angle
233 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); 234 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
234 235
236 // Color piece by type
235 switch (type) { 237 switch (type) {
236 case LOCKED: g.setPaint(Color.green); break; 238 case LOCKED: g.setPaint(Color.green); break;
237 case ACTIVE: g.setPaint(Color.red); break; 239 case ACTIVE: g.setPaint(Color.red); break;
238 case START: g.setPaint(Color.orange); break; 240 case START: g.setPaint(Color.orange); break;
239 } 241 }
240 242
241 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); 243 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
242 244
243 245 // Start pieces (center piece) do not have border, etc.
244 if (type == PieceType.START) 246 if (type == PieceType.START)
245 return; 247 return;
246 248
249 // Active piece has a throbbing "ghost" border
247 if (type == PieceType.ACTIVE) 250 if (type == PieceType.ACTIVE)
248 { 251 {
249 float offs1 = throbTime * 10.0f, 252 float offs1 = throbTime * 10.0f,
250 offs2 = throbTime * 20.0f; 253 offs2 = throbTime * 20.0f;
251 254
252 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) )); 255 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
253 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f)); 256 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
254 g.draw(new RoundRectangle2D.Float(x - offs1, y - offs1, dim + offs2, dim + offs2, dim / 10, dim / 10)); 257 g.draw(new RoundRectangle2D.Float(
255 } 258 x - offs1, y - offs1,
256 259 dim + offs2, dim + offs2,
260 dim / 10, dim / 10));
261 }
262
263 // Draw the connections
257 g.setStroke(new BasicStroke(5.0f)); 264 g.setStroke(new BasicStroke(5.0f));
258 CubicCurve2D c = new CubicCurve2D.Float(); 265 CubicCurve2D c = new CubicCurve2D.Float();
259 // QuadCurve2D c = new QuadCurve2D.Float();
260 boolean[] drawn = new boolean[numConnections]; 266 boolean[] drawn = new boolean[numConnections];
261 for (int i = 0; i < numConnections; i++) 267 for (int i = 0; i < numConnections; i++)
262 if (!drawn[i]) 268 if (!drawn[i])
263 { 269 {
264 Point2D start, cp1, cp2, end; 270 Point2D start, cp1, cp2, end;
273 cp2 = getPointCoords(x, y, dim, connections[i] + 8); 279 cp2 = getPointCoords(x, y, dim, connections[i] + 8);
274 280
275 c.setCurve(start, cp1, cp2, end); 281 c.setCurve(start, cp1, cp2, end);
276 g.draw(c); 282 g.draw(c);
277 283
284 // Mark connection drawn, so we don't overdraw
278 drawn[i] = true; 285 drawn[i] = true;
279 drawn[connections[i]] = true; 286 drawn[connections[i]] = true;
280 } 287 }
281 288
289 // Draw piece border
282 g.setPaint(Color.black); 290 g.setPaint(Color.black);
283 g.setStroke(new BasicStroke(5.0f)); 291 g.setStroke(new BasicStroke(5.0f));
284 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); 292 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
285 } 293 }
286 } 294 }