annotate game/Piece.java @ 174:92df534806c4

Fix file permissions.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 06 Mar 2017 11:55:40 +0200
parents 7bf508d363bd
children 189cd8fe2304
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
151
d6d92845d6a2 ISO-8859-1 -> UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 149
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
1
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 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
16
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
17 static final int numConnections = 8;
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
18 static final float maxTime = 50.0f;
9
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,
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
27 stateChanged, stateActive,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
28 active;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
29
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
30 float currAngle, rotationTime, rotationSpeed,
153
71205451ef57 Remove scaling.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
31 typeTime, typeValue, throbTime;
91
cc96bc955db6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 85
diff changeset
32
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
33 Interpolate lerpRotation,
149
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
34 lerpScale,
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
35 lerpType;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
37
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
38 public Piece(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
39 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
40 // Initialize
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
41 connections = new int[numConnections];
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
42 states = new boolean[numConnections];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
43 type = ptype;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
45 rotationChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
46 rotationActive = false;
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
47 currRotation = 4 * 5000;
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
48 currAngle = getAngle(currRotation);
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
49
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
50 typeChanged = false;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
51 typeActive = false;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
52
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
53 throbTime = 0;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
149
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
55 lerpType = new Interpolate(1.0f, 0.0f, maxTime);
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
56 lerpScale = new Interpolate(0.0f, (float) Math.PI, maxTime);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
58 // Initialize connections between endpoints of the paths inside the piece
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 connections[i] = -1;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
62
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
63 // Randomize connections in the piece
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
64 Random rnd = new Random();
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
65 for (int i = 0; i < numConnections; i++)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
66 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
67 while (connections[i] < 0)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
68 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
69 int tmp = rnd.nextInt(numConnections);
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
70 if (tmp != i && connections[tmp] < 0)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
71 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
72 connections[i] = tmp;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
73 connections[tmp] = i;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
74 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
75 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
76 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
77 }
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
78
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
79 public Piece()
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
80 {
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
81 this(PieceType.NONE);
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
82 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
84
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
85 public void changed()
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
86 {
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
87 typeChanged = true;
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
88 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
89
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
90 public void setType(PieceType ptype)
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
91 {
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
92 // typeChanged = (prevType != ptype) && (ptype == PieceType.LOCKED);
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
93 prevType = type;
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
94 type = ptype;
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
95 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
97 public void clearStates()
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
98 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
99 for (int i = 0; i < numConnections; i++)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
100 states[i] = false;
167
7bf508d363bd Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
101
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
102 stateChanged = true;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
103 }
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
104
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
105 public int getRotation()
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
106 {
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
107 return currRotation % 4;
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
108 }
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
109
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
110 public int getRotatedPoint(int in)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
111 {
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
112 int point = (in - (getRotation() * 2)) % 8;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
113 if (point < 0) point = 8 + point;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
114 return point;
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
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
117 public int getAntiRotatedPoint(int in)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
118 {
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
119 int point = (in + (getRotation() * 2)) % 8;
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
120 if (point < 0) point = 8 + point;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
121 return point;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
122 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
123
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
124 public int getMatchingPoint(int point)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
125 {
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
126 switch (point)
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
127 {
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
128 case 0: return 5;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
129 case 1: return 4;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
130
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
131 case 2: return 7;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
132 case 3: return 6;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
133
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
134 case 4: return 1;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
135 case 5: return 0;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
136
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
137 case 6: return 3;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
138 case 7: return 2;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
139 }
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
140 return -1;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
141 }
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 34
diff changeset
142
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
143 public void setConnectionState(int point, boolean state)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
144 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
145 states[point] = state;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
146 states[connections[point]] = state;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
147 stateChanged = true;
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
148 }
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
149
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
150 public int getConnection(int point)
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
151 {
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
152 return connections[point];
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
153 }
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
154
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
155 private float getAngle(float rotation)
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
156 {
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
157 return (float) ((rotation * Math.PI) / 2.0f);
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
158 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
159
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
160 public void rotate(RotateDir dir)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
161 {
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
162 // Only normal
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
163 if (type != PieceType.LOCKED && type != PieceType.ACTIVE)
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
164 return;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
166 currRotation = (currRotation + (dir == RotateDir.RIGHT ? 1 : -1));
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
167 lerpRotation = new Interpolate(getAngle(currRotation), currAngle, maxTime);
3
b8fd19e2d879 Indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
168 rotationChanged = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
169 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
171 public Point2D getPointCoords(float x, float y, float dim, int index)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
172 {
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
173 float ox = 0, oy = 0;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
174 float step = dim / 10;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
175
167
7bf508d363bd Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
176 switch (index)
7bf508d363bd Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
177 {
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
178 // Normal line starting and ending points
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
179 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
180 case 1: ox = 7.0f; oy = 0.4f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
181
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
182 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
183 case 3: ox = 9.6f; oy = 7.0f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
184
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
185 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
186 case 5: ox = 3.0f; oy = 9.6f; break;
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
187
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
188 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
189 case 7: ox = 0.4f; oy = 3.0f; break;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
191
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
192 // Matching control points for each point above (+8)
39
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
193 case 8: ox = 3.0f; oy = 2.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
194 case 9: ox = 7.0f; oy = 2.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
195
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
196 case 10: ox = 7.5f; oy = 3.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
197 case 11: ox = 7.5f; oy = 7.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
198
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
199 case 12: ox = 7.0f; oy = 7.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
200 case 13: ox = 3.0f; oy = 7.5f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
201
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
202 case 14: ox = 2.5f; oy = 7.0f; break;
e682b623aea9 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
203 case 15: ox = 2.5f; oy = 3.0f; break;
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
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
206 return new Point2D.Float(x + ox * step, y + oy * step);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
207 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
208
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
209 public PieceType getType()
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
210 {
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
211 return type;
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
212 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
213
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
214 public void animate(float time)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
215 {
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
216 active = false;
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
217
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
218 if (rotationChanged)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
219 {
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
220 rotationTime = time;
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
221 rotationActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
222 rotationChanged = false;
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
223 rotationSpeed = 1.0f;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
224 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
225
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
226 if (typeChanged && type == PieceType.LOCKED)
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
227 {
104
eb2e72dd8cae Change how piece rotation works.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
228 rotationSpeed = 1.5f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
229 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
231 if (rotationActive)
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
232 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
233 float t = (time - rotationTime) * rotationSpeed;
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
234
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
235 if (t < maxTime)
149
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
236 {
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
237 currAngle = lerpRotation.getValue(t);
149
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
238 }
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
239 else
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
240 {
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
241 currAngle = lerpRotation.start;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
242 rotationActive = false;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
243 }
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
244
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
245 active = true;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
246 }
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 45
diff changeset
247
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
248 if (typeChanged)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
249 {
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
250 typeTime = time;
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
251 typeActive = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
252 typeChanged = false;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
253 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
254
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
255 if (typeActive)
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
256 {
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
257 float t = (time - typeTime) * 2.0f;
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
258
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
259 if (t < maxTime)
152
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
260 {
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
261 typeValue = lerpType.getValue(t);
152
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
262 }
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
263 else
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
264 {
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
265 typeValue = lerpType.start;
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
266 typeActive = false;
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
267 }
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
268
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
269
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
270 active = true;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
271 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
272
40
a69103644bf6 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 39
diff changeset
273 if (stateChanged)
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
274 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
275 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
276
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
277 throbTime = (time % 100) / 100.0f;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
278 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
280 public void paint(Graphics2D g, float x, float y, float dim)
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
281 {
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
282 AffineTransform save = g.getTransform();
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
283 Composite csave = g.getComposite();
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
284
149
35374be74fdc Add some bling to piece rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
285
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
286 // Change compositing alpha for the whole piece drawing
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
287 // when the piece is being "introduced".
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
288 if (typeActive)
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
289 {
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
290 g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, typeValue));
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
291 }
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
292
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
293
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
294 // Transform drawing by current angle
11
b89ecc8d5557 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
295 g.rotate(currAngle, x + dim / 2.0f, y + dim / 2.0f);
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296
45
79185dababf2 Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 43
diff changeset
297 // Color piece by type
167
7bf508d363bd Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
298 switch (type)
7bf508d363bd Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
299 {
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
300 case LOCKED: g.setPaint(new Color(0.3f, 0.8f, 0.3f, 0.35f)); break;
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
301 case ACTIVE: g.setPaint(new Color(0.9f, 0.3f, 0.3f, 0.35f)); break;
92
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
302 case START: g.setPaint(new Color(1.0f, 0.6f, 0.0f, 0.95f)); break;
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
303 }
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
304
153
71205451ef57 Remove scaling.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
305 float corner = dim / 10.0f;
71205451ef57 Remove scaling.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
306 g.fill(new RoundRectangle2D.Float(x, y, dim, dim, corner, corner));
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
92
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
308 // Start pieces (center piece) have a different kind of border
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
309 // and no connections drawn inside
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
310 if (type == PieceType.START)
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
311 {
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
312 // Draw piece border
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
313 g.setPaint(Color.black);
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
314 g.setStroke(new BasicStroke(2.0f));
153
71205451ef57 Remove scaling.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
315 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, corner, corner));
92
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
316 }
d5f51370617b Change start piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
317 else
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
318 {
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
319 // Active piece has a throbbing "ghost" border
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
320 if (type == PieceType.ACTIVE)
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
321 {
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
322 float offs1 = throbTime * 10.0f,
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
323 offs2 = throbTime * 20.0f;
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
324
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
325 g.setPaint(new Color(0.0f, 0.0f, 0.0f, (float) (1.0f - throbTime) ));
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
326 g.setStroke(new BasicStroke(2.0f + throbTime * 2.0f));
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
327 g.draw(new RoundRectangle2D.Float(
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
328 x - offs1, y - offs1,
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
329 dim + offs2, dim + offs2,
153
71205451ef57 Remove scaling.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
330 corner, corner));
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
331 }
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
332
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
333 // Draw piece border
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
334 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f));
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
335 g.setStroke(new BasicStroke(5.0f));
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
336 g.draw(new RoundRectangle2D.Float(x, y, dim, dim, dim / 10, dim / 10));
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
338 // Draw the connections
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
339 g.setStroke(new BasicStroke(5.5f));
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
340 CubicCurve2D curve = new CubicCurve2D.Float();
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
341 boolean[] drawn = new boolean[numConnections];
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
342 for (int i = 0; i < numConnections; i++)
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
343 if (!drawn[i])
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
344 {
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
345 Point2D start, cp1, cp2, end;
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
346 boolean isActive = states[i] || states[connections[i]];
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
347
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
348 g.setPaint(isActive ? Color.white : Color.black);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
349
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
350 start = getPointCoords(x, y, dim, i);
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
351 end = getPointCoords(x, y, dim, connections[i]);
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
352 cp1 = getPointCoords(x, y, dim, i + 8);
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
353 cp2 = getPointCoords(x, y, dim, connections[i] + 8);
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
354
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
355 curve.setCurve(start, cp1, cp2, end);
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
356 g.draw(curve);
34
6f6c551cc14c Fix piece connections rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 32
diff changeset
357
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
358 // Mark connection drawn, so we don't overdraw
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
359 drawn[i] = true;
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
360 drawn[connections[i]] = true;
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
361 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
362
58
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
363 } // !PieceType.START
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
364
cde170f2f980 Clean up the piece rendering.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
365 g.setTransform(save);
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 104
diff changeset
366 g.setComposite(csave);
5
4890020bf856 Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
367 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
368 }