Mercurial > hg > ristipolku
comparison game/Engine.java @ 32:e480579cc460
More work on debugging the path resolving.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 03 Feb 2011 18:22:16 +0200 |
parents | 60a4579a79df |
children | aa15b2c556b4 |
comparison
equal
deleted
inserted
replaced
31:8dbc79294106 | 32:e480579cc460 |
---|---|
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 class IDMButton | 96 class IDMButton |
97 { | 97 { |
98 BufferedImage imgUp, imgPressed; | |
99 | |
98 public IDMButton(float x, float y, String text) | 100 public IDMButton(float x, float y, String text) |
99 { | 101 { |
100 } | 102 } |
101 | 103 |
102 public void paint(Graphics2D g) | 104 public void paint(Graphics2D g) |
165 private boolean isEmpty(int x, int y) | 167 private boolean isEmpty(int x, int y) |
166 { | 168 { |
167 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); | 169 return (x >= 0 && x < boardSize && y >= 0 && y < boardSize && board[x][y] == null); |
168 } | 170 } |
169 | 171 |
170 public void pieceRotate(boolean dir) | 172 public void pieceRotate(Piece.RotateDir dir) |
171 { | 173 { |
172 if (current != null) | 174 if (current != null) |
173 current.rotate(dir); | 175 current.rotate(dir); |
174 } | 176 } |
175 | 177 |
277 BufferedImage lautaBG = null, lautaBGScaled = null; | 279 BufferedImage lautaBG = null, lautaBGScaled = null; |
278 Dimension lautaDim; | 280 Dimension lautaDim; |
279 | 281 |
280 SoundElement[] sounds; | 282 SoundElement[] sounds; |
281 | 283 |
284 Piece testi; int con = 0; | |
285 | |
282 public SoundElement snd(Sound snd) | 286 public SoundElement snd(Sound snd) |
283 { | 287 { |
284 return sounds[snd.ordinal()]; | 288 return sounds[snd.ordinal()]; |
285 } | 289 } |
286 | 290 |
290 System.out.print("Engine() constructor\n"); | 294 System.out.print("Engine() constructor\n"); |
291 | 295 |
292 gameClock = 0; | 296 gameClock = 0; |
293 gameFrames = 0; | 297 gameFrames = 0; |
294 startTime = new Date().getTime(); | 298 startTime = new Date().getTime(); |
299 | |
300 testi = new Piece(PieceType.LOCKED); | |
295 | 301 |
296 | 302 |
297 // Load resources | 303 // Load resources |
298 try | 304 try |
299 { | 305 { |
372 | 378 |
373 // Background, pieces | 379 // Background, pieces |
374 g2.drawImage(lautaBGScaled, 0, 0, null); | 380 g2.drawImage(lautaBGScaled, 0, 0, null); |
375 lauta.paint(g2, 100, 150, 60); | 381 lauta.paint(g2, 100, 150, 60); |
376 | 382 |
383 testi.paint(g2, 50f,50f,100f); | |
384 | |
377 // Scores | 385 // Scores |
378 g2.setFont(font1); | 386 g2.setFont(font1); |
379 g2.setPaint(Color.white); | 387 g2.setPaint(Color.white); |
380 | 388 |
381 | 389 |
382 // Other elements | 390 // Other elements |
383 long currTime = new Date().getTime(); | 391 long currTime = new Date().getTime(); |
384 g2.drawString("fps = "+ ((currTime - startTime) / gameFrames), dim.width - 120, 20); | 392 g2.drawString("fps = "+ ((gameFrames * 1000) / (currTime - startTime)), dim.width - 120, 20); |
393 | |
394 g2.drawString("con = "+ con, 20, 30); | |
385 } | 395 } |
386 | 396 |
387 public void startThreads() | 397 public void startThreads() |
388 { | 398 { |
389 System.out.print("startThreads()\n"); | 399 System.out.print("startThreads()\n"); |
440 // Handle keyboard input | 450 // Handle keyboard input |
441 switch (e.getKeyCode()) | 451 switch (e.getKeyCode()) |
442 { | 452 { |
443 case KeyEvent.VK_LEFT: | 453 case KeyEvent.VK_LEFT: |
444 case KeyEvent.VK_UP: | 454 case KeyEvent.VK_UP: |
445 lauta.pieceRotate(false); | 455 lauta.pieceRotate(Piece.RotateDir.LEFT); |
446 break; | 456 break; |
447 | 457 |
448 case KeyEvent.VK_RIGHT: | 458 case KeyEvent.VK_RIGHT: |
449 case KeyEvent.VK_DOWN: | 459 case KeyEvent.VK_DOWN: |
450 lauta.pieceRotate(true); | 460 lauta.pieceRotate(Piece.RotateDir.RIGHT); |
451 break; | 461 break; |
452 | 462 |
453 case KeyEvent.VK_ENTER: | 463 case KeyEvent.VK_ENTER: |
454 lauta.pieceFinishTurn(); | 464 lauta.pieceFinishTurn(); |
455 snd(Sound.PIECE_PLACED).stop(); | 465 snd(Sound.PIECE_PLACED).stop(); |
472 if (gameClock % 3 == 1) | 482 if (gameClock % 3 == 1) |
473 { | 483 { |
474 repaint(); | 484 repaint(); |
475 gameFrames++; | 485 gameFrames++; |
476 } | 486 } |
487 | |
488 // debugataan | |
489 con = ((int) (gameClock / 100)) & 7; | |
490 testi.clearActiveConnections(); | |
491 testi.setActiveConnection(con); | |
477 | 492 |
478 // Sleep for a moment | 493 // Sleep for a moment |
479 try { | 494 try { |
480 Thread.sleep(10); | 495 Thread.sleep(10); |
481 } | 496 } |