Mercurial > hg > ristipolku
annotate game/Engine.java @ 56:8718cc1c6586
Minor bugfixes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 23 Feb 2011 20:31:39 +0200 |
parents | 974ec36c562e |
children | 1435e9d7fd1a |
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 |
8 | 21 /* |
22 class AnimatedElement | |
23 { | |
24 float x, y, stime, value; | |
25 Interpolate lerp; | |
26 boolean active; | |
27 | |
28 public AnimatedElement(float x, float y, ) | |
29 { | |
30 stime = 0; | |
31 this.x = x; | |
32 this.y = y; | |
33 | |
34 } | |
35 | |
36 public animate(float time) | |
37 { | |
38 if (!active) | |
39 { | |
40 active = true; | |
41 stime = time; | |
42 } | |
43 | |
44 float t = (time - stime) / 10.0f; | |
45 if (t < 100) | |
46 value = lerp.getValue(t); | |
47 else | |
48 { | |
49 | |
50 } | |
51 } | |
52 | |
53 public paint(Graphics2D g, ); | |
54 { | |
55 } | |
56 } | |
57 */ | |
0 | 58 |
48 | 59 class GameBoard extends IDMWidget |
0 | 60 { |
2 | 61 public static final int boardSize = 9; |
62 public static final int boardMiddle = 4; | |
63 Piece[][] board; | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
64 |
8 | 65 public boolean flagGameOver; |
55 | 66 public int gameScore; |
54 | 67 |
68 public Piece currPiece, nextPiece; | |
41 | 69 int currX, currY, currPoint; |
9 | 70 |
48 | 71 |
47 | 72 SoundManager soundManager; |
73 Sound sndPlaced; | |
74 | |
75 public GameBoard(SoundManager smgr) | |
2 | 76 { |
77 board = new Piece[boardSize][boardSize]; | |
78 | |
79 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | |
80 | |
41 | 81 currX = boardMiddle; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
82 currY = boardMiddle; |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
83 currPoint = 0; |
8 | 84 |
54 | 85 nextPiece = new Piece(PieceType.ACTIVE); |
9 | 86 pieceFinishTurn(); |
8 | 87 |
88 flagGameOver = false; | |
55 | 89 gameScore = 0; |
47 | 90 |
91 soundManager = smgr; | |
50 | 92 // sndPlaced = soundManager.getSound("sounds/placed.wav"); |
2 | 93 } |
0 | 94 |
51 | 95 public void paint(Graphics2D g, float sx, float sy, float scale) |
2 | 96 { |
97 for (int y = 0; y < boardSize; y++) | |
98 for (int x = 0; x < boardSize; x++) | |
99 if (board[x][y] != null) | |
100 { | |
6 | 101 AffineTransform save = g.getTransform(); |
102 | |
4 | 103 board[x][y].paint(g, |
104 sx + (x * scale), | |
105 sy + (y * scale), | |
106 scale - scale / 10); | |
6 | 107 |
108 g.setTransform(save); | |
2 | 109 } |
110 } | |
9 | 111 |
112 public void animate(float time) | |
113 { | |
114 for (int y = 0; y < boardSize; y++) | |
115 for (int x = 0; x < boardSize; x++) | |
116 if (board[x][y] != null) | |
117 { | |
118 board[x][y].animate(time); | |
119 } | |
120 } | |
1 | 121 |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
122 public void pieceRotate(Piece.RotateDir dir) |
2 | 123 { |
41 | 124 if (currPiece != null) |
125 currPiece.rotate(dir); | |
2 | 126 } |
1 | 127 |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
128 private void pieceMoveTo(int point) |
7 | 129 { |
46 | 130 switch (point) |
131 { | |
132 case 0: currY--; break; | |
133 case 1: currY--; break; | |
134 | |
135 case 2: currX++; break; | |
136 case 3: currX++; break; | |
137 | |
138 case 4: currY++; break; | |
139 case 5: currY++; break; | |
140 | |
141 case 6: currX--; break; | |
142 case 7: currX--; break; | |
143 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
144 } |
9 | 145 |
54 | 146 public void pieceCreateNew() |
147 { | |
148 currPiece = nextPiece; | |
149 nextPiece = new Piece(PieceType.ACTIVE); | |
150 } | |
151 | |
152 public void pieceSwapCurrent() | |
153 { | |
56 | 154 if (!flagGameOver) |
155 { | |
156 Piece tmp = currPiece; | |
157 currPiece = nextPiece; | |
158 nextPiece = tmp; | |
159 board[currX][currY] = currPiece; | |
160 } | |
54 | 161 } |
162 | |
53 | 163 public boolean pieceCheck(Piece piece) |
48 | 164 { |
53 | 165 if (piece == null) |
48 | 166 { |
167 // Create new piece | |
56 | 168 pieceCreateNew(); |
48 | 169 board[currX][currY] = currPiece; |
170 return true; | |
171 } | |
172 else | |
53 | 173 if (piece.getType() == PieceType.START) |
48 | 174 { |
175 if (currPiece != null) | |
176 { | |
177 // Hit center starting piece, game over | |
178 flagGameOver = true; | |
179 return true; | |
180 } | |
181 else | |
182 { | |
183 // Start piece as first piece means game is starting | |
184 pieceMoveTo(currPoint); | |
54 | 185 pieceCreateNew(); |
48 | 186 board[currX][currY] = currPiece; |
187 return true; | |
188 } | |
189 } | |
190 | |
191 // Mark the current piece as locked | |
53 | 192 piece.setType(PieceType.LOCKED); |
48 | 193 |
194 // Solve connection (with rotations) through the piece | |
53 | 195 currPoint = piece.getRotatedPoint(piece.getMatchingPoint(currPoint)); |
48 | 196 |
197 // Mark connection as active | |
53 | 198 piece.setConnectionState(currPoint, true); |
48 | 199 |
200 // Solve exit point (with rotations) | |
53 | 201 currPoint = piece.getAntiRotatedPoint(piece.getConnection(currPoint)); |
48 | 202 |
203 // Move to next position accordingly | |
204 pieceMoveTo(currPoint); | |
205 return false; | |
206 } | |
207 | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
208 public void pieceFinishTurn() |
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
209 { |
48 | 210 boolean finished = false; |
55 | 211 int connections = 0; |
212 | |
48 | 213 while (!finished) |
7 | 214 { |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
215 if (currX >= 0 && currX < boardSize && currY >= 0 && currY < boardSize) |
27 | 216 { |
55 | 217 connections++; |
48 | 218 finished = pieceCheck(board[currX][currY]); |
27 | 219 } |
220 else | |
221 { | |
46 | 222 // Outside of the board, game over |
48 | 223 finished = true; |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
224 flagGameOver = true; |
7 | 225 } |
226 } | |
53 | 227 |
55 | 228 gameScore += connections * connections; |
229 | |
53 | 230 if (flagGameOver) |
231 { | |
232 currPiece = null; | |
233 System.out.print("GameOver!\n"); | |
234 } | |
42
951a4d669af0
Initially working path solving algorithm.
Matti Hamalainen <ccr@tnsp.org>
parents:
41
diff
changeset
|
235 } |
47 | 236 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
237 public boolean keyPressed(KeyEvent e) |
47 | 238 { |
54 | 239 if (flagGameOver) |
240 return false; | |
241 | |
47 | 242 switch (e.getKeyCode()) |
243 { | |
244 case KeyEvent.VK_LEFT: | |
245 case KeyEvent.VK_UP: | |
246 pieceRotate(Piece.RotateDir.LEFT); | |
247 return true; | |
248 | |
249 case KeyEvent.VK_RIGHT: | |
250 case KeyEvent.VK_DOWN: | |
251 pieceRotate(Piece.RotateDir.RIGHT); | |
252 return true; | |
253 | |
254 case KeyEvent.VK_ENTER: | |
255 soundManager.play(sndPlaced); | |
256 pieceFinishTurn(); | |
257 return true; | |
258 } | |
259 return false; | |
260 } | |
1 | 261 } |
262 | |
263 | |
9 | 264 public class Engine extends JPanel |
18 | 265 implements Runnable, KeyListener, MouseListener |
1 | 266 { |
25 | 267 long startTime; |
268 float gameClock, gameFrames; | |
8 | 269 Thread animThread; |
270 boolean animEnable = false; | |
25 | 271 |
272 Font fontMain, font1, font2; | |
55 | 273 FontMetrics metrics1, metrics2; |
274 | |
4 | 275 GameBoard lauta = null; |
9 | 276 BufferedImage lautaBG = null, lautaBGScaled = null; |
25 | 277 Dimension lautaDim; |
22 | 278 |
37 | 279 static final AudioFormat sfmt = new AudioFormat(22050, 16, 1, true, false); |
47 | 280 SoundManager soundManager; |
281 Sound musa; | |
1 | 282 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
283 IDMContainer widgets; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
284 |
9 | 285 public Engine() |
2 | 286 { |
25 | 287 // Initialize globals |
288 System.out.print("Engine() constructor\n"); | |
289 | |
37 | 290 // Sound system |
47 | 291 soundManager = new SoundManager(sfmt, 16); |
9 | 292 |
25 | 293 // Load resources |
4 | 294 try |
295 { | |
24 | 296 ResourceLoader res = new ResourceLoader("graphics/board.jpg"); |
18 | 297 lautaBG = ImageIO.read(res.getStream()); |
21 | 298 |
25 | 299 try { |
300 res = new ResourceLoader("graphics/font.ttf"); | |
301 fontMain = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); | |
55 | 302 |
25 | 303 font1 = fontMain.deriveFont(24f); |
55 | 304 font2 = fontMain.deriveFont(64f); |
25 | 305 } |
306 catch (FontFormatException e) | |
307 { | |
308 System.out.print("Could not initialize fonts.\n"); | |
309 } | |
37 | 310 |
56 | 311 // musa = soundManager.getSound("sounds/gamemusic.wav"); |
4 | 312 } |
313 catch (IOException e) | |
314 { | |
315 JOptionPane.showMessageDialog(null, | |
21 | 316 e.getMessage(), |
4 | 317 "Initialization error", |
318 JOptionPane.ERROR_MESSAGE); | |
37 | 319 |
21 | 320 System.out.print(e.getMessage()); |
18 | 321 } |
322 | |
52 | 323 // 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
|
324 widgets = new IDMContainer(); |
52 | 325 |
326 widgets.add(new BtnSwapPiece(0.75f, 0.60f)); | |
327 widgets.add(new BtnNewGame(0.75f, 0.85f)); | |
50 | 328 |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
329 // Game |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
330 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
331 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
332 // Initialize event listeners |
18 | 333 addKeyListener(this); |
334 addMouseListener(this); | |
335 | |
336 // Get initial focus | |
337 if (!hasFocus()) | |
338 { | |
339 System.out.print("Engine(): requesting focus\n"); | |
340 requestFocus(); | |
4 | 341 } |
37 | 342 |
47 | 343 soundManager.play(musa); |
8 | 344 } |
345 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
346 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
|
347 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
348 gameClock = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
349 gameFrames = 0; |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
350 startTime = new Date().getTime(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
351 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
352 lauta = new GameBoard(soundManager); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
353 } |
25 | 354 |
355 public void paintComponent(Graphics g) | |
356 { | |
357 Graphics2D g2 = (Graphics2D) g; | |
358 | |
359 // Use antialiasing when rendering the game elements | |
360 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, | |
361 RenderingHints.VALUE_ANTIALIAS_ON); | |
362 | |
363 g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, | |
364 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); | |
365 | |
52 | 366 // Rescale if parent component size has changed |
25 | 367 Dimension dim = getSize(); |
368 if (lautaDim == null || !dim.equals(lautaDim)) | |
369 { | |
52 | 370 // Rescale background image |
25 | 371 lautaBGScaled = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB); |
372 Graphics2D gimg = lautaBGScaled.createGraphics(); | |
373 gimg.setRenderingHint(RenderingHints.KEY_INTERPOLATION, | |
374 RenderingHints.VALUE_INTERPOLATION_BICUBIC); | |
375 | |
376 gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); | |
377 lautaDim = dim; | |
378 | |
52 | 379 // Rescale IDM GUI widgets |
51 | 380 widgets.setScale(dim.width, dim.height); |
52 | 381 |
25 | 382 System.out.print("scale changed\n"); |
383 } | |
384 | |
55 | 385 if (metrics1 == null) |
386 metrics1 = g2.getFontMetrics(font1); | |
387 | |
388 if (metrics2 == null) | |
389 metrics2 = g2.getFontMetrics(font2); | |
390 | |
52 | 391 // Background image, pieces |
25 | 392 g2.drawImage(lautaBGScaled, 0, 0, null); |
52 | 393 lauta.paint(g2, 90, 140, 65); |
55 | 394 |
395 if (!lauta.flagGameOver) | |
396 { | |
397 lauta.nextPiece.paint(g2, 830, 325, 90); | |
398 } | |
399 else | |
400 { | |
401 String text = "Game Over!"; | |
402 int textWidth = metrics2.stringWidth(text); | |
403 g2.setFont(font2); | |
404 | |
405 g2.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.5f)); | |
406 g2.drawString(text, (dim.width - textWidth) / 2 + 5, dim.height / 2 + 5); | |
407 | |
408 double f = Math.sin(gameClock * 0.1) * 4.0; | |
409 g2.setPaint(Color.white); | |
410 g2.drawString(text, (dim.width - textWidth) / 2 + (float) f, dim.height / 2 + (float) f); | |
411 } | |
412 | |
50 | 413 widgets.paint(g2); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
414 |
52 | 415 // Scores, etc |
55 | 416 g2.setFont(font2); |
25 | 417 g2.setPaint(Color.white); |
50 | 418 |
55 | 419 g2.drawString(""+ String.format("%05d", lauta.gameScore), dim.width - 230, 220); |
420 | |
421 g2.setFont(font1); | |
25 | 422 long currTime = new Date().getTime(); |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
423 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); |
25 | 424 } |
425 | |
8 | 426 public void startThreads() |
427 { | |
9 | 428 System.out.print("startThreads()\n"); |
8 | 429 if (animThread == null) |
430 { | |
431 animThread = new Thread(this); | |
432 animEnable = true; | |
433 animThread.start(); | |
434 } | |
435 } | |
436 | |
437 public void stopThreads() | |
438 { | |
9 | 439 System.out.print("stopThreads()\n"); |
37 | 440 |
441 // Stop animations | |
8 | 442 if (animThread != null) |
443 { | |
444 animThread.interrupt(); | |
445 animEnable = false; | |
446 animThread = null; | |
447 } | |
22 | 448 |
37 | 449 // Shut down sound manager |
47 | 450 soundManager.close(); |
2 | 451 } |
0 | 452 |
18 | 453 public void mouseEntered(MouseEvent e) { } |
454 public void mouseExited(MouseEvent e) { } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
455 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
456 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
|
457 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
458 widgets.mousePressed(e); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
459 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
460 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
461 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
|
462 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
463 widgets.mouseReleased(e); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
464 } |
18 | 465 |
466 public void mouseClicked(MouseEvent e) | |
467 { | |
468 System.out.print("mouseClicked()\n"); | |
469 if (!hasFocus()) | |
470 { | |
471 System.out.print("requesting focus\n"); | |
472 requestFocus(); | |
473 } | |
474 } | |
475 | |
9 | 476 public void keyTyped(KeyEvent e) |
2 | 477 { |
478 } | |
1 | 479 |
2 | 480 public void keyReleased(KeyEvent e) |
481 { | |
482 } | |
1 | 483 |
9 | 484 public void keyPressed(KeyEvent e) |
2 | 485 { |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
486 // Handle keyboard input |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
487 if (lauta.keyPressed(e)) |
47 | 488 return; |
489 | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
490 widgets.keyPressed(e); |
2 | 491 } |
8 | 492 |
493 public void run() | |
494 { | |
495 while (animEnable) | |
496 { | |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
497 // Progress game animation clock |
25 | 498 gameClock++; |
9 | 499 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
500 // Animate components |
55 | 501 if (!lauta.flagGameOver) |
502 { | |
503 lauta.animate(gameClock); | |
504 lauta.nextPiece.animate(gameClock); | |
505 } | |
9 | 506 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
507 // Repaint with a frame limiter |
25 | 508 if (gameClock % 3 == 1) |
24 | 509 { |
10 | 510 repaint(); |
25 | 511 gameFrames++; |
24 | 512 } |
32
e480579cc460
More work on debugging the path resolving.
Matti Hamalainen <ccr@tnsp.org>
parents:
30
diff
changeset
|
513 |
26
3d4cc47df31a
Cleanups, fix piece rendering and rotation.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
514 // Sleep for a moment |
9 | 515 try { |
516 Thread.sleep(10); | |
517 } | |
518 catch (InterruptedException x) { | |
519 } | |
8 | 520 } |
521 } | |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
522 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
523 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
|
524 { |
51 | 525 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
|
526 { |
51 | 527 super(x, y, KeyEvent.VK_ESCAPE, font1, "Uusi peli"); |
49
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
528 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
529 |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
530 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
|
531 { |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
532 startNewGame(); |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
533 } |
e6da5c71be28
Add more code to IDM widgets, do preliminary work for integrating them.
Matti Hamalainen <ccr@tnsp.org>
parents:
48
diff
changeset
|
534 } |
50 | 535 |
536 class BtnSwapPiece extends IDMButton | |
537 { | |
51 | 538 public BtnSwapPiece(float x, float y) |
50 | 539 { |
51 | 540 super(x, y, KeyEvent.VK_SPACE, font1, "Vaihda"); |
50 | 541 } |
542 | |
543 public void clicked() | |
544 { | |
54 | 545 lauta.pieceSwapCurrent(); |
50 | 546 } |
547 } | |
0 | 548 } |