annotate game/Engine.java @ 124:fa1b86b632aa

Slight changes in UI buttons placement to match the graphics changes.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 24 Nov 2011 15:29:04 +0200
parents 52d79502447c
children 67b2322fda91
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
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
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.*;
6
be0bf7544069 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
16 import java.io.*;
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
17 import game.*;
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
18 import javax.sound.sampled.*;
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
19
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
20
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
21 class AboutBox extends IDMWidget
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
22 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
23 BufferedImage aboutImg;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
24 boolean aboutSecret;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
25
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
26 IDMPoint currPos, currOffs;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
27 Paint textPaint;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
28 Font textFont;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
29 FontMetrics textMetrics;
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
30
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
31
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
32 public AboutBox()
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
33 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
34 try {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
35 ResourceLoader res = new ResourceLoader("graphics/girl.jpg");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
36 aboutImg = ImageIO.read(res.getStream());
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
37 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
38 catch (IOException e)
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 }
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 aboutSecret = false;
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 setPos(150f, 150f);
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
45 setSize(675f, 420f);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
46 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
47
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
48 public void setTextFont(Font font, FontMetrics metrics)
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 textFont = font;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
51 textMetrics = metrics;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
52 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
53
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
54 public void setTextPaint(Paint paint)
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
55 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
56 textPaint = paint;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
57 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
58
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
59 public void setCurrPos(IDMPoint npos)
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 currPos = npos;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
62 currOffs = new IDMPoint(0, 0);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
63 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
64
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
65 public void setCurrPos(float x, float y)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
66 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
67 setCurrPos(new IDMPoint(x, y));
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
68 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
69
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
70 public void drawString(Graphics2D g, String text)
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
71 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
72 Paint savePaint = g.getPaint();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
73 g.setPaint(textPaint);
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
74 g.setFont(textFont);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
76 int i = 0;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
77 while (i < text.length())
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 int p = text.indexOf("\n", i);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
80 boolean linefeed;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
81 String str;
80
3d34258ccc2c Render empty lines correctly.
Matti Hamalainen <ccr@tnsp.org>
parents: 77
diff changeset
82 if (p >= i)
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
83 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
84 str = text.substring(i, p);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
85 i = p + 1;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
86 linefeed = true;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
87 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
88 else
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
89 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
90 str = text.substring(i);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
91 i += str.length();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
92 linefeed = false;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
93 }
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 g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y);
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 if (linefeed)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
98 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
99 currOffs.x = 0;
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
100 currOffs.y += textMetrics.getHeight();
75
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 else
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
103 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
104 currOffs.x += textMetrics.stringWidth(str);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
105 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
106 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
107
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
108 g.setPaint(savePaint);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
109 }
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 public void paint(Graphics2D g)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
112 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
113 int x = getScaledX(), y = getScaledY(),
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
114 w = getScaledWidth(), h = getScaledHeight();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
115
115
8c3bc197310d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
116 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.7f));
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
117 g.fill(new RoundRectangle2D.Float(x, y, w, h, 10, 10));
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
118
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
119 setTextFont(G.fonts[3], G.metrics[3]);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
120 setTextPaint(Color.white);
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
121
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
122 setCurrPos(x + 20, y + 30);
105
75015dfd47ef Move version number info to G.java.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
123 drawString(g, "RistiPolku (CrossPaths) v"+ G.version +"\n");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
124
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
125 setTextFont(G.fonts[1], G.metrics[1]);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
126 if (aboutSecret)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
127 {
115
8c3bc197310d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
128 g.drawImage(aboutImg, x + 20, y + 55,
8c3bc197310d Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 108
diff changeset
129 aboutImg.getWidth(), aboutImg.getHeight(), null);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
130
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
131 setCurrPos(x + 225, y + 75);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
132 drawString(g,
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
133 "Dedicated to my\n" +
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
134 "favorite woman\n" +
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
135 "in the world.");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
136
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
137 setCurrPos(x + 370, y + 175);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
138 drawString(g, "- Matti");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
139 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
140 else
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
141 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
142 setTextPaint(Color.yellow);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
143 drawString(g, "(c) Copyright 2011 Matti 'ccr' Hämäläinen\n");
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
144
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
145 setTextPaint(Color.white);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
146 drawString(g, "Programming project for Java-course\n" +
81
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
147 "T740306 taught by Kari Laitinen." +
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
148 "\n \n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
149
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
150 setTextPaint(Color.red);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
151 drawString(g, "Controls:\n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
152
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
153 IDMPoint old = currOffs.copy();
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
154
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
155 setTextPaint(Color.white);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
156 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
157 "Arrow keys / mouse wheel\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
158 "Enter / mouse click\n"+
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
159 "Space bar\n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
160
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
161 currPos.x += 330;
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
162 currOffs.y = old.y;
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
163 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
164 "- Rotate piece\n" +
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
165 "- Place/lock piece\n" +
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
166 "- Swap piece\n");
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
167
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
168 currPos.x -= 330;
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
169 setTextPaint(Color.green);
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
170 drawString(g,
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
171 "\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
172 "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
173 "advancing the path by several segments per turn."
8932b1300ba1 Adjust about box size, add instructions.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
174 );
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
175 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
176 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
177
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
178 public boolean keyPressed(KeyEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
179 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
180 if (e.getKeyCode() == KeyEvent.VK_L)
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 aboutSecret = true;
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 else
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 clicked();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
187 aboutSecret = false;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
188 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
189 return true;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
190 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
191
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
192 public void clicked()
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
193 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
194 parent.remove(this);
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
195 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
196 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
197
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
199 class GameBoard extends IDMWidget
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
201 static final int boardSize = 9;
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
202 static final int boardMiddle = 4;
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
203 Piece[][] board;
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
204 float pscale, ptime;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
205
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
206 public boolean flagGameOver;
119
52d79502447c Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
207 int gameScore;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
208
119
52d79502447c Make few variables un-public.
Matti Hamalainen <ccr@tnsp.org>
parents: 117
diff changeset
209 Piece currPiece, nextPiece;
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
210 int currX, currY, currPoint;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
211
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
212 Sound sndPlaced;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
213
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
214 public GameBoard(IDMPoint pos, float ps)
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
215 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
216 super(pos);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
217 pscale = ps;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
218
108
ae66d21d4747 Disable piece placement sound.
Matti Hamalainen <ccr@tnsp.org>
parents: 106
diff changeset
219 // sndPlaced = G.smgr.getSound("sounds/placed.wav");
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
220
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
221 startNewGame();
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
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
224 public void startNewGame()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
225 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
226 board = new Piece[boardSize][boardSize];
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
227 board[boardMiddle][boardMiddle] = new Piece(PieceType.START);
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
228
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
229 currX = boardMiddle;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
230 currY = boardMiddle;
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
231 currPoint = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
232
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
233 currPiece = null;
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
234 nextPiece = new Piece(PieceType.ACTIVE);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
235
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
236 flagGameOver = false;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
237 pieceFinishTurn();
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
238 gameScore = 0;
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
239 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
241 public void paintBackPlate(Graphics2D g)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
242 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
243 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
244 g.setStroke(new BasicStroke(5.0f));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
245 g.draw(new RoundRectangle2D.Float(getScaledX(), getScaledY(),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
246 boardSize * pscale, boardSize * pscale,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
247 pscale / 5, pscale / 5));
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
248 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
249
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
250 public void paint(Graphics2D g)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
251 {
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
252 for (int y = 0; y < boardSize; y++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
253 for (int x = 0; x < boardSize; x++)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
254 if (board[x][y] != null)
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
255 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
256 board[x][y].paint(g,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
257 getScaledX() + (x * pscale),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
258 getScaledY() + (y * pscale),
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
259 pscale - pscale / 10);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
260 }
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
261
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
262 if (!flagGameOver)
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
263 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
264 if (nextPiece != null)
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
265 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
266 // Draw next piece
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
267 AffineTransform save = g.getTransform();
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
268 nextPiece.paint(g, 830, 325, 90);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
269 g.setTransform(save);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
270 }
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
271 }
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
272 else
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
273 {
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
274 // Game over text
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
275 String text = "Game Over!";
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
276 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
277 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
278
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
279 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
280 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
281
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
282 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
283 g.setPaint(Color.white);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
284 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
285 }
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
286
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
287 // Score
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
288 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
289 g.setPaint(Color.white);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
290 g.drawString(""+ String.format("%05d", gameScore), G.screenDim.width - 230, 220);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
291
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
292 }
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
293
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
294 public boolean contains(float x, float y)
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
295 {
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
296 return (x >= getScaledX() &&
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
297 y >= getScaledY() &&
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
298 x < getScaledX() + boardSize * pscale &&
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
299 y < getScaledY() + boardSize * pscale);
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
300 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
301
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
302 public void animate(float time)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
303 {
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
304 ptime = time;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
305 for (int y = 0; y < boardSize; y++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
306 for (int x = 0; x < boardSize; x++)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
307 if (board[x][y] != null)
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
308 {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
309 board[x][y].animate(time);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
310 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
311 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
312
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
313 public void pieceRotate(Piece.RotateDir dir)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
314 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
315 if (currPiece != null && !flagGameOver)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
316 {
41
a5fd4f74a767 Rename some variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 40
diff changeset
317 currPiece.rotate(dir);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
318 }
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
319 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
320
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
321 // Change coordinates based on the "outgoing"
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
322 // piece connection point.
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
323 private void pieceMoveTo(int point)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
324 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
325 switch (point)
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
326 {
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
327 case 0: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
328 case 1: currY--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
329
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
330 case 2: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
331 case 3: currX++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
332
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
333 case 4: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
334 case 5: currY++; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
335
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
336 case 6: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
337 case 7: currX--; break;
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
338 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
339 }
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
340
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
341 public void pieceCreateNew()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
342 {
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
343 currPiece = nextPiece;
106
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
344 currPiece.changed();
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
345 nextPiece = new Piece(PieceType.ACTIVE);
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
346 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
347
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
348 public void pieceSwapCurrent()
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
349 {
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
350 if (!flagGameOver)
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
351 {
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
352 Piece tmp = currPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
353 currPiece = nextPiece;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
354 nextPiece = tmp;
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
355 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
356 currPiece.changed();
41c6cca69d60 Make new pieces appear gradually, and same effect for swapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 105
diff changeset
357 nextPiece.changed();
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
358 }
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
359 }
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
360
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
361 // Check one piece, set connections, find the new placement
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
362 // based on piece rotations etc.
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
363 private boolean pieceCheck(Piece piece)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
364 {
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
365 if (piece == null)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
366 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
367 // Create new piece
56
8718cc1c6586 Minor bugfixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 55
diff changeset
368 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
369 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
370 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
371 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
372 else
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
373 if (piece.getType() == PieceType.START)
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
374 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
375 if (currPiece != null)
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
376 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
377 // Hit center starting piece, game over
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
378 flagGameOver = true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
379 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
380 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
381 else
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
382 {
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
383 // Start piece as first piece means game is starting
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
384 pieceMoveTo(currPoint);
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
385 pieceCreateNew();
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
386 board[currX][currY] = currPiece;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
387 return true;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
388 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
389 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
390
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
391 // Mark the current piece as locked
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
392 piece.setType(PieceType.LOCKED);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
393
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
394 // Solve connection (with rotations) through the piece
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
395 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
396
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
397 // Mark connection as active
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
398 piece.setConnectionState(currPoint, true);
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
399
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
400 // Solve exit point (with rotations)
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
401 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint));
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
402
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
403 // Move to next position accordingly
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
404 pieceMoveTo(currPoint);
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
405 return false;
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
406 }
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
407
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
408 // 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
409 // 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
410 public void pieceFinishTurn()
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
411 {
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
412 boolean finished = false;
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
413 int connections = 0;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
414
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
415 if (currPiece != null)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
416 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
417 G.smgr.play(sndPlaced);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
418 }
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
419
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
420 while (!finished)
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
421 {
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
422 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
423 {
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
424 connections++;
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
425 finished = pieceCheck(board[currX][currY]);
27
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
426 }
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
427 else
26adc2827983 More work on the internals.
Matti Hamalainen <ccr@tnsp.org>
parents: 26
diff changeset
428 {
46
3e8d1c30f573 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 44
diff changeset
429 // Outside of the board, game over
48
f13bab4cccd3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 47
diff changeset
430 finished = true;
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
431 flagGameOver = true;
7
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
432 }
70714c229e23 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
433 }
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
434
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
435 // Compute and add score
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
436 gameScore += connections * connections;
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
437
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
438 // If game over, clear the game
53
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
439 if (flagGameOver)
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
440 {
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
441 currPiece = null;
6bf4675e2d96 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 52
diff changeset
442 }
42
951a4d669af0 Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents: 41
diff changeset
443 }
66
d406e14b870d Add comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
444
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
445 public boolean mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
446 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
447 int notches = e.getWheelRotation();
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
448
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
449 if (notches < 0)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
450 pieceRotate(Piece.RotateDir.LEFT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
451 else
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
452 pieceRotate(Piece.RotateDir.RIGHT);
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
453
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
454 return true;
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
455 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
456
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
457 public void clicked()
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
458 {
77
d17db72ac770 Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
459 if (!flagGameOver)
d17db72ac770 Fix the game continuing after gameover bug again due to refactoring.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
460 pieceFinishTurn();
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
461 }
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
462
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
463 public boolean keyPressed(KeyEvent e)
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
464 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
465 if (flagGameOver)
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
466 return false;
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
467
47
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
468 switch (e.getKeyCode())
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
469 {
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
470 case KeyEvent.VK_LEFT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
471 case KeyEvent.VK_UP:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
472 pieceRotate(Piece.RotateDir.LEFT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
473 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
474
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
475 case KeyEvent.VK_RIGHT:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
476 case KeyEvent.VK_DOWN:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
477 pieceRotate(Piece.RotateDir.RIGHT);
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
478 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
479
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
480 case KeyEvent.VK_ENTER:
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
481 pieceFinishTurn();
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
482 return true;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
483 }
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
484 return false;
695cf13c103a Move some code.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
485 }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
486 }
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
487
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
488
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
489 public class Engine extends JPanel
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
490 implements Runnable, KeyListener,
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
491 MouseListener, MouseWheelListener
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
492 {
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
493 long startTime;
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
494 float gameClock, gameFrames;
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
495
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
496 Thread animThread;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
497 boolean animEnable = false;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
498
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
499 GameBoard lauta = null;
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
500 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
501 IDMContainer widgets;
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
502 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
503
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
504 public Engine()
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
505 {
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
506 // Initialize globals
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
507 System.out.print("Engine() constructor\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
508
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
509 // Sound system
116
858b9644a61e Adjusts number of max simultaneous sounds.
Matti Hamalainen <ccr@tnsp.org>
parents: 115
diff changeset
510 G.smgr = new SoundManager(new AudioFormat(22050, 16, 1, true, false), 16);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
511
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
512 // Load resources
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
513 try
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
514 {
24
1be98362e5e9 FPS measurement.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
515 ResourceLoader res = new ResourceLoader("graphics/board.jpg");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
516 G.lautaBG = ImageIO.read(res.getStream());
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
517
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
518 try {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
519 res = new ResourceLoader("graphics/font.ttf");
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
520
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
521 G.fonts = new Font[G.numFonts];
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
522 G.fonts[0] = Font.createFont(Font.TRUETYPE_FONT, res.getStream());
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
523 G.fonts[1] = G.fonts[0].deriveFont(24f);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
524 G.fonts[2] = G.fonts[0].deriveFont(64f);
76
43f68fe605de More cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
525 G.fonts[3] = G.fonts[0].deriveFont(32f);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
526
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
527 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
528 catch (FontFormatException e)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
529 {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
530 System.out.print("Could not initialize fonts.\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
531 }
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
532
69
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
533 res = new ResourceLoader("sounds/gamemusic.wav");
163232ec225b Stream music data instead of loading to memory.
Matti Hamalainen <ccr@tnsp.org>
parents: 68
diff changeset
534 musa = res.getStream();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
535 }
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
536 catch (IOException e)
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
537 {
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
538 JOptionPane.showMessageDialog(null,
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
539 e.getMessage(),
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
540 "Initialization error",
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
541 JOptionPane.ERROR_MESSAGE);
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
542
21
df494a65bf8c More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 18
diff changeset
543 System.out.print(e.getMessage());
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
544 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
545
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
546 // 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
547 widgets = new IDMContainer();
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
548
117
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
549 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
550 widgets.add(lauta);
973f567c7b9d Change how gameboard is rendered, make it more OO-sensible.
Matti Hamalainen <ccr@tnsp.org>
parents: 116
diff changeset
551
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
552 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
553 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
554 widgets.add(new BtnNewGame (767f, 630f));
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
555
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
556 aboutBox = new AboutBox();
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
557
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
558 // Game
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
559 startNewGame();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
560
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
561 // Initialize event listeners
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
562 addKeyListener(this);
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
563 addMouseListener(this);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
564 addMouseWheelListener(this);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
565
93
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
566 // Start playing background music
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
567 G.smgr.play(musa);
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
568
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
569 // Get initial focus
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
570 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
571 {
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
572 System.out.print("Engine(): requesting focus\n");
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
573 requestFocus();
4
e0e8fd08331e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
574 }
93
e1d657e6c25b Work on audio code.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
575
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
576 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
577
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
578 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
579 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
580 gameClock = 0;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
581 gameFrames = 0;
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
582 startTime = new Date().getTime();
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
583 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
584 }
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
585
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
586 public void paintComponent(Graphics g)
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
587 {
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
588 Graphics2D g2 = (Graphics2D) g;
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
589
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
590 // Rescale if parent component size has changed
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
591 Dimension dim = getSize();
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
592 if (G.screenDim == null || !dim.equals(G.screenDim))
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
593 {
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
594 // Rescale IDM GUI widgets
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
595 widgets.setScale(dim.width / 1024.0f, dim.height / 768.0f);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
596 G.screenDim = dim;
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
597
52
01851bae3da3 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 51
diff changeset
598 // Rescale background image
87
6afbf88c8bda Change background image type from RGBA to RGB only, improves rendering speed.
Matti Hamalainen <ccr@tnsp.org>
parents: 86
diff changeset
599 G.lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_RGB);
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
600 Graphics2D gimg = G.lautaBGScaled.createGraphics();
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
601 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
602 RenderingHints.VALUE_INTERPOLATION_BICUBIC);
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
603
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
604 gimg.drawImage(G.lautaBG, 0, 0, dim.width, dim.height, null);
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
605 lauta.paintBackPlate(gimg);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
606
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
607 System.out.print("scale changed\n");
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
608 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
609
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
610 // Get font metrics against current Graphics2D context
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
611 if (G.metrics == null)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
612 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
613 G.metrics = new FontMetrics[G.numFonts];
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
614 for (int i = 0; i < G.numFonts; i++)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
615 G.metrics[i] = g2.getFontMetrics(G.fonts[i]);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
616 }
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
617
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
618 // Draw background image, pieces, widgets
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
619 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
620
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
621 // 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
622 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
623 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
624
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
625 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
626 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
627
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
628 widgets.paint(g2);
55
974ec36c562e Updates.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
629
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
630
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
631 // Frames per second counter
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
632 g2.setFont(G.fonts[1]);
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
633 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
634 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), G.screenDim.width - 120, 20);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
635
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
636 gameFrames++;
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
637 }
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
638
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
639 public void startThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
640 {
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
641 System.out.print("startThreads()\n");
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
642 if (animThread == null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
643 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
644 animThread = new Thread(this);
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
645 animEnable = true;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
646 animThread.start();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
647 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
648 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
649
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
650 public void stopThreads()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
651 {
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
652 System.out.print("stopThreads()\n");
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
653
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
654 // Stop animations
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
655 if (animThread != null)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
656 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
657 animThread.interrupt();
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
658 animEnable = false;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
659 animThread = null;
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
660 }
22
afde253ec705 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
661
37
3dc5ae9f1c80 Work on game logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 35
diff changeset
662 // Shut down sound manager
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
663 G.smgr.close();
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
664 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
666 public void mouseEntered(MouseEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
667 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
668 widgets.mouseEntered(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
669 }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
670 public void mouseExited(MouseEvent e)
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
671 {
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
672 widgets.mouseExited(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
673 }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
674
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
675 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
676 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
677 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
678 aboutBox.mousePressed(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
679 else
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
680 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
681 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
682
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
683 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
684 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
685 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
686 aboutBox.mouseReleased(e);
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
687 else
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
688 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
689 }
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
690
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
691 public void mouseClicked(MouseEvent e)
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
692 {
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
693 if (!hasFocus())
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
694 {
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
695 System.out.print("Requesting focus\n");
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
696 requestFocus();
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
697 }
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
698 }
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
699
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
700 public void mouseWheelMoved(MouseWheelEvent e)
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
701 {
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
702 lauta.mouseWheelMoved(e);
18
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
703 }
4507a431b410 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
704
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
705 public void keyTyped(KeyEvent e) { }
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
706 public void keyReleased(KeyEvent e) { }
1
44f1e7b47fcf Preliminary work ... puuh.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
707
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
708 public void keyPressed(KeyEvent e)
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
709 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
710 // Handle keyboard input
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
711 if (widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
712 aboutBox.keyPressed(e);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
713 else
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
714 widgets.keyPressed(e);
2
1785f66a7beb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1
diff changeset
715 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
716
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
717 public void run()
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
718 {
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
719 while (animEnable)
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
720 {
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
721 // Progress game animation clock
25
bbac3e4a4b9b Cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
722 gameClock++;
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
723
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
724 // Animate components
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
725 lauta.animate(gameClock);
62
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
726 if (lauta.nextPiece != null)
caf67c7e0814 Fix a possible null pointer exception under certain circumstances.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
727 lauta.nextPiece.animate(gameClock);
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
728
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
729 // Repaint with a frame limiter
59
fd10a9422b60 Cleanups, bugfixes, etc etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
730 if (gameClock % 4 == 1)
10
4bacc98973f5 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 9
diff changeset
731 repaint();
32
e480579cc460 More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents: 30
diff changeset
732
26
3d4cc47df31a Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents: 25
diff changeset
733 // Sleep for a moment
9
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
734 try {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
735 Thread.sleep(10);
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
736 }
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
737 catch (InterruptedException x) {
a7751971c2a3 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
738 }
8
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
739 }
d8e7fd8f3ccf Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
740 }
49
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
741
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
742 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
743 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
744 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
745 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
746 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
747 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
748
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
749 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
750 {
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
751 startNewGame();
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
752 }
e6da5c71be28 Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents: 48
diff changeset
753 }
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
754
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
755 class BtnSwapPiece extends IDMButton
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
756 {
51
f81f76458b92 Work on widgets.
Matti Hamalainen <ccr@tnsp.org>
parents: 50
diff changeset
757 public BtnSwapPiece(float x, float y)
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
758 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
759 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
760 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
761
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
762 public void clicked()
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
763 {
54
cc7943cd7f2d Moar work.
Matti Hamalainen <ccr@tnsp.org>
parents: 53
diff changeset
764 lauta.pieceSwapCurrent();
50
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
765 }
496e616ff09d More work on IDMgui.
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
766 }
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
767
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
768 class BtnAbout extends IDMButton
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
769 {
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
770 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
771 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
772 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
773 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
774
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
775 public void clicked()
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
776 {
75
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
777 if (!widgets.containsObject(aboutBox))
b586ce4f6d97 Large GUI code cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 71
diff changeset
778 widgets.add(aboutBox);
60
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
779 }
4a984e3b27d2 Cleanups. Add a ad-hoc about box, it's ugly.
Matti Hamalainen <ccr@tnsp.org>
parents: 59
diff changeset
780 }
0
f930f72ed0f5 Initial import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
781 }