annotate game/Piece.java @ 32:e480579cc460

More work on debugging the path resolving.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 03 Feb 2011 18:22:16 +0200
parents 60a4579a79df
children 6f6c551cc14c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Ristipolku
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 package game;
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 import java.awt.*;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
8 import java.awt.geom.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 import java.util.*;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
10 import java.math.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 public class Piece
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
17 static final int numConnections = 8;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
18 static final float maxTime = 50.0f;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
19
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
20 int currRotation;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
21 int[] connections;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
22 boolean[] active;
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
23 PieceType type, prevType;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
25 boolean rotationChanged, rotationActive,
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
26 typeChanged, typeActive,
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
27 activeChanged, activeActive;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
28 float currAngle, newAngle, rotationTime, typeTime;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
29
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
30 float throbTime;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
31 Interpolate lerpRotation;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
33 int point;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
34
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
35
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
36 public Piece(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
37 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
38 // Initialize
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
39 connections = new int[numConnections];
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
40 active = new boolean[numConnections];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
41 type = ptype;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
43 rotationChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
44 rotationActive = false;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
45 currRotation = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
46 currAngle = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
47
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
48 typeChanged = false;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
49 typeActive = false;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
51 throbTime = 0;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
54 // Initialize connections between endpoints of the paths inside the piece
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
55 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
56 connections[i] = -1;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
58
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
59 // Randomize connections in the piece
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
60 Random rnd = new Random();
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
61 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
62 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
63 while (connections[i] < 0)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
64 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
65 int tmp = rnd.nextInt(numConnections);
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
66 if (tmp != i && connections[tmp] < 0)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
67 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
68 connections[i] = tmp;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
69 connections[tmp] = i;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
70 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
71 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
72 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
73 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
74
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
75 public Piece()
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
76 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
77 this(PieceType.NONE);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
78 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
80 public void setType(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
81 {
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
82 typeChanged = (prevType != ptype);
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
83 prevType = type;
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
84 type = ptype;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
85 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
87 public int getConnection(int in)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
88 {
30
60a4579a79df Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
89 return connections[(in + (currRotation * 2)) % 8];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
90 }
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
91
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
92 public void rotate(RotateDir dir)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
93 {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
94 // Only normal
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
95 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
96 return;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
98 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)) % 4;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
99 newAngle = (float) ((currRotation * Math.PI) / 2.0f);
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
100 lerpRotation = new Interpolate(newAngle, currAngle, maxTime);
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
101 rotationChanged = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
102 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
104 public Point2D getPointCoords(float x, float y, float dim, int index)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
105 {
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
106 float ox = 0, oy = 0;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
107 float step = dim / 10;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
109 switch (index) {
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
110 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
111 case 1: ox = 7.0f; oy = 0.4f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
112 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
113 case 3: ox = 9.6f; oy = 7.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
114 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
115 case 5: ox = 3.0f; oy = 9.6f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
116 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
117 case 7: ox = 0.4f; oy = 3.0f; break;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
119 case 8: ox = 3.0f; oy = 3.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
120 case 9: ox = 7.0f; oy = 3.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
121 case 10: ox = 7.0f; oy = 3.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
122 case 11: ox = 7.0f; oy = 7.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
123 case 12: ox = 7.0f; oy = 7.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
124 case 13: ox = 7.0f; oy = 7.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
125 case 14: ox = 3.0f; oy = 7.0f; break;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
126 case 15: ox = 3.0f; oy = 3.0f; break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
127 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
129 return new Point2D.Float(x + ox * step, y + oy * step);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
130 }
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
131
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
132 public void clearActiveConnections()
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
133 {
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
134 for (int i = 0; i < numConnections; i++)
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
135 active[i] = false;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
136
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
137 activeChanged = true;
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
138 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
140 public void setActiveConnection(int index)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
141 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
142 active[index] = true;
30
60a4579a79df Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
143 active[connections[index]] = true;
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
144
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
145 activeChanged = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
146 }
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
147
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
148 public PieceType getType()
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
149 {
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
150 return type;
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
151 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
152
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
153 public void animate(float time)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
154 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
155 if (rotationChanged)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
156 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
157 rotationTime = time;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
158 rotationActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
159 rotationChanged = false;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
160 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
162 if (rotationActive)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
163 {
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
164 float t = (time - rotationTime) / 2;
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
165
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
166 if (t < maxTime)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
167 currAngle = lerpRotation.getValue(t);
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
168 else
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
169 {
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
170 currAngle = newAngle;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
171 rotationActive = false;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
172 }
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
173 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
174
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
175 if (typeChanged)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
176 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
177 typeTime = time;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
178 typeActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
179 typeChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
180 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
181
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
182 if (typeActive)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
183 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
184 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
185
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
186 if (activeChanged)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
187 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
188 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
189
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
190 throbTime = (time % 100) / 100.0f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
191 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
193 public void paint(Graphics2D g, float x, float y, float dim)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
194 {
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
195 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
197 switch (type) {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
198 case LOCKED: g.setPaint(Color.green); break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
199 case ACTIVE: g.setPaint(Color.red); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
200 case START: g.setPaint(Color.orange); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
201 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
202
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
203 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
205 g.setPaint(Color.black);
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
206 g.setStroke(new BasicStroke(5.0f));
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
207 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
208
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
209 if (type == PieceType.START)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
210 return;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
211
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
212 if (type == PieceType.ACTIVE)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
213 {
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
214 float offs1 = throbTime * 10.0f,
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
215 offs2 = throbTime * 20.0f;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
216
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
217 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
218 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
219 g.draw(new RoundRectangle2D.Float(x - offs1, y - offs1, dim + offs2, dim + offs2, dim / 10, dim / 10));
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
220 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
221
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
222 g.setStroke(new BasicStroke(5.0f));
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
223 CubicCurve2D c = new CubicCurve2D.Float();
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
224 // QuadCurve2D c = new QuadCurve2D.Float();
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
225 boolean[] drawn = new boolean[numConnections];
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
226 for (int i = 0; i < numConnections; i++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
227 if (!drawn[i])
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
228 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
229 Point2D start, cp1, cp2, end;
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
230
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
231 boolean isActive = active[i] || active[connections[i]];
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
232 g.setPaint(isActive ? Color.white : Color.black);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
233
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
234 start = getPointCoords(x, y, dim, i);
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
235 end = getPointCoords(x, y, dim, connections[i]);
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
236
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
237 cp1 = getPointCoords(x, y, dim, i + 8);
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
238 cp2 = getPointCoords(x, y, dim, connections[i] + 8);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
240 c.setCurve(start, cp1, cp2, end);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
241 g.draw(c);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
242
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
243 drawn[i] = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
244 drawn[connections[i]] = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
245 }
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
246 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 }