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