annotate game/Piece.java @ 11:b89ecc8d5557

More work.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 30 Jan 2011 00:26:35 +0200
parents 4bacc98973f5
children df494a65bf8c
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 {
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
15 static final int numConnections = 8;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
16 static final float maxTime = 50.0f;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
17
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
18 int currRotation;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
19 int[] connections;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
20 boolean[] active;
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
21 PieceType type, oldType;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
23 boolean rotationChanged, rotationActive,
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
24 typeChanged, typeActive,
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
25 activeChanged, activeActive;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
26 float currAngle, newAngle, rotationTime, typeTime;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
27 float throb;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
28
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
29 Interpolate lerpRotation;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
31 public Piece(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
32 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
33 // Initialize
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
34 connections = new int[numConnections];
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
35 active = new boolean[numConnections];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
36 type = ptype;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
38 rotationChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
39 rotationActive = false;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
40 currRotation = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
41 currAngle = 0;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
42
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
43 typeChanged = false;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
44 typeActive = false;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
46 throb = 0;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
49 // Initialize connections between endpoints of the paths inside the piece
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
50 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
51 connections[i] = -1;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
53 // Randomize connections in the piece
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
54 Random rnd = new Random();
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 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
57 while (connections[i] < 0)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
58 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
59 int tmp = rnd.nextInt(numConnections);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
60 if (connections[tmp] < 0)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
61 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
62 connections[i] = tmp;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
63 connections[tmp] = i;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
64 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
65 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
66 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
67 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
68
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
69 public Piece()
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
70 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
71 this(PieceType.NONE);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
72 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
74 public void setType(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
75 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
76 typeChanged = (oldType != ptype);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
77 oldType = type;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
78 type = ptype;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
79 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
81 public int getConnection(int in)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
82 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
83 return connections[in];
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
84 }
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
85
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
86 public void rotate(boolean dir)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
87 {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
88 // Only normal
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
89 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
90 return;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
92 currRotation = (currRotation + (dir ? -1 : 1)) % 4;
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
93 newAngle = (float) ((currRotation * Math.PI) / 2.0f);
10
4bacc98973f5 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
94 lerpRotation = new Interpolate(currAngle, newAngle, maxTime);
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
95 rotationChanged = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
96 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
98 public Point2D getPointCoords(float x, float y, float dim, int index)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
99 {
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
100 float ox = 0, oy = 0;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
101 float step = dim / 10;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
103 switch (index) {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
104 case 0: ox = 3.0f; oy = 0.5f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
105 case 1: ox = 7.0f; oy = 0.5f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
106 case 2: ox = 9.5f; oy = 3.0f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
107 case 3: ox = 9.5f; oy = 7.0f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
108 case 4: ox = 7.0f; oy = 9.5f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
109 case 5: ox = 3.0f; oy = 9.5f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
110 case 6: ox = 0.5f; oy = 7.0f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
111 case 7: ox = 0.5f; oy = 3.0f; break;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
113 case -1: ox = 5.0f; oy = 5.0f; break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
114 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
116 return new Point2D.Float(x + ox * step, y + oy * step);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
117 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
119 public void setActiveConnection(int index)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
120 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
121 active[index] = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
122 activeChanged = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
123 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
124
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
125 public void animate(float time)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
126 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
127 if (rotationChanged)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
128 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
129 rotationTime = time;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
130 rotationActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
131 rotationChanged = false;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
132 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
134 if (rotationActive)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
135 {
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
136 float t = (time - rotationTime) / 2;
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
137
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
138 if (t < maxTime)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
139 currAngle = lerpRotation.getValue(t);
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
140 else
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
141 {
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
142 currAngle = newAngle;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
143 rotationActive = false;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
144 }
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
145 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
146
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
147 if (typeChanged)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
148 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
149 typeTime = time;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
150 typeActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
151 typeChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
152 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
153
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
154 if (typeActive)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
155 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
156 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
157
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
158 if (activeChanged)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
159 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
160 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
161
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
162 throb = (time % 100) / 100.0f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
163 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
165 public void paint(Graphics2D g, float x, float y, float dim)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
166 {
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
167 // AffineTransform tf = new AffineTransform();
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
168 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
169 // g.transform(tf);
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
170
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
171 if (type == PieceType.ACTIVE)
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
172 System.out.print("angle = " + currAngle + "\n");
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
174 switch (type) {
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
175 case LOCKED: g.setPaint(Color.green); break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
176 case ACTIVE: g.setPaint(Color.red); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
177 case START: g.setPaint(Color.orange); break;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
178 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
179
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
180 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
181
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
182 g.setPaint(Color.black);
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
183 g.setStroke(new BasicStroke(4.0f));
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
184 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
185
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
186 if (type == PieceType.START)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
187 return;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
188
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
189 if (type == PieceType.ACTIVE)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
190 {
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
191 float offs1 = throb * 10.0f,
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
192 offs2 = throb * 20.0f;
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
193
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
194 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throb) ));
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
195 g.setStroke(new BasicStroke(2.0f + throb * 2.0f));
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
196 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
197 }
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
198
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
199 g.setPaint(Color.black);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
200 g.setStroke(new BasicStroke(6.0f));
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
201 // CubicCurve2D c = new CubicCurve2D.Float();
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
202 QuadCurve2D c = new QuadCurve2D.Float();
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
203 boolean[] drawn = new boolean[numConnections];
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
204 for (int i = 0; i < numConnections; i++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
205 if (!drawn[i])
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
206 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
207 Point2D start, cp1, cp2, end;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
208
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
209 start = getPointCoords(x, y, dim, i);
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
210 end = getPointCoords(x, y, dim, connections[i]);
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
211 cp1 = getPointCoords(x, y, dim, -1);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
213 c.setCurve(start, cp1, end);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
214 g.draw(c);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
215
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
216 drawn[i] = true;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
217 drawn[connections[i]] = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
218 }
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
219 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 }