comparison game/Piece.java @ 134:4c0dec72e2f0

Whitespace cosmetic cleanup.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Nov 2011 21:51:54 +0200
parents 41c6cca69d60
children 9eb791e2fa17
comparison
equal deleted inserted replaced
133:881deac2daf8 134:4c0dec72e2f0
11 11
12 12
13 public class Piece 13 public class Piece
14 { 14 {
15 public enum RotateDir { LEFT, RIGHT } 15 public enum RotateDir { LEFT, RIGHT }
16 16
17 static final int numConnections = 8; 17 static final int numConnections = 8;
18 static final float maxTime = 50.0f; 18 static final float maxTime = 50.0f;
19 19
20 int currRotation; 20 int currRotation;
21 int[] connections; 21 int[] connections;
45 currRotation = 4 * 5000; 45 currRotation = 4 * 5000;
46 currAngle = getAngle(currRotation); 46 currAngle = getAngle(currRotation);
47 47
48 typeChanged = false; 48 typeChanged = false;
49 typeActive = false; 49 typeActive = false;
50 50
51 throbTime = 0; 51 throbTime = 0;
52 52
53 lerpType = new Interpolate(1.0f, 0.0f, maxTime); 53 lerpType = new Interpolate(1.0f, 0.0f, maxTime);
54 54
55 // Initialize connections between endpoints of the paths inside the piece 55 // Initialize connections between endpoints of the paths inside the piece
81 81
82 public void changed() 82 public void changed()
83 { 83 {
84 typeChanged = true; 84 typeChanged = true;
85 } 85 }
86 86
87 public void setType(PieceType ptype) 87 public void setType(PieceType ptype)
88 { 88 {
89 // typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED); 89 // typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED);
90 prevType = type; 90 prevType = type;
91 type = ptype; 91 type = ptype;
114 { 114 {
115 int point = (in + (getRotation() * 2)) % 8; 115 int point = (in + (getRotation() * 2)) % 8;
116 if (point < 0) point = 8 + point; 116 if (point < 0) point = 8 + point;
117 return point; 117 return point;
118 } 118 }
119 119
120 public int getMatchingPoint(int point) 120 public int getMatchingPoint(int point)
121 { 121 {
122 switch (point) 122 switch (point)
123 { 123 {
124 case 0: return 5; 124 case 0: return 5;
150 150
151 private float getAngle(float rotation) 151 private float getAngle(float rotation)
152 { 152 {
153 return (float) ((rotation * Math.PI) / 2.0f); 153 return (float) ((rotation * Math.PI) / 2.0f);
154 } 154 }
155 155
156 public void rotate(RotateDir dir) 156 public void rotate(RotateDir dir)
157 { 157 {
158 // Only normal 158 // Only normal
159 if (type != PieceType.LOCKED && type != PieceType.ACTIVE) 159 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
160 return; 160 return;
161 161
162 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)); 162 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1));
163 lerpRotation = new Interpolate(getAngle(currRotation), currAngle, maxTime); 163 lerpRotation = new Interpolate(getAngle(currRotation), currAngle, maxTime);
166 166
167 public Point2D getPointCoords(float x, float y, float dim, int index) 167 public Point2D getPointCoords(float x, float y, float dim, int index)
168 { 168 {
169 float ox = 0, oy = 0; 169 float ox = 0, oy = 0;
170 float step = dim / 10; 170 float step = dim / 10;
171 171
172 switch (index) { 172 switch (index) {
173 // Normal line starting and ending points 173 // Normal line starting and ending points
174 case 0: ox = 3.0f; oy = 0.4f; break; 174 case 0: ox = 3.0f; oy = 0.4f; break;
175 case 1: ox = 7.0f; oy = 0.4f; break; 175 case 1: ox = 7.0f; oy = 0.4f; break;
176 176
198 case 15: ox = 2.5f; oy = 3.0f; break; 198 case 15: ox = 2.5f; oy = 3.0f; break;
199 } 199 }
200 200
201 return new Point2D.Float(x + ox * step, y + oy * step); 201 return new Point2D.Float(x + ox * step, y + oy * step);
202 } 202 }
203 203
204 public PieceType getType() 204 public PieceType getType()
205 { 205 {
206 return type; 206 return type;
207 } 207 }
208 208
238 { 238 {
239 typeTime = time; 239 typeTime = time;
240 typeActive = true; 240 typeActive = true;
241 typeChanged = false; 241 typeChanged = false;
242 } 242 }
243 243
244 if (typeActive) 244 if (typeActive)
245 { 245 {
246 float t = (time - typeTime) * 2.0f; 246 float t = (time - typeTime) * 2.0f;
247 247
248 if (t < maxTime) 248 if (t < maxTime)
251 { 251 {
252 typeValue = lerpType.start; 252 typeValue = lerpType.start;
253 typeActive = false; 253 typeActive = false;
254 } 254 }
255 } 255 }
256 256
257 if (stateChanged) 257 if (stateChanged)
258 { 258 {
259 } 259 }
260 260
261 throbTime = (time % 100) / 100.0f; 261 throbTime = (time % 100) / 100.0f;
262 } 262 }
263 263
264 public void paint(Graphics2D g, float x, float y, float dim) 264 public void paint(Graphics2D g, float x, float y, float dim)
265 { 265 {
338 338
339 // Mark connection drawn, so we don't overdraw 339 // Mark connection drawn, so we don't overdraw
340 drawn[i] = true; 340 drawn[i] = true;
341 drawn[connections[i]] = true; 341 drawn[connections[i]] = true;
342 } 342 }
343 343
344 } // !PieceType.START 344 } // !PieceType.START
345 345
346 g.setTransform(save); 346 g.setTransform(save);
347 g.setComposite(csave); 347 g.setComposite(csave);
348 } 348 }