Mercurial > hg > ristipolku
annotate game/Piece.java @ 129:a0376e40102e
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 24 Nov 2011 21:09:57 +0200 |
parents | 41c6cca69d60 |
children | 4c0dec72e2f0 |
rev | line source |
---|---|
1 | 1 /* |
2 * Ristipolku | |
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org> | |
4 */ | |
5 package game; | |
6 | |
7 import java.awt.*; | |
7 | 8 import java.awt.geom.*; |
1 | 9 import java.util.*; |
6 | 10 import java.math.*; |
1 | 11 |
12 | |
13 public class Piece | |
14 { | |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
15 public enum RotateDir { LEFT, RIGHT } |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
16 |
3 | 17 static final int numConnections = 8; |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
18 static final float maxTime = 50.0f; |
9 | 19 |
3 | 20 int currRotation; |
21 int[] connections; | |
40 | 22 boolean[] states; |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
23 PieceType type, prevType; |
1 | 24 |
3 | 25 boolean rotationChanged, rotationActive, |
9 | 26 typeChanged, typeActive, |
40 | 27 stateChanged, stateActive; |
6 | 28 |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
29 float currAngle, rotationTime, rotationSpeed, |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
30 typeTime, typeValue, throbTime; |
91 | 31 |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
32 Interpolate lerpRotation, |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
33 lerpType; |
1 | 34 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
35 |
3 | 36 public Piece(PieceType ptype) |
37 { | |
38 // Initialize | |
39 connections = new int[numConnections]; | |
40 | 40 states = new boolean[numConnections]; |
3 | 41 type = ptype; |
1 | 42 |
3 | 43 rotationChanged = false; |
6 | 44 rotationActive = false; |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
45 currRotation = 4 * 5000; |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
46 currAngle = getAngle(currRotation); |
6 | 47 |
3 | 48 typeChanged = false; |
49 typeActive = false; | |
1 | 50 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
51 throbTime = 0; |
1 | 52 |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
53 lerpType = new Interpolate(1.0f, 0.0f, maxTime); |
1 | 54 |
3 | 55 // Initialize connections between endpoints of the paths inside the piece |
56 for (int i = 0; i < numConnections; i++) | |
57 connections[i] = -1; | |
1 | 58 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
59 |
6 | 60 // Randomize connections in the piece |
3 | 61 Random rnd = new Random(); |
62 for (int i = 0; i < numConnections; i++) | |
63 { | |
64 while (connections[i] < 0) | |
65 { | |
66 int tmp = rnd.nextInt(numConnections); | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
21
diff
changeset
|
67 if (tmp != i && connections[tmp] < 0) |
3 | 68 { |
69 connections[i] = tmp; | |
70 connections[tmp] = i; | |
71 } | |
72 } | |
73 } | |
74 } | |
75 | |
76 public Piece() | |
77 { | |
78 this(PieceType.NONE); | |
79 } | |
1 | 80 |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
81 |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
82 public void changed() |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
83 { |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
84 typeChanged = true; |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
85 } |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
86 |
3 | 87 public void setType(PieceType ptype) |
88 { | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
89 // typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED); |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
90 prevType = type; |
3 | 91 type = ptype; |
92 } | |
1 | 93 |
40 | 94 public void clearStates() |
95 { | |
96 for (int i = 0; i < numConnections; i++) | |
97 states[i] = false; | |
98 stateChanged = true; | |
99 } | |
100 | |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
101 public int getRotation() |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
102 { |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
103 return currRotation % 4; |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
104 } |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
105 |
40 | 106 public int getRotatedPoint(int in) |
3 | 107 { |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
108 int point = (in - (getRotation() * 2)) % 8; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
109 if (point < 0) point = 8 + point; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
110 return point; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
111 } |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
112 |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
113 public int getAntiRotatedPoint(int in) |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
114 { |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
115 int point = (in + (getRotation() * 2)) % 8; |
40 | 116 if (point < 0) point = 8 + point; |
117 return point; | |
118 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
119 |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
120 public int getMatchingPoint(int point) |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
121 { |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
122 switch (point) |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
123 { |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
124 case 0: return 5; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
125 case 1: return 4; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
126 |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
127 case 2: return 7; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
128 case 3: return 6; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
129 |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
130 case 4: return 1; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
131 case 5: return 0; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
132 |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
133 case 6: return 3; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
134 case 7: return 2; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
135 } |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
136 return -1; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
137 } |
37 | 138 |
40 | 139 public void setConnectionState(int point, boolean state) |
140 { | |
141 states[point] = state; | |
142 states[connections[point]] = state; | |
143 stateChanged = true; | |
144 } | |
145 | |
146 public int getConnection(int point) | |
147 { | |
148 return connections[point]; | |
3 | 149 } |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
150 |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
151 private float getAngle(float rotation) |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
152 { |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
153 return (float) ((rotation * Math.PI) / 2.0f); |
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
154 } |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
155 |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
156 public void rotate(RotateDir dir) |
3 | 157 { |
6 | 158 // Only normal |
159 if (type != PieceType.LOCKED && type != PieceType.ACTIVE) | |
3 | 160 return; |
1 | 161 |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
162 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)); |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
163 lerpRotation = new Interpolate(getAngle(currRotation), currAngle, maxTime); |
3 | 164 rotationChanged = true; |
5 | 165 } |
1 | 166 |
7 | 167 public Point2D getPointCoords(float x, float y, float dim, int index) |
5 | 168 { |
7 | 169 float ox = 0, oy = 0; |
170 float step = dim / 10; | |
1 | 171 |
5 | 172 switch (index) { |
34
6f6c551cc14c
Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
173 // Normal line starting and ending points |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
174 case 0: ox = 3.0f; oy = 0.4f; break; |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
175 case 1: ox = 7.0f; oy = 0.4f; break; |
39 | 176 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
177 case 2: ox = 9.6f; oy = 3.0f; break; |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
178 case 3: ox = 9.6f; oy = 7.0f; break; |
39 | 179 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
180 case 4: ox = 7.0f; oy = 9.6f; break; |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
181 case 5: ox = 3.0f; oy = 9.6f; break; |
39 | 182 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
183 case 6: ox = 0.4f; oy = 7.0f; break; |
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
184 case 7: ox = 0.4f; oy = 3.0f; break; |
1 | 185 |
39 | 186 |
34
6f6c551cc14c
Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
187 // Matching control points for each point above (+8) |
39 | 188 case 8: ox = 3.0f; oy = 2.5f; break; |
189 case 9: ox = 7.0f; oy = 2.5f; break; | |
190 | |
191 case 10: ox = 7.5f; oy = 3.0f; break; | |
192 case 11: ox = 7.5f; oy = 7.0f; break; | |
193 | |
194 case 12: ox = 7.0f; oy = 7.5f; break; | |
195 case 13: ox = 3.0f; oy = 7.5f; break; | |
196 | |
197 case 14: ox = 2.5f; oy = 7.0f; break; | |
198 case 15: ox = 2.5f; oy = 3.0f; break; | |
5 | 199 } |
1 | 200 |
7 | 201 return new Point2D.Float(x + ox * step, y + oy * step); |
5 | 202 } |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
203 |
27 | 204 public PieceType getType() |
205 { | |
206 return type; | |
207 } | |
9 | 208 |
7 | 209 public void animate(float time) |
5 | 210 { |
211 if (rotationChanged) | |
212 { | |
213 rotationTime = time; | |
214 rotationActive = true; | |
7 | 215 rotationChanged = false; |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
216 rotationSpeed = 1.0f; |
54 | 217 } |
218 | |
219 if (typeChanged && type == PieceType.LOCKED) | |
220 { | |
104
eb2e72dd8cae
Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
221 rotationSpeed = 1.5f; |
5 | 222 } |
1 | 223 |
5 | 224 if (rotationActive) |
225 { | |
54 | 226 float t = (time - rotationTime) * rotationSpeed; |
11 | 227 |
9 | 228 if (t < maxTime) |
7 | 229 currAngle = lerpRotation.getValue(t); |
230 else | |
231 { | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
232 currAngle = lerpRotation.start; |
7 | 233 rotationActive = false; |
234 } | |
5 | 235 } |
54 | 236 |
6 | 237 if (typeChanged) |
238 { | |
239 typeTime = time; | |
240 typeActive = true; | |
7 | 241 typeChanged = false; |
6 | 242 } |
243 | |
244 if (typeActive) | |
245 { | |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
246 float t = (time - typeTime) * 2.0f; |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
247 |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
248 if (t < maxTime) |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
249 typeValue = lerpType.getValue(t); |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
250 else |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
251 { |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
252 typeValue = lerpType.start; |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
253 typeActive = false; |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
254 } |
6 | 255 } |
256 | |
40 | 257 if (stateChanged) |
9 | 258 { |
259 } | |
260 | |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
261 throbTime = (time % 100) / 100.0f; |
5 | 262 } |
1 | 263 |
7 | 264 public void paint(Graphics2D g, float x, float y, float dim) |
5 | 265 { |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
266 AffineTransform save = g.getTransform(); |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
267 Composite csave = g.getComposite(); |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
268 |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
269 // Change compositing alpha for the whole piece drawing |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
270 // when the piece is being "introduced". |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
271 if (typeActive) |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
272 { |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
273 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, typeValue)); |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
274 } |
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
275 |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
276 |
45 | 277 // Transform drawing by current angle |
11 | 278 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f); |
1 | 279 |
45 | 280 // Color piece by type |
5 | 281 switch (type) { |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
282 case LOCKED: g.setPaint(new Color(0.3f, 0.8f, 0.3f, 0.35f)); break; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
283 case ACTIVE: g.setPaint(new Color(0.9f, 0.3f, 0.3f, 0.35f)); break; |
92
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
284 case START: g.setPaint(new Color(1.0f, 0.6f, 0.0f, 0.95f)); break; |
5 | 285 } |
6 | 286 |
7 | 287 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); |
1 | 288 |
92
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
289 // Start pieces (center piece) have a different kind of border |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
290 // and no connections drawn inside |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
291 if (type == PieceType.START) |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
292 { |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
293 // Draw piece border |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
294 g.setPaint(Color.black); |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
295 g.setStroke(new BasicStroke(2.0f)); |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
296 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
297 } |
d5f51370617b
Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
91
diff
changeset
|
298 else |
5 | 299 { |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
300 // Active piece has a throbbing "ghost" border |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
301 if (type == PieceType.ACTIVE) |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
302 { |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
303 float offs1 = throbTime * 10.0f, |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
304 offs2 = throbTime * 20.0f; |
27 | 305 |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
306 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) )); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
307 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f)); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
308 g.draw(new RoundRectangle2D.Float( |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
309 x - offs1, y - offs1, |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
310 dim + offs2, dim + offs2, |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
311 dim / 10, dim / 10)); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
312 } |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
313 |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
314 // Draw piece border |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
315 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f)); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
316 g.setStroke(new BasicStroke(5.0f)); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
317 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10)); |
1 | 318 |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
319 // Draw the connections |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
320 g.setStroke(new BasicStroke(5.5f)); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
321 CubicCurve2D curve = new CubicCurve2D.Float(); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
322 boolean[] drawn = new boolean[numConnections]; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
323 for (int i = 0; i < numConnections; i++) |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
324 if (!drawn[i]) |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
325 { |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
326 Point2D start, cp1, cp2, end; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
327 boolean isActive = states[i] || states[connections[i]]; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
328 |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
329 g.setPaint(isActive ? Color.white : Color.black); |
9 | 330 |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
331 start = getPointCoords(x, y, dim, i); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
332 end = getPointCoords(x, y, dim, connections[i]); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
333 cp1 = getPointCoords(x, y, dim, i + 8); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
334 cp2 = getPointCoords(x, y, dim, connections[i] + 8); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
335 |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
336 curve.setCurve(start, cp1, cp2, end); |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
337 g.draw(curve); |
34
6f6c551cc14c
Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
32
diff
changeset
|
338 |
58
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
339 // Mark connection drawn, so we don't overdraw |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
340 drawn[i] = true; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
341 drawn[connections[i]] = true; |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
342 } |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
343 |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
344 } // !PieceType.START |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
345 |
cde170f2f980
Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents:
54
diff
changeset
|
346 g.setTransform(save); |
106
41c6cca69d60
Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
104
diff
changeset
|
347 g.setComposite(csave); |
5 | 348 } |
1 | 349 } |