comparison game/Piece.java @ 104:eb2e72dd8cae

Change how piece rotation works.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Mar 2011 18:46:41 +0200
parents d5f51370617b
children 41c6cca69d60
comparison
equal deleted inserted replaced
103:8d5cb9e58301 104:eb2e72dd8cae
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 = 35.0f; 18 static final float maxTime = 50.0f;
19 19
20 int currRotation; 20 int currRotation;
21 int[] connections; 21 int[] connections;
22 boolean[] states; 22 boolean[] states;
23 PieceType type, prevType; 23 PieceType type, prevType;
40 states = new boolean[numConnections]; 40 states = new boolean[numConnections];
41 type = ptype; 41 type = ptype;
42 42
43 rotationChanged = false; 43 rotationChanged = false;
44 rotationActive = false; 44 rotationActive = false;
45 currRotation = 0; 45 currRotation = 4 * 5000;
46 currAngle = 0; 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;
89 for (int i = 0; i < numConnections; i++) 89 for (int i = 0; i < numConnections; i++)
90 states[i] = false; 90 states[i] = false;
91 stateChanged = true; 91 stateChanged = true;
92 } 92 }
93 93
94 public int getRotation()
95 {
96 return currRotation % 4;
97 }
98
94 public int getRotatedPoint(int in) 99 public int getRotatedPoint(int in)
95 { 100 {
96 int point = (in - (currRotation * 2)) % 8; 101 int point = (in - (getRotation() * 2)) % 8;
97 if (point < 0) point = 8 + point; 102 if (point < 0) point = 8 + point;
98 return point; 103 return point;
99 } 104 }
100 105
101 public int getAntiRotatedPoint(int in) 106 public int getAntiRotatedPoint(int in)
102 { 107 {
103 int point = (in + (currRotation * 2)) % 8; 108 int point = (in + (getRotation() * 2)) % 8;
104 if (point < 0) point = 8 + point; 109 if (point < 0) point = 8 + point;
105 return point; 110 return point;
106 } 111 }
107 112
108 public int getMatchingPoint(int point) 113 public int getMatchingPoint(int point)
133 138
134 public int getConnection(int point) 139 public int getConnection(int point)
135 { 140 {
136 return connections[point]; 141 return connections[point];
137 } 142 }
143
144 private float getAngle(float rotation)
145 {
146 return (float) ((rotation * Math.PI) / 2.0f);
147 }
138 148
139 public void rotate(RotateDir dir) 149 public void rotate(RotateDir dir)
140 { 150 {
141 // Only normal 151 // Only normal
142 if (type != PieceType.LOCKED && type != PieceType.ACTIVE) 152 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
143 return; 153 return;
144 154
145 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)) % 4; 155 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1));
146 newAngle = (float) ((currRotation * Math.PI) / 2.0f); 156 newAngle = getAngle(currRotation);
147 lerpRotation = new Interpolate(newAngle, currAngle, maxTime); 157 lerpRotation = new Interpolate(newAngle, currAngle, maxTime);
148 rotationChanged = true; 158 rotationChanged = true;
149 } 159 }
150 160
151 public Point2D getPointCoords(float x, float y, float dim, int index) 161 public Point2D getPointCoords(float x, float y, float dim, int index)
195 if (rotationChanged) 205 if (rotationChanged)
196 { 206 {
197 rotationTime = time; 207 rotationTime = time;
198 rotationActive = true; 208 rotationActive = true;
199 rotationChanged = false; 209 rotationChanged = false;
200 rotationSpeed = 0.5f; 210 rotationSpeed = 1.0f;
201 } 211 }
202 212
203 if (typeChanged && type == PieceType.LOCKED) 213 if (typeChanged && type == PieceType.LOCKED)
204 { 214 {
205 rotationSpeed = 1.0f; 215 rotationSpeed = 1.5f;
206 } 216 }
207 217
208 if (rotationActive) 218 if (rotationActive)
209 { 219 {
210 float t = (time - rotationTime) * rotationSpeed; 220 float t = (time - rotationTime) * rotationSpeed;