annotate game/Engine.java @ 170:b9bc493ae53c

Modularize and clean up code.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 02 Mar 2017 15:57:15 +0200
parents 159252f9480d
children 5070e57ebbfc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
2 * Ristipolku Game Engine
151
d6d92845d6a2 ISO-8859-1 -> UTF-8.
Matti Hamalainen <ccr@tnsp.org>
parents: 148
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 */
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
5 package game;
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
6
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 import java.awt.*;
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 import java.awt.geom.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
9 import java.awt.event.*;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
10 import java.awt.image.*;
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
11 import java.awt.event.*;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
12 import java.awt.font.*;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
13 import javax.imageio.*;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
14 import javax.swing.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
15 import java.util.*;
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
16 import java.util.concurrent.locks.Lock;
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
17 import java.util.concurrent.locks.ReentrantReadWriteLock;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
18 import java.io.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
19 import game.*;
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
20 import javax.sound.sampled.*;
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
21
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
22
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
23 class AboutBox extends IDMWidget
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
24 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
25 BufferedImage aboutImg;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
26 boolean aboutSecret;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
27
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
28 IDMPoint currPos, currOffs;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
29 Paint textPaint;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
30 Font textFont;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
31 FontMetrics textMetrics;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
32
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
33
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
34 public AboutBox()
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
35 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
36 try {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
37 ResourceLoader res = new ResourceLoader("graphics/girl.jpg");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
38 aboutImg = ImageIO.read(res.getStream());
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
39 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
40 catch (IOException e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
41 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
42 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
43
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
44 aboutSecret = false;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
45
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
46 setPos(150f, 150f);
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
47 setSize(720f, 420f);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
48 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
49
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
50 public void setTextFont(Font font, FontMetrics metrics)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
51 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
52 textFont = font;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
53 textMetrics = metrics;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
54 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
55
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
56 public void setTextPaint(Paint paint)
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
57 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
58 textPaint = paint;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
59 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
60
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
61 public void setCurrPos(IDMPoint npos)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
62 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
63 currPos = npos;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
64 currOffs = new IDMPoint(0, 0);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
65 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
66
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
67 public void setCurrPos(float x, float y)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
68 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
69 setCurrPos(new IDMPoint(x, y));
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
70 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
71
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
72 public void setCurrPosScaledRel(float x, float y)
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
73 {
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
74 setCurrPos(new IDMPoint(getScaledRelX(x), getScaledRelY(y)));
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
75 }
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
76
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
77 public void drawString(Graphics2D g, String text)
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
78 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
79 Paint savePaint = g.getPaint();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
80 g.setPaint(textPaint);
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
81 g.setFont(textFont);
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
82
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
83 int i = 0;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
84 while (i < text.length())
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
85 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
86 int p = text.indexOf("\n", i);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
87 boolean linefeed;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
88 String str;
80
3d34258ccc2c Render empty lines correctly.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
89 if (p >= i)
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
90 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
91 str = text.substring(i, p);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
92 i = p + 1;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
93 linefeed = true;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
94 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
95 else
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
96 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
97 str = text.substring(i);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
98 i += str.length();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
99 linefeed = false;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
100 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
101
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
102 g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y);
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
103
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
104 if (linefeed)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
105 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
106 currOffs.x = 0;
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
107 currOffs.y += textMetrics.getHeight();
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
108 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
109 else
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
110 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
111 currOffs.x += textMetrics.stringWidth(str);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
112 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
113 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
114
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
115 g.setPaint(savePaint);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
116 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
117
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
118 public void paint(Graphics2D g)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
119 {
115
8c3bc197310d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
120 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f));
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
121 g.fill(new RoundRectangle2D.Float(getScaledX(), getScaledY(), getScaledWidth(), getScaledHeight(), 10, 10));
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
122
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
123 setTextFont(G.fonts[3], G.metrics[3]);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
124 setTextPaint(Color.white);
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
125
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
126 setCurrPosScaledRel(20, 30);
105
75015dfd47ef Move version number info to G.java.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
127 drawString(g, "RistiPolku (CrossPaths) v"+ G.version +"\n");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
128
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
129 setTextFont(G.fonts[1], G.metrics[1]);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
130 if (aboutSecret)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
131 {
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
132 g.drawImage(aboutImg, (int) getScaledRelX(20), (int) getScaledRelY(55),
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
133 aboutImg.getWidth(), aboutImg.getHeight(), null);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
134
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
135 setCurrPosScaledRel(225, 75);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
136 drawString(g,
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
137 "Dedicated to my\n" +
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
138 "favorite woman\n" +
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
139 "in the world.");
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
140
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
141 setCurrPosScaledRel(370, 175);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
142 drawString(g, "- Matti");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
143 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
144 else
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
145 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
146 setTextPaint(Color.yellow);
152
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
147 drawString(g, "(c) Copyright 2011 Tecnic Software productions (TNSP)\n");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
148
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
149 setTextPaint(Color.white);
152
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
150 drawString(g, "Programming, graphics and design by " +
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
151 "Matti 'ccr' Hämäläinen.\n" +
64b04c0eccce Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
152 "Audio from archive.org, used non-commercially.\n \n");
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
153
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
154 setTextPaint(Color.red);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
155 drawString(g, "Controls:\n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
156
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
157 IDMPoint old = currOffs.copy();
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
158
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
159 setTextPaint(Color.white);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
160 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
161 "Arrow keys / mouse wheel\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
162 "Enter / mouse click\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
163 "Space bar\n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
164
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
165 currPos.x += getScaledX(330);
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
166 currOffs.y = old.y;
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
167 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
168 "- Rotate piece\n" +
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
169 "- Place/lock piece\n" +
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
170 "- Swap piece\n");
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
171
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
172 currPos.x -= getScaledX(330);
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
173 setTextPaint(Color.green);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
174 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
175 "\nObjective: Create a path long as possible by rotating\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
176 "and placing pieces. More points will be awarded for\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
177 "advancing the path by several segments per turn."
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
178 );
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
179 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
180 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
181
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
182 public boolean keyPressed(KeyEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
183 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
184 if (e.getKeyCode() == KeyEvent.VK_L)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
185 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
186 aboutSecret = true;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
187 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
188 else
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
189 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
190 clicked();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
191 aboutSecret = false;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
192 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
193 return true;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
194 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
195
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
196 public void clicked()
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
197 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
198 parent.remove(this);
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
199 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
200 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
201
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
203 class GameBoard extends IDMWidget
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
205 static final int boardSize = 9;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
206 static final int boardMiddle = 4;
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
207 Piece[][] board;
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
208 float pscale, ptime;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
209
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
210 public boolean flagGameOver, flagBoardIsDirty;
119
52d79502447c Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
211 int gameScore;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
212
119
52d79502447c Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
213 Piece currPiece, nextPiece;
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
214 int currX, currY, currPoint;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
215
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
216 Sound sndPlaced;
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
217
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
218 private final ReentrantReadWriteLock pointLock = new ReentrantReadWriteLock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
219 private ArrayList<AnimatedPointElement> pointElems;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
220
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
221 public GameBoard(IDMPoint pos, float ps)
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
222 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
223 super(pos);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
224 pscale = ps;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
225
108
ae66d21d4747 Disable piece placement sound.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
226 // sndPlaced = G.smgr.getSound("sounds/placed.wav");
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
227
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
228 pointElems = new ArrayList<AnimatedPointElement>();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
229
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
230 startNewGame();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
231 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
232
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
233 public void startNewGame()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
234 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
235 board = new Piece[boardSize][boardSize];
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
236 board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
237
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
238 currX = boardMiddle;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
239 currY = boardMiddle;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
240 currPoint = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
241
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
242 currPiece = null;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
243 nextPiece = new Piece(PieceType.ACTIVE);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
244
65
dc936dba124e Set game over-flag correctly, so that we reset everything after a game over
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
245 flagGameOver = false;
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
246 flagBoardIsDirty = true;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
247 pieceFinishTurn();
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
248 gameScore = 0;
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
249 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
251 public void paintBackPlate(Graphics2D g)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
252 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
253 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.2f));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
254 g.setStroke(new BasicStroke(5.0f));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
255 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
256 boardSize * pscale, boardSize * pscale,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
257 pscale / 5, pscale / 5));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
258 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
259
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
260 public void paintBoard(Graphics2D g, boolean drawCurrent)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
261 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
262 for (int y = 0; y < boardSize; y++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
263 for (int x = 0; x < boardSize; x++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
264 if (board[x][y] != null)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
265 {
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
266 if ((drawCurrent && board[x][y] == currPiece) ||
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
267 (!drawCurrent && board[x][y] != currPiece))
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
268 {
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
269 board[x][y].paint(g,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
270 getScaledX() + (x * pscale),
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
271 getScaledY() + (y * pscale),
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
272 pscale - pscale / 10);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
273 }
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
274 }
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
275 }
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
276
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
277 public void paint(Graphics2D g)
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
278 {
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
279 paintBoard(g, true);
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
280
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
281 Lock read = pointLock.readLock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
282 read.lock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
283 try
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
284 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
285 for (AnimatedPointElement elem : pointElems)
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
286 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
287 elem.paint(g);
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
288 }
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
289 }
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
290 finally
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
291 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
292 read.unlock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
293 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
294
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
295
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
296 if (!flagGameOver)
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
297 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
298 if (nextPiece != null)
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
299 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
300 // Draw next piece
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
301 AffineTransform save = g.getTransform();
154
48b91eabc029 Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
302 nextPiece.paint(g, G.screenDim.width * 0.85f - 90.0f/2.0f, G.screenDim.height * 0.43f, 90.0f);
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
303 g.setTransform(save);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
304 }
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
305 }
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
306 else
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
307 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
308 // Game over text
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
309 String text = "Game Over!";
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
310 int textWidth = G.metrics[2].stringWidth(text);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
311 g.setFont(G.fonts[2]);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
312
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
313 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f));
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
314 g.drawString(text, (G.screenDim.width - textWidth) / 2 + 5, G.screenDim.height / 2 + 5);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
315
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
316 double f = Math.sin(ptime * 0.1) * 4.0;
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
317 g.setPaint(Color.white);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
318 g.drawString(text, (G.screenDim.width - textWidth) / 2 + (float) f, G.screenDim.height / 2 + (float) f);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
319 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
320
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
321 // Score
154
48b91eabc029 Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
322 String text = ""+ String.format("%05d", gameScore);
48b91eabc029 Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
323 int textWidth = G.metrics[2].stringWidth(text);
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
324 g.setFont(G.fonts[2]);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
325 g.setPaint(Color.white);
154
48b91eabc029 Improve scaling a bit, not completely functional yet.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
326 g.drawString(text, (G.screenDim.width * 0.85f) - textWidth / 2, G.screenDim.height * 0.3f);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
327 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
328
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
329 public boolean contains(float x, float y)
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
330 {
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
331 return (x >= getScaledX() &&
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
332 y >= getScaledY() &&
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
333 x < getScaledX() + boardSize * pscale &&
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
334 y < getScaledY() + boardSize * pscale);
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
335 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
336
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
337 public boolean isBoardDirty()
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
338 {
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
339 if (flagBoardIsDirty)
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
340 {
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
341 flagBoardIsDirty = false;
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
342 return true;
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
343 }
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
344 else
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
345 return false;
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
346 }
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
347
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
348 public void animate(float time)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
349 {
148
5b25561855c3 Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
350 if (nextPiece != null)
5b25561855c3 Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
351 {
5b25561855c3 Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
352 nextPiece.animate(time);
5b25561855c3 Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
353 }
5b25561855c3 Move next piece animation call into better place.
Matti Hamalainen <ccr@tnsp.org>
parents: 147
diff changeset
354
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
355 ptime = time;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
356 for (int y = 0; y < boardSize; y++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
357 for (int x = 0; x < boardSize; x++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
358 if (board[x][y] != null)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
359 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
360 board[x][y].animate(time);
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
361 if (board[x][y] != currPiece && board[x][y].active)
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
362 flagBoardIsDirty = true;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
363 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
364
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
365 Lock write = pointLock.writeLock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
366 write.lock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
367 try
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
368 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
369 ArrayList<AnimatedPointElement> tmp = new ArrayList<AnimatedPointElement>();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
370
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
371 for (AnimatedPointElement elem : pointElems)
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
372 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
373 elem.animate(time);
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
374 if (elem.active)
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
375 tmp.add(elem);
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
376 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
377
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
378 pointElems = tmp;
144
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
379
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
380 if (time % 32 == 1)
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
381 {
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
382 Random rnd = new Random();
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
383 pointElems.add(new AnimatedPointElement(
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
384 new IDMPoint(10 + rnd.nextInt(400), 10 + rnd.nextInt(100)), "."));
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
385 }
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
386 }
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
387 finally
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
388 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
389 write.unlock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
390 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
391 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
392
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
393 public void pieceRotate(Piece.RotateDir dir)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
394 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
395 if (currPiece != null && !flagGameOver)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
396 {
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
397 currPiece.rotate(dir);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
398 }
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
399 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
400
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
401 // Change coordinates based on the "outgoing"
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
402 // piece connection point.
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
403 private void pieceMoveTo(int point)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
404 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
405 switch (point)
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
406 {
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
407 case 0: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
408 case 1: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
409
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
410 case 2: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
411 case 3: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
412
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
413 case 4: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
414 case 5: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
415
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
416 case 6: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
417 case 7: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
418 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
419 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
420
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
421 public void pieceCreateNew()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
422 {
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
423 currPiece = nextPiece;
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
424 currPiece.changed();
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
425 nextPiece = new Piece(PieceType.ACTIVE);
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
426 flagBoardIsDirty = true;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
427 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
428
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
429 public void pieceSwapCurrent()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
430 {
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
431 if (!flagGameOver)
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
432 {
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
433 Piece tmp = currPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
434 currPiece = nextPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
435 nextPiece = tmp;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
436 board[currX][currY] = currPiece;
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
437 currPiece.changed();
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
438 nextPiece.changed();
139
be9cc2ee3c16 Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
439 flagBoardIsDirty = true;
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
440 }
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
441 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
442
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
443 // Check one piece, set connections, find the new placement
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
444 // based on piece rotations etc.
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
445 private boolean pieceCheck(Piece piece)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
446 {
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
447 if (piece == null)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
448 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
449 // Create new piece
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
450 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
451 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
452 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
453 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
454 else
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
455 if (piece.getType() == PieceType.START)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
456 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
457 if (currPiece != null)
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
458 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
459 // Hit center starting piece, game over
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
460 flagGameOver = true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
461 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
462 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
463 else
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
464 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
465 // Start piece as first piece means game is starting
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
466 pieceMoveTo(currPoint);
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
467 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
468 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
469 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
470 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
471 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
472
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
473 // Mark the current piece as locked
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
474 piece.setType(PieceType.LOCKED);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
475
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
476 // Solve connection (with rotations) through the piece
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
477 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
478
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
479 // Mark connection as active
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
480 piece.setConnectionState(currPoint, true);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
481
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
482 // Solve exit point (with rotations)
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
483 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
484
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
485 // Move to next position accordingly
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
486 pieceMoveTo(currPoint);
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
487 return false;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
488 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
489
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
490 // Finish one move/turn of the game, resolve path and find placement
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
491 // of the next piece, or set "game over" state if required.
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
492 public void pieceFinishTurn()
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
493 {
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
494 boolean finished = false;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
495 int connections = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
496
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
497 if (currPiece != null)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
498 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
499 G.smgr.play(sndPlaced);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
500 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
501
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
502 while (!finished)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
503 {
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
504 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize)
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
505 {
135
a33fdb1de11c Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
506 int oldX = currX, oldY = currY;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
507 connections++;
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
508 finished = pieceCheck(board[currX][currY]);
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
509
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
510 if (!finished)
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
511 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
512 Lock write = pointLock.writeLock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
513 write.lock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
514 try
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
515 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
516 pointElems.add(new AnimatedPointElement(
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
517 new IDMPoint(
135
a33fdb1de11c Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
518 getScaledX() + ((oldX + 0.5f) * pscale),
a33fdb1de11c Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
519 getScaledY() + ((oldY + 0.5f) * pscale)),
131
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
520 "" + connections));
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
521 }
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
522 finally
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
523 {
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
524 write.unlock();
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
525 }
67b2322fda91 Add spawning of animated score elements when player finishes a turn.
Matti Hamalainen <ccr@tnsp.org>
parents: 124
diff changeset
526 }
135
a33fdb1de11c Fix where the animated point elements appear initially.
Matti Hamalainen <ccr@tnsp.org>
parents: 134
diff changeset
527
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
528 }
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
529 else
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
530 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
531 // Outside of the board, game over
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
532 finished = true;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
533 flagGameOver = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
534 }
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
535 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
536
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
537 // Compute and add score
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
538 gameScore += connections * connections;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
539
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
540 // If game over, clear the game
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
541 if (flagGameOver)
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
542 {
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
543 currPiece = null;
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
544 }
139
be9cc2ee3c16 Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
545
be9cc2ee3c16 Minor fixes in updating logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 138
diff changeset
546 flagBoardIsDirty = true;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
547 }
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
548
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
549 public boolean mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
550 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
551 int notches = e.getWheelRotation();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
552
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
553 if (notches < 0)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
554 pieceRotate(Piece.RotateDir.LEFT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
555 else
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
556 pieceRotate(Piece.RotateDir.RIGHT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
557
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
558 return true;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
559 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
560
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
561 public void clicked()
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
562 {
77
d17db72ac770 Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
563 if (!flagGameOver)
d17db72ac770 Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
564 pieceFinishTurn();
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
565 }
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
566
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
567 public boolean keyPressed(KeyEvent e)
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
568 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
569 if (flagGameOver)
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
570 return false;
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
571
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
572 switch (e.getKeyCode())
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
573 {
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
574 case KeyEvent.VK_LEFT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
575 case KeyEvent.VK_UP:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
576 pieceRotate(Piece.RotateDir.LEFT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
577 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
578
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
579 case KeyEvent.VK_RIGHT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
580 case KeyEvent.VK_DOWN:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
581 pieceRotate(Piece.RotateDir.RIGHT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
582 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
583
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
584 case KeyEvent.VK_ENTER:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
585 pieceFinishTurn();
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
586 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
587 }
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
588 return false;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
589 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
590 }
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
591
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
592
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
593 public class Engine extends JPanel
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
594 implements Runnable, KeyListener,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
595 MouseListener, MouseWheelListener
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
596 {
164
2b2fa62cfea5 Fix animation timing.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
597 double startTime;
144
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
598 float gameUpdates, gameFrames;
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
599
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
600 Thread animThread;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
601 boolean animEnable = false;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
602
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
603 GameBoard lauta = null;
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
604 InputStream musa;
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
605 IDMContainer widgets;
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
606 AboutBox aboutBox;
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
607
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
608 public void dbg(String msg)
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
609 {
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
610 System.out.print("Engine: " + msg);
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
611 }
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
612
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
613 public Engine()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
614 {
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
615 // Initialize globals
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
616 System.out.print("Engine() constructor\n");
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
617
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
618 // Sound system
133
881deac2daf8 Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
619 G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 1);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
620
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
621 // Load resources
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
622 try
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
623 {
24
1be98362e5e9 FPS measurement.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
624 ResourceLoader res = new ResourceLoader("graphics/board.jpg");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
625 G.lautaBG = ImageIO.read(res.getStream());
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
626
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
627 try {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
628 res = new ResourceLoader("graphics/font.ttf");
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
629
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
630 G.fonts = new Font[G.numFonts];
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
631 G.baseFont = Font.createFont(Font.TRUETYPE_FONT, res.getStream());
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
632
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
633 setupDerivedFonts(1.0f);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
634 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
635 catch (FontFormatException e)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
636 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
637 dbg("Could not initialize fonts.\n");
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
638 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
639
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
640 res = new ResourceLoader("sounds/gamemusic.wav");
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
641 musa = res.getStream();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
642 }
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
643 catch (IOException e)
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
644 {
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
645 JOptionPane.showMessageDialog(null,
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
646 e.getMessage(),
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
647 "Initialization error",
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
648 JOptionPane.ERROR_MESSAGE);
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
649
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
650 dbg(e.getMessage());
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
651 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
652
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
653 // Create IDM GUI widgets
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
654 widgets = new IDMContainer();
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
655
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
656 lauta = new GameBoard(new IDMPoint(95, 130), 63);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
657 widgets.add(lauta);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
658
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
659 widgets.add(new BtnSwapPiece(767f, 450f));
124
fa1b86b632aa Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 119
diff changeset
660 widgets.add(new BtnAbout (767f, 550f));
fa1b86b632aa Slight changes in UI buttons placement to match the graphics changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 119
diff changeset
661 widgets.add(new BtnNewGame (767f, 630f));
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
662
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
663 aboutBox = new AboutBox();
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
664
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
665 // Game
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
666 startNewGame();
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
667
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
668 // Initialize event listeners
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
669 addKeyListener(this);
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
670 addMouseListener(this);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
671 addMouseWheelListener(this);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
672
93
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
673 // Start playing background music
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
674 G.smgr.play(musa);
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
675
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
676 // Get initial focus
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
677 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
678 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
679 dbg("Requesting focus.\n");
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
680 requestFocus();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
681 }
93
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
682
144
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
683 gameUpdates = 0;
164
2b2fa62cfea5 Fix animation timing.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
684 startTime = System.currentTimeMillis();
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
685 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
686
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
687 public void startNewGame()
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
688 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
689 gameFrames = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
690 lauta.startNewGame();
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
691 }
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
692
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
693 public void setupDerivedFonts(float scale)
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
694 {
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
695 G.fonts[0] = G.baseFont.deriveFont(16f * scale);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
696 G.fonts[1] = G.baseFont.deriveFont(22f * scale);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
697 G.fonts[2] = G.baseFont.deriveFont(62f * scale);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
698 G.fonts[3] = G.baseFont.deriveFont(32f * scale);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
699 }
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
700
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
701 public void paintComponent(Graphics g)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
702 {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
703 Graphics2D g2 = (Graphics2D) g;
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
704 boolean scaleChanged = false,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
705 updateBoard = lauta.isBoardDirty();
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
706
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
707 // Rescale if parent component size has changed
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
708 Dimension dim = getSize();
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
709 if (G.screenDim == null || !dim.equals(G.screenDim) || G.metrics == null)
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
710 {
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
711 dbg("Scale changed.\n");
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
712 scaleChanged = true;
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
713 updateBoard = true;
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
714
133
881deac2daf8 Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
715 float dw = dim.width / 1024.0f,
881deac2daf8 Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
716 dh = dim.height / 768.0f;
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
717
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
718 G.screenDim = dim;
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
719
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
720 // Rescale fonts
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
721 setupDerivedFonts(dw);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
722
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
723 // Get font metrics against current Graphics2D context
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
724 G.metrics = new FontMetrics[G.numFonts];
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
725 for (int i = 0; i < G.numFonts; i++)
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
726 G.metrics[i] = g2.getFontMetrics(G.fonts[i]);
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
727
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
728 // Rescale IDM GUI widgets
133
881deac2daf8 Some more work on scaling widgets, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 131
diff changeset
729 widgets.setScale(dw, dh);
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
730 }
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
731
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
732 if (updateBoard)
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
733 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
734 // dbg("updateBoard()\n");
138
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
735 G.lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
736 Graphics2D gimg = G.lautaBGScaled.createGraphics();
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
737 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
738 RenderingHints.VALUE_INTERPOLATION_BICUBIC);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
739
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
740 gimg.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
741 RenderingHints.VALUE_ANTIALIAS_ON);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
742
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
743 gimg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
744 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
745
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
746 gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
747 lauta.paintBackPlate(gimg);
9eb791e2fa17 Optimize board updating logic, so that the old placed tiles need not to be
Matti Hamalainen <ccr@tnsp.org>
parents: 135
diff changeset
748 lauta.paintBoard(gimg, false);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
749 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
750
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
751
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
752 // Draw background image, pieces, widgets
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
753 g2.drawImage(G.lautaBGScaled, 0, 0, null);
86
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
754
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
755 // Use antialiasing when rendering the game elements
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
756 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
757 RenderingHints.VALUE_ANTIALIAS_ON);
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
758
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
759 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
760 RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
454a9fcd13ca Turn antialiasing rendering hints on only for the needed elements to improve rendering speed and CPU usage.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
761
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
762 widgets.paint(g2);
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
763
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
764
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
765 // Frames per second counter
155
1ba6f56203f2 Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
766 /*
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
767 g2.setFont(G.fonts[1]);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
768 long currTime = new Date().getTime();
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
769 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20);
155
1ba6f56203f2 Disable FPS counter for now.
Matti Hamalainen <ccr@tnsp.org>
parents: 154
diff changeset
770 */
168
159252f9480d Fix animation choppiness.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
771
159252f9480d Fix animation choppiness.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
772 Toolkit.getDefaultToolkit().sync();
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
773 gameFrames++;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
774 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
775
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
776 public void startThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
777 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
778 dbg("startThreads()\n");
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
779 if (animThread == null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
780 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
781 animThread = new Thread(this);
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
782 animEnable = true;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
783 animThread.start();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
784 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
785 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
786
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
787 public void stopThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
788 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
789 dbg("stopThreads()\n");
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
790
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
791 // Stop animations
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
792 if (animThread != null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
793 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
794 animThread.interrupt();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
795 animEnable = false;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
796 animThread = null;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
797 }
22
afde253ec705 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
798
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
799 // Shut down sound manager
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
800 G.smgr.close();
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
801 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
802
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
803 public void mouseEntered(MouseEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
804 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
805 widgets.mouseEntered(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
806 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
807 public void mouseExited(MouseEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
808 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
809 widgets.mouseExited(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
810 }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
811
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
812 public void mousePressed(MouseEvent e)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
813 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
814 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
815 aboutBox.mousePressed(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
816 else
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
817 widgets.mousePressed(e);
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
818 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
819
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
820 public void mouseReleased(MouseEvent e)
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
821 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
822 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
823 aboutBox.mouseReleased(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
824 else
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
825 widgets.mouseReleased(e);
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
826 }
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
827
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
828 public void mouseClicked(MouseEvent e)
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
829 {
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
830 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
831 {
147
0ec311706d3c Clean up debug messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 144
diff changeset
832 dbg("Requesting focus.\n");
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
833 requestFocus();
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
834 }
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
835 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
836
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
837 public void mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
838 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
839 lauta.mouseWheelMoved(e);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
840 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
841
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
842 public void keyTyped(KeyEvent e) { }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
843 public void keyReleased(KeyEvent e) { }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
844
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
845 public void keyPressed(KeyEvent e)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
846 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
847 // Handle keyboard input
170
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
848
b9bc493ae53c Modularize and clean up code.
Matti Hamalainen <ccr@tnsp.org>
parents: 168
diff changeset
849 // About box is modal, so pass key events to it when active
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
850 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
851 aboutBox.keyPressed(e);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
852 else
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
853 widgets.keyPressed(e);
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
854 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
855
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
856 public void run()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
857 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
858 while (animEnable)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
859 {
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
860 // Progress game animation clock
144
f01cb1ea26a5 Add some decorative animated elements.
Matti Hamalainen <ccr@tnsp.org>
parents: 140
diff changeset
861 gameUpdates++;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
862
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
863 // Animate components
164
2b2fa62cfea5 Fix animation timing.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
864 int tmp = (int) ((System.currentTimeMillis() - startTime) / 10f);
2b2fa62cfea5 Fix animation timing.
Matti Hamalainen <ccr@tnsp.org>
parents: 162
diff changeset
865 lauta.animate(tmp);
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
866
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
867 // Repaint with a frame limiter
168
159252f9480d Fix animation choppiness.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
868 if (gameUpdates % 2 == 1)
10
4bacc98973f5 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
869 repaint();
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
870
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
871 // Sleep for a moment
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
872 try {
168
159252f9480d Fix animation choppiness.
Matti Hamalainen <ccr@tnsp.org>
parents: 164
diff changeset
873 Thread.sleep(15);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
874 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
875 catch (InterruptedException x) {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
876 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
877 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
878 }
134
4c0dec72e2f0 Whitespace cosmetic cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 133
diff changeset
879
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
880 class BtnNewGame extends IDMButton
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
881 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
882 public BtnNewGame(float x, float y)
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
883 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
884 super(x, y, KeyEvent.VK_ESCAPE, G.fonts[1], "New Game");
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
885 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
886
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
887 public void clicked()
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
888 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
889 startNewGame();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
890 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
891 }
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
892
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
893 class BtnSwapPiece extends IDMButton
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
894 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
895 public BtnSwapPiece(float x, float y)
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
896 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
897 super(x, y, KeyEvent.VK_SPACE, G.fonts[1], "Swap");
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
898 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
899
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
900 public void clicked()
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
901 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
902 lauta.pieceSwapCurrent();
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
903 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
904 }
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
905
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
906 class BtnAbout extends IDMButton
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
907 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
908 public BtnAbout(float x, float y)
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
909 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
910 super(x, y, KeyEvent.VK_A, G.fonts[1], "About");
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
911 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
912
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
913 public void clicked()
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
914 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
915 if (!widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
916 widgets.add(aboutBox);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
917 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
918 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
919 }