Mercurial > hg > ristipolku
comparison game/Piece.java @ 5:4890020bf856
Cleanups, etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 28 Jan 2011 18:00:18 +0200 |
parents | b8fd19e2d879 |
children | be0bf7544069 |
comparison
equal
deleted
inserted
replaced
4:e0e8fd08331e | 5:4890020bf856 |
---|---|
72 | 72 |
73 public int getConnection(int in) | 73 public int getConnection(int in) |
74 { | 74 { |
75 return connections[in]; | 75 return connections[in]; |
76 } | 76 } |
77 | 77 |
78 public void rotate(boolean dir) | 78 public void rotate(boolean dir) |
79 { | 79 { |
80 if (type != PieceType.NORMAL) | 80 if (type != PieceType.NORMAL) |
81 return; | 81 return; |
82 | 82 |
87 else if (currRotation > maxRotation) | 87 else if (currRotation > maxRotation) |
88 newRotation = minRotation; | 88 newRotation = minRotation; |
89 | 89 |
90 rotationDir = dir; | 90 rotationDir = dir; |
91 rotationChanged = true; | 91 rotationChanged = true; |
92 } | 92 } |
93 | 93 |
94 public Point2D getPoint(double x, double y, double dim, int index) | 94 public Point2D getPointCoords(double x, double y, double dim, int index) |
95 { | 95 { |
96 double ox = 0, oy = 0; | 96 double ox = 0, oy = 0; |
97 double step = dim / 10; | 97 double step = dim / 10; |
98 | 98 |
99 switch (index) { | 99 switch (index) { |
100 case 0: ox = 3.0f; oy = 0.5f; break; | 100 case 0: ox = 3.0f; oy = 0.5f; break; |
101 case 1: ox = 7.0f; oy = 0.5f; break; | 101 case 1: ox = 7.0f; oy = 0.5f; break; |
102 case 2: ox = 9.5f; oy = 3.0f; break; | 102 case 2: ox = 9.5f; oy = 3.0f; break; |
103 case 3: ox = 9.5f; oy = 7.0f; break; | 103 case 3: ox = 9.5f; oy = 7.0f; break; |
104 case 4: ox = 7.0f; oy = 9.5f; break; | 104 case 4: ox = 7.0f; oy = 9.5f; break; |
105 case 5: ox = 3.0f; oy = 9.5f; break; | 105 case 5: ox = 3.0f; oy = 9.5f; break; |
106 case 6: ox = 0.5f; oy = 7.0f; break; | 106 case 6: ox = 0.5f; oy = 7.0f; break; |
107 case 7: ox = 0.5f; oy = 3.0f; break; | 107 case 7: ox = 0.5f; oy = 3.0f; break; |
108 | |
109 case -1: ox = 5; oy = 5; break; | |
110 } | |
111 | 108 |
112 return new Point2D.Double(x + ox * step, y + oy * step); | 109 case -1: ox = 5.0f; oy = 5.0f; break; |
113 } | 110 } |
114 | |
115 public void animate(double time) | |
116 { | |
117 if (rotationChanged) | |
118 { | |
119 rotationTime = time; | |
120 rotationActive = true; | |
121 } | |
122 | 111 |
123 if (rotationActive) | 112 return new Point2D.Double(x + ox * step, y + oy * step); |
124 { | 113 } |
125 double t = time - rotationTime; | 114 |
126 rotationAngle = | 115 public void animate(double time) |
127 } | 116 { |
117 if (rotationChanged) | |
118 { | |
119 rotationTime = time; | |
120 rotationActive = true; | |
121 } | |
122 | |
123 if (rotationActive) | |
124 { | |
125 double t = time - rotationTime; | |
126 rotationAngle = | |
127 } | |
128 | 128 |
129 } | 129 } |
130 | 130 |
131 public void paint(Graphics2D g, double x, double y, double dim) | 131 public void paint(Graphics2D g, double x, double y, double dim) |
132 { | 132 { |
133 AffineTransform save = g.getTransform(); | 133 AffineTransform save = g.getTransform(); |
134 | 134 |
135 g.setStroke(new BasicStroke(4.0f)); | 135 AffineTransform tf = new AffineTransform(); |
136 tf.rotate(Math.toRadians(rotationAngle)); | |
137 g.transform(tf); | |
136 | 138 |
137 switch (type) { | 139 switch (type) { |
138 case NORMAL: g.setPaint(Color.green); break; | 140 case NORMAL: g.setPaint(Color.green); break; |
139 case ACTIVE: g.setPaint(Color.red); break; | 141 case ACTIVE: g.setPaint(Color.red); break; |
140 case START: g.setPaint(Color.orange); break; | 142 case START: g.setPaint(Color.orange); break; |
141 } | 143 } |
144 g.fill(new RoundRectangle2D.Double(x, y, dim, dim, dim / 10, dim / 10)); | |
142 | 145 |
143 AffiineTransform tf = new AffineTransform(); | 146 g.setPaint(Color.black); |
144 tf.rotate(Math.toRadians(rotationAngle)); | 147 g.setStroke(new BasicStroke(4.0f)); |
145 g.transform(tf); | 148 g.draw(new RoundRectangle2D.Double(x, y, dim, dim, dim / 10, dim / 10)); |
146 g.fill(new RoundRectangle2D.Double(x, y, dim, dim, dim / 10, dim / 10)); | |
147 | 149 |
148 g.setPaint(Color.black); | 150 if (type == PieceType.START) |
149 g.setStroke(new BasicStroke(4.0f)); | 151 return; |
150 g.draw(new RoundRectangle2D.Double(x, y, dim, dim, dim / 10, dim / 10)); | |
151 | 152 |
152 if (type == PieceType.START) | 153 g.setStroke(new BasicStroke(6.0f)); |
153 return; | 154 // CubicCurve2D c = new CubicCurve2D.Double(); |
155 QuadCurve2D c = new QuadCurve2D.Double(); | |
154 | 156 |
155 g.setStroke(new BasicStroke(6.0f)); | 157 for (int i = 0; i < numConnections / 2; i++) |
156 // CubicCurve2D c = new CubicCurve2D.Double(); | 158 { |
157 QuadCurve2D c = new QuadCurve2D.Double(); | 159 Point2D start, cp1, cp2, end; |
158 | 160 start = getPoint(x, y, dim, i); |
159 for (int i = 0; i < numConnections / 2; i++) | 161 end = getPoint(x, y, dim, connections[i]); |
160 { | |
161 Point2D start, cp1, cp2, end; | |
162 | |
163 start = getPoint(x, y, dim, i); | |
164 end = getPoint(x, y, dim, connections[i]); | |
165 | |
166 // cp1 = getPoint(x, y, dim, (i + 4) % 8); | 162 // cp1 = getPoint(x, y, dim, (i + 4) % 8); |
167 // cp2 = getPoint(x, y, dim, (connections[i] + 4) % 8); | 163 // cp2 = getPoint(x, y, dim, (connections[i] + 4) % 8); |
168 cp1 = getPoint(x, y, dim, -1); | 164 cp1 = getPoint(x, y, dim, -1); |
169 | 165 |
170 c.setCurve(start, cp1, end); | 166 c.setCurve(start, cp1, end); |
171 g.draw(c); | 167 g.draw(c); |
172 } | 168 } |
173 | 169 g.setTransform(save); |
174 g.setTransform(save); | 170 } |
175 } | |
176 } | 171 } |