comparison game/Piece.java @ 153:71205451ef57

Remove scaling.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 11 Apr 2013 20:17:13 +0300
parents 64b04c0eccce
children
comparison
equal deleted inserted replaced
152:64b04c0eccce 153:71205451ef57
26 typeChanged, typeActive, 26 typeChanged, typeActive,
27 stateChanged, stateActive, 27 stateChanged, stateActive,
28 active; 28 active;
29 29
30 float currAngle, rotationTime, rotationSpeed, 30 float currAngle, rotationTime, rotationSpeed,
31 typeTime, typeValue, throbTime, currScale; 31 typeTime, typeValue, throbTime;
32 32
33 Interpolate lerpRotation, 33 Interpolate lerpRotation,
34 lerpScale, 34 lerpScale,
35 lerpType; 35 lerpType;
36 36
44 44
45 rotationChanged = false; 45 rotationChanged = false;
46 rotationActive = false; 46 rotationActive = false;
47 currRotation = 4 * 5000; 47 currRotation = 4 * 5000;
48 currAngle = getAngle(currRotation); 48 currAngle = getAngle(currRotation);
49 currScale = 1;
50 49
51 typeChanged = false; 50 typeChanged = false;
52 typeActive = false; 51 typeActive = false;
53 52
54 throbTime = 0; 53 throbTime = 0;
232 float t = (time - rotationTime) * rotationSpeed; 231 float t = (time - rotationTime) * rotationSpeed;
233 232
234 if (t < maxTime) 233 if (t < maxTime)
235 { 234 {
236 currAngle = lerpRotation.getValue(t); 235 currAngle = lerpRotation.getValue(t);
237 currScale = (float) (1.0 + Math.sin(lerpScale.getValue(t)) * 0.25);
238 } 236 }
239 else 237 else
240 { 238 {
241 currAngle = lerpRotation.start; 239 currAngle = lerpRotation.start;
242 currScale = 1;
243 rotationActive = false; 240 rotationActive = false;
244 } 241 }
245 242
246 active = true; 243 active = true;
247 } 244 }
258 float t = (time - typeTime) * 2.0f; 255 float t = (time - typeTime) * 2.0f;
259 256
260 if (t < maxTime) 257 if (t < maxTime)
261 { 258 {
262 typeValue = lerpType.getValue(t); 259 typeValue = lerpType.getValue(t);
263 if (!rotationActive)
264 currScale = (float) (1.0 + Math.sin(lerpScale.getValue(t)) * 0.1);
265 } 260 }
266 else 261 else
267 { 262 {
268 typeValue = lerpType.start; 263 typeValue = lerpType.start;
269 if (!rotationActive)
270 currScale = 1;
271 typeActive = false; 264 typeActive = false;
272 } 265 }
273 266
274 267
275 active = true; 268 active = true;
296 } 289 }
297 290
298 291
299 // Transform drawing by current angle 292 // Transform drawing by current angle
300 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); 293 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
301
302 // Scale dimensions
303 dim = dim * currScale;
304 294
305 // Color piece by type 295 // Color piece by type
306 switch (type) { 296 switch (type) {
307 case LOCKED: g.setPaint(new Color(0.3f, 0.8f, 0.3f, 0.35f)); break; 297 case LOCKED: g.setPaint(new Color(0.3f, 0.8f, 0.3f, 0.35f)); break;
308 case ACTIVE: g.setPaint(new Color(0.9f, 0.3f, 0.3f, 0.35f)); break; 298 case ACTIVE: g.setPaint(new Color(0.9f, 0.3f, 0.3f, 0.35f)); break;
309 case START: g.setPaint(new Color(1.0f, 0.6f, 0.0f, 0.95f)); break; 299 case START: g.setPaint(new Color(1.0f, 0.6f, 0.0f, 0.95f)); break;
310 } 300 }
311 301
312 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); 302 float corner = dim / 10.0f;
303 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, corner, corner));
313 304
314 // Start pieces (center piece) have a different kind of border 305 // Start pieces (center piece) have a different kind of border
315 // and no connections drawn inside 306 // and no connections drawn inside
316 if (type == PieceType.START) 307 if (type == PieceType.START)
317 { 308 {
318 // Draw piece border 309 // Draw piece border
319 g.setPaint(Color.black); 310 g.setPaint(Color.black);
320 g.setStroke(new BasicStroke(2.0f)); 311 g.setStroke(new BasicStroke(2.0f));
321 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); 312 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, corner, corner));
322 } 313 }
323 else 314 else
324 { 315 {
325 // Active piece has a throbbing "ghost" border 316 // Active piece has a throbbing "ghost" border
326 if (type == PieceType.ACTIVE) 317 if (type == PieceType.ACTIVE)
331 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) )); 322 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
332 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f)); 323 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
333 g.draw(new RoundRectangle2D.Float( 324 g.draw(new RoundRectangle2D.Float(
334 x - offs1, y - offs1, 325 x - offs1, y - offs1,
335 dim + offs2, dim + offs2, 326 dim + offs2, dim + offs2,
336 dim / 10, dim / 10)); 327 corner, corner));
337 } 328 }
338 329
339 // Draw piece border 330 // Draw piece border
340 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f)); 331 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f));
341 g.setStroke(new BasicStroke(5.0f)); 332 g.setStroke(new BasicStroke(5.0f));