Mercurial > hg > ristipolku
comparison game/Piece.java @ 40:a69103644bf6
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Feb 2011 23:34:47 +0200 |
parents | e682b623aea9 |
children | 951a4d669af0 |
comparison
equal
deleted
inserted
replaced
39:e682b623aea9 | 40:a69103644bf6 |
---|---|
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; |
22 boolean[] active; | 22 boolean[] states; |
23 PieceType type, prevType; | 23 PieceType type, prevType; |
24 | 24 |
25 boolean rotationChanged, rotationActive, | 25 boolean rotationChanged, rotationActive, |
26 typeChanged, typeActive, | 26 typeChanged, typeActive, |
27 activeChanged, activeActive; | 27 stateChanged, stateActive; |
28 float currAngle, newAngle, rotationTime, typeTime; | 28 float currAngle, newAngle, rotationTime, typeTime; |
29 | 29 |
30 float throbTime; | 30 float throbTime; |
31 Interpolate lerpRotation; | 31 Interpolate lerpRotation; |
32 | 32 |
33 int point; | |
34 | |
35 | 33 |
36 public Piece(PieceType ptype) | 34 public Piece(PieceType ptype) |
37 { | 35 { |
38 // Initialize | 36 // Initialize |
39 connections = new int[numConnections]; | 37 connections = new int[numConnections]; |
40 active = new boolean[numConnections]; | 38 states = new boolean[numConnections]; |
41 type = ptype; | 39 type = ptype; |
42 | 40 |
43 rotationChanged = false; | 41 rotationChanged = false; |
44 rotationActive = false; | 42 rotationActive = false; |
45 currRotation = 0; | 43 currRotation = 0; |
82 typeChanged = (prevType != ptype); | 80 typeChanged = (prevType != ptype); |
83 prevType = type; | 81 prevType = type; |
84 type = ptype; | 82 type = ptype; |
85 } | 83 } |
86 | 84 |
87 public int getConnection(int in) | 85 public void clearStates() |
88 { | 86 { |
89 int offs = (in + (currRotation * 2)) % 8; | 87 for (int i = 0; i < numConnections; i++) |
90 if (offs < 0) | 88 states[i] = false; |
91 offs = 8 + offs; | 89 stateChanged = true; |
92 | 90 } |
93 return connections[offs]; | 91 |
92 public int getRotatedPoint(int in) | |
93 { | |
94 int point = (in + (currRotation * 2)) % 8; | |
95 if (point < 0) point = 8 + point; | |
96 return point; | |
97 } | |
98 | |
99 public void setConnectionState(int point, boolean state) | |
100 { | |
101 states[point] = state; | |
102 states[connections[point]] = state; | |
103 stateChanged = true; | |
104 } | |
105 | |
106 public int getConnection(int point) | |
107 { | |
108 return connections[point]; | |
94 } | 109 } |
95 | 110 |
96 public void rotate(RotateDir dir) | 111 public void rotate(RotateDir dir) |
97 { | 112 { |
98 // Only normal | 113 // Only normal |
140 } | 155 } |
141 | 156 |
142 return new Point2D.Float(x + ox * step, y + oy * step); | 157 return new Point2D.Float(x + ox * step, y + oy * step); |
143 } | 158 } |
144 | 159 |
145 public void clearActiveConnections() | |
146 { | |
147 for (int i = 0; i < numConnections; i++) | |
148 active[i] = false; | |
149 | |
150 activeChanged = true; | |
151 } | |
152 | |
153 public void setActiveConnection(int index) | |
154 { | |
155 active[index] = true; | |
156 active[connections[index]] = true; | |
157 | |
158 activeChanged = true; | |
159 } | |
160 | |
161 public PieceType getType() | 160 public PieceType getType() |
162 { | 161 { |
163 return type; | 162 return type; |
164 } | 163 } |
165 | 164 |
194 | 193 |
195 if (typeActive) | 194 if (typeActive) |
196 { | 195 { |
197 } | 196 } |
198 | 197 |
199 if (activeChanged) | 198 if (stateChanged) |
200 { | 199 { |
201 } | 200 } |
202 | 201 |
203 throbTime = (time % 100) / 100.0f; | 202 throbTime = (time % 100) / 100.0f; |
204 } | 203 } |
235 boolean[] drawn = new boolean[numConnections]; | 234 boolean[] drawn = new boolean[numConnections]; |
236 for (int i = 0; i < numConnections; i++) | 235 for (int i = 0; i < numConnections; i++) |
237 if (!drawn[i]) | 236 if (!drawn[i]) |
238 { | 237 { |
239 Point2D start, cp1, cp2, end; | 238 Point2D start, cp1, cp2, end; |
240 | 239 boolean isActive = states[i] || states[connections[i]]; |
241 boolean isActive = active[i] || active[connections[i]]; | 240 |
242 g.setPaint(isActive ? Color.white : Color.black); | 241 g.setPaint(isActive ? Color.white : Color.black); |
243 | 242 |
244 start = getPointCoords(x, y, dim, i); | 243 start = getPointCoords(x, y, dim, i); |
245 end = getPointCoords(x, y, dim, connections[i]); | 244 end = getPointCoords(x, y, dim, connections[i]); |
246 | 245 |