comparison game/Piece.java @ 149:35374be74fdc

Add some bling to piece rotation.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 28 May 2012 16:46:54 +0300
parents 9eb791e2fa17
children d6d92845d6a2
comparison
equal deleted inserted replaced
148:5b25561855c3 149:35374be74fdc
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; 31 typeTime, typeValue, throbTime, currScale;
32 32
33 Interpolate lerpRotation, 33 Interpolate lerpRotation,
34 lerpScale,
34 lerpType; 35 lerpType;
35 36
36 37
37 public Piece(PieceType ptype) 38 public Piece(PieceType ptype)
38 { 39 {
43 44
44 rotationChanged = false; 45 rotationChanged = false;
45 rotationActive = false; 46 rotationActive = false;
46 currRotation = 4 * 5000; 47 currRotation = 4 * 5000;
47 currAngle = getAngle(currRotation); 48 currAngle = getAngle(currRotation);
49 currScale = 1;
48 50
49 typeChanged = false; 51 typeChanged = false;
50 typeActive = false; 52 typeActive = false;
51 53
52 throbTime = 0; 54 throbTime = 0;
53 55
54 lerpType = new Interpolate(1.0f, 0.0f, maxTime); 56 lerpType = new Interpolate(1.0f, 0.0f, maxTime);
57 lerpScale = new Interpolate(0.0f, (float) Math.PI, maxTime);
55 58
56 // Initialize connections between endpoints of the paths inside the piece 59 // Initialize connections between endpoints of the paths inside the piece
57 for (int i = 0; i < numConnections; i++) 60 for (int i = 0; i < numConnections; i++)
58 connections[i] = -1; 61 connections[i] = -1;
59 62
227 if (rotationActive) 230 if (rotationActive)
228 { 231 {
229 float t = (time - rotationTime) * rotationSpeed; 232 float t = (time - rotationTime) * rotationSpeed;
230 233
231 if (t < maxTime) 234 if (t < maxTime)
235 {
232 currAngle = lerpRotation.getValue(t); 236 currAngle = lerpRotation.getValue(t);
237 currScale = (float) (1.0 + Math.sin(lerpScale.getValue(t)) * 0.25);
238 }
233 else 239 else
234 { 240 {
235 currAngle = lerpRotation.start; 241 currAngle = lerpRotation.start;
236 rotationActive = false; 242 rotationActive = false;
237 } 243 }
271 277
272 public void paint(Graphics2D g, float x, float y, float dim) 278 public void paint(Graphics2D g, float x, float y, float dim)
273 { 279 {
274 AffineTransform save = g.getTransform(); 280 AffineTransform save = g.getTransform();
275 Composite csave = g.getComposite(); 281 Composite csave = g.getComposite();
282
283 // Scale dimensions
284 dim = dim * currScale;
276 285
277 // Change compositing alpha for the whole piece drawing 286 // Change compositing alpha for the whole piece drawing
278 // when the piece is being "introduced". 287 // when the piece is being "introduced".
279 if (typeActive) 288 if (typeActive)
280 { 289 {