Mercurial > hg > ristipolku
comparison game/Engine.java @ 144:f01cb1ea26a5
Add some decorative animated elements.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 25 Nov 2011 13:48:02 +0200 |
parents | f3703e617342 |
children | 0ec311706d3c |
comparison
equal
deleted
inserted
replaced
143:5eea4719b429 | 144:f01cb1ea26a5 |
---|---|
228 startNewGame(); | 228 startNewGame(); |
229 } | 229 } |
230 | 230 |
231 public void startNewGame() | 231 public void startNewGame() |
232 { | 232 { |
233 | |
234 board = new Piece[boardSize][boardSize]; | 233 board = new Piece[boardSize][boardSize]; |
235 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); | 234 board[boardMiddle][boardMiddle] = new Piece(PieceType.START); |
236 | 235 |
237 currX = boardMiddle; | 236 currX = boardMiddle; |
238 currY = boardMiddle; | 237 currY = boardMiddle; |
367 if (elem.active) | 366 if (elem.active) |
368 tmp.add(elem); | 367 tmp.add(elem); |
369 } | 368 } |
370 | 369 |
371 pointElems = tmp; | 370 pointElems = tmp; |
371 | |
372 if (time % 32 == 1) | |
373 { | |
374 Random rnd = new Random(); | |
375 pointElems.add(new AnimatedPointElement( | |
376 new IDMPoint(10 + rnd.nextInt(400), 10 + rnd.nextInt(100)), ".")); | |
377 } | |
372 } | 378 } |
373 finally | 379 finally |
374 { | 380 { |
375 write.unlock(); | 381 write.unlock(); |
376 } | 382 } |
579 public class Engine extends JPanel | 585 public class Engine extends JPanel |
580 implements Runnable, KeyListener, | 586 implements Runnable, KeyListener, |
581 MouseListener, MouseWheelListener | 587 MouseListener, MouseWheelListener |
582 { | 588 { |
583 long startTime; | 589 long startTime; |
584 float gameClock, gameFrames; | 590 float gameUpdates, gameFrames; |
585 | 591 |
586 Thread animThread; | 592 Thread animThread; |
587 boolean animEnable = false; | 593 boolean animEnable = false; |
588 | 594 |
589 GameBoard lauta = null; | 595 GameBoard lauta = null; |
660 { | 666 { |
661 System.out.print("Engine(): requesting focus\n"); | 667 System.out.print("Engine(): requesting focus\n"); |
662 requestFocus(); | 668 requestFocus(); |
663 } | 669 } |
664 | 670 |
671 gameUpdates = 0; | |
665 } | 672 } |
666 | 673 |
667 public void startNewGame() | 674 public void startNewGame() |
668 { | 675 { |
669 gameClock = 0; | |
670 gameFrames = 0; | 676 gameFrames = 0; |
671 startTime = new Date().getTime(); | 677 startTime = new Date().getTime(); |
672 lauta.startNewGame(); | 678 lauta.startNewGame(); |
673 } | 679 } |
674 | 680 |
829 public void run() | 835 public void run() |
830 { | 836 { |
831 while (animEnable) | 837 while (animEnable) |
832 { | 838 { |
833 // Progress game animation clock | 839 // Progress game animation clock |
834 gameClock++; | 840 gameUpdates++; |
835 | 841 |
836 // Animate components | 842 // Animate components |
837 lauta.animate(gameClock); | 843 lauta.animate(gameUpdates); |
838 if (lauta.nextPiece != null) | 844 if (lauta.nextPiece != null) |
839 lauta.nextPiece.animate(gameClock); | 845 lauta.nextPiece.animate(gameUpdates); |
840 | 846 |
841 // Repaint with a frame limiter | 847 // Repaint with a frame limiter |
842 if (gameClock % 4 == 1) | 848 if (gameUpdates % 4 == 1) |
843 repaint(); | 849 repaint(); |
844 | 850 |
845 // Sleep for a moment | 851 // Sleep for a moment |
846 try { | 852 try { |
847 Thread.sleep(10); | 853 Thread.sleep(10); |