annotate game/Piece.java @ 54:cc7943cd7f2d

Moar work.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 23 Feb 2011 19:54:48 +0200
parents 79185dababf2
children cde170f2f980
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;
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
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
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,
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
27 stateChanged, stateActive;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
28 float currAngle, newAngle, rotationTime, typeTime, rotationSpeed;
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
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
34 public Piece(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
35 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
36 // Initialize
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
37 connections = new int[numConnections];
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
38 states = new boolean[numConnections];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
39 type = ptype;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
41 rotationChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
42 rotationActive = false;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
43 currRotation = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
44 currAngle = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
45
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
46 typeChanged = false;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
47 typeActive = false;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
49 throbTime = 0;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
52 // Initialize connections between endpoints of the paths inside the piece
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
53 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
54 connections[i] = -1;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
56
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
57 // Randomize connections in the piece
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
58 Random rnd = new Random();
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
59 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
60 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
61 while (connections[i] < 0)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
62 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
63 int tmp = rnd.nextInt(numConnections);
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
64 if (tmp != i && connections[tmp] < 0)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
65 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
66 connections[i] = tmp;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
67 connections[tmp] = i;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
68 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
69 }
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 public Piece()
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
74 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
75 this(PieceType.NONE);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
76 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
78 public void setType(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
79 {
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
80 typeChanged = (prevType != ptype);
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
81 prevType = type;
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
82 type = ptype;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
83 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
85 public void clearStates()
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
86 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
87 for (int i = 0; i < numConnections; i++)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
88 states[i] = false;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
89 stateChanged = true;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
90 }
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
91
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
92 public int getRotatedPoint(int in)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
93 {
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
94 int point = (in - (currRotation * 2)) % 8;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
95 if (point < 0) point = 8 + point;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
96 return point;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
97 }
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
98
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
99 public int getAntiRotatedPoint(int in)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
100 {
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
101 int point = (in + (currRotation * 2)) % 8;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
102 if (point < 0) point = 8 + point;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
103 return point;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
104 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
105
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
106 public int getMatchingPoint(int point)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
107 {
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
108 switch (point)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
109 {
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
110 case 0: return 5;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
111 case 1: return 4;
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 case 2: return 7;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
114 case 3: return 6;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
115
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
116 case 4: return 1;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
117 case 5: return 0;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
118
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
119 case 6: return 3;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
120 case 7: return 2;
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 return -1;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
123 }
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
124
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
125 public void setConnectionState(int point, boolean state)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
126 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
127 states[point] = state;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
128 states[connections[point]] = state;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
129 stateChanged = true;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
130 }
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
131
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
132 public int getConnection(int point)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
133 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
134 return connections[point];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
135 }
32
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 public void rotate(RotateDir dir)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
138 {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
139 // Only normal
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
140 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
141 return;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
143 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1)) % 4;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
144 newAngle = (float) ((currRotation * Math.PI) / 2.0f);
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
145 lerpRotation = new Interpolate(newAngle, currAngle, maxTime);
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
146 rotationChanged = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
147 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
149 public Point2D getPointCoords(float x, float y, float dim, int index)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
150 {
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
151 float ox = 0, oy = 0;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
152 float step = dim / 10;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
154 switch (index) {
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
155 // Normal line starting and ending points
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
156 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
157 case 1: ox = 7.0f; oy = 0.4f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
158
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
159 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
160 case 3: ox = 9.6f; oy = 7.0f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
161
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
162 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
163 case 5: ox = 3.0f; oy = 9.6f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
164
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
165 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
166 case 7: ox = 0.4f; oy = 3.0f; break;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
168
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
169 // Matching control points for each point above (+8)
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
170 case 8: ox = 3.0f; oy = 2.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
171 case 9: ox = 7.0f; oy = 2.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
172
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
173 case 10: ox = 7.5f; oy = 3.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
174 case 11: ox = 7.5f; oy = 7.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
175
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
176 case 12: ox = 7.0f; oy = 7.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
177 case 13: ox = 3.0f; oy = 7.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
178
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
179 case 14: ox = 2.5f; oy = 7.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
180 case 15: ox = 2.5f; oy = 3.0f; break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
181 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
183 return new Point2D.Float(x + ox * step, y + oy * step);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
184 }
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
185
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
186 public PieceType getType()
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
187 {
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
188 return type;
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
189 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
190
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
191 public void animate(float time)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
192 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
193 if (rotationChanged)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
194 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
195 rotationTime = time;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
196 rotationActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
197 rotationChanged = false;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
198 rotationSpeed = 0.5f;
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
199 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
200
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
201 if (typeChanged && type == PieceType.LOCKED)
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
202 {
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
203 rotationSpeed = 1.0f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
204 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
206 if (rotationActive)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
207 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
208 float t = (time - rotationTime) * rotationSpeed;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
209
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
210 if (t < maxTime)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
211 currAngle = lerpRotation.getValue(t);
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
212 else
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
213 {
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
214 currAngle = newAngle;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
215 rotationActive = false;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
216 }
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
217 }
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
218
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
219 if (typeChanged)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
220 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
221 typeTime = time;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
222 typeActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
223 typeChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
224 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
225
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
226 if (typeActive)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
227 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
228 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
229
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
230 if (stateChanged)
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
231 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
232 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
233
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
234
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
235
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
236 throbTime = (time % 100) / 100.0f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
237 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
239 public void paint(Graphics2D g, float x, float y, float dim)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
240 {
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
241 // Transform drawing by current angle
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
242 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
244 // Color piece by type
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
245 switch (type) {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
246 case LOCKED: g.setPaint(Color.green); break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
247 case ACTIVE: g.setPaint(Color.red); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
248 case START: g.setPaint(Color.orange); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
249 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
250
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
251 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
252
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
253 // Start pieces (center piece) do not have border, etc.
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
254 if (type == PieceType.START)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
255 return;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
256
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
257 // Active piece has a throbbing "ghost" border
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
258 if (type == PieceType.ACTIVE)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
259 {
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
260 float offs1 = throbTime * 10.0f,
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
261 offs2 = throbTime * 20.0f;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
262
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
263 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
264 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
265 g.draw(new RoundRectangle2D.Float(
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
266 x - offs1, y - offs1,
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
267 dim + offs2, dim + offs2,
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
268 dim / 10, dim / 10));
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
269 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
270
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
271 // Draw the connections
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
272 g.setStroke(new BasicStroke(5.0f));
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
273 CubicCurve2D c = new CubicCurve2D.Float();
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
274 boolean[] drawn = new boolean[numConnections];
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
275 for (int i = 0; i < numConnections; i++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
276 if (!drawn[i])
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
277 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
278 Point2D start, cp1, cp2, end;
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
279 boolean isActive = states[i] || states[connections[i]];
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
280
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
281 g.setPaint(isActive ? Color.white : Color.black);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
282
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
283 start = getPointCoords(x, y, dim, i);
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
284 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
285
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
286 cp1 = getPointCoords(x, y, dim, i + 8);
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
287 cp2 = getPointCoords(x, y, dim, connections[i] + 8);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
289 c.setCurve(start, cp1, cp2, end);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
290 g.draw(c);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
291
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
292 // Mark connection drawn, so we don't overdraw
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
293 drawn[i] = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
294 drawn[connections[i]] = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
295 }
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
296
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
297 // Draw piece border
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
298 g.setPaint(Color.black);
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
299 g.setStroke(new BasicStroke(5.0f));
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
300 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
301 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 }