annotate game/Piece.java @ 26:3d4cc47df31a

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