Mercurial > hg > ristipolku
comparison game/Engine.java @ 51:f81f76458b92
Work on widgets.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 23 Feb 2011 02:49:07 +0200 |
parents | 496e616ff09d |
children | 01851bae3da3 |
comparison
equal
deleted
inserted
replaced
50:496e616ff09d | 51:f81f76458b92 |
---|---|
89 | 89 |
90 soundManager = smgr; | 90 soundManager = smgr; |
91 // sndPlaced = soundManager.getSound("sounds/placed.wav"); | 91 // sndPlaced = soundManager.getSound("sounds/placed.wav"); |
92 } | 92 } |
93 | 93 |
94 public void paint(Graphics2D g, int sx, int sy, float scale) | 94 public void paint(Graphics2D g, float sx, float sy, float scale) |
95 { | 95 { |
96 for (int y = 0; y < boardSize; y++) | 96 for (int y = 0; y < boardSize; y++) |
97 for (int x = 0; x < boardSize; x++) | 97 for (int x = 0; x < boardSize; x++) |
98 if (board[x][y] != null) | 98 if (board[x][y] != null) |
99 { | 99 { |
114 for (int x = 0; x < boardSize; x++) | 114 for (int x = 0; x < boardSize; x++) |
115 if (board[x][y] != null) | 115 if (board[x][y] != null) |
116 { | 116 { |
117 board[x][y].animate(time); | 117 board[x][y].animate(time); |
118 } | 118 } |
119 | |
120 } | 119 } |
121 | 120 |
122 public void pieceRotate(Piece.RotateDir dir) | 121 public void pieceRotate(Piece.RotateDir dir) |
123 { | 122 { |
124 if (currPiece != null) | 123 if (currPiece != null) |
250 static final AudioFormat sfmt = new AudioFormat(22050, 16, 1, true, false); | 249 static final AudioFormat sfmt = new AudioFormat(22050, 16, 1, true, false); |
251 SoundManager soundManager; | 250 SoundManager soundManager; |
252 Sound musa; | 251 Sound musa; |
253 | 252 |
254 IDMContainer widgets; | 253 IDMContainer widgets; |
255 BtnNewGame btnNewGame; | |
256 BtnSwapPiece btnSwapPiece; | |
257 | 254 |
258 public Engine() | 255 public Engine() |
259 { | 256 { |
260 // Initialize globals | 257 // Initialize globals |
261 System.out.print("Engine() constructor\n"); | 258 System.out.print("Engine() constructor\n"); |
292 System.out.print(e.getMessage()); | 289 System.out.print(e.getMessage()); |
293 } | 290 } |
294 | 291 |
295 // UI IDM widgets | 292 // UI IDM widgets |
296 widgets = new IDMContainer(); | 293 widgets = new IDMContainer(); |
297 btnNewGame = new BtnNewGame(); | 294 |
298 widgets.add(btnNewGame); | 295 widgets.add(new BtnNewGame(0.75f, 0.75f)); |
299 | 296 widgets.add(new BtnSwapPiece(0.75f, 0.85f)); |
300 btnSwapPiece = new BtnSwapPiece(); | |
301 widgets.add(btnSwapPiece); | |
302 | 297 |
303 // Game | 298 // Game |
304 startNewGame(); | 299 startNewGame(); |
305 | 300 |
306 // Initialize event listeners | 301 // Initialize event listeners |
347 RenderingHints.VALUE_INTERPOLATION_BICUBIC); | 342 RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
348 | 343 |
349 gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); | 344 gimg.drawImage(lautaBG, 0, 0, dim.width, dim.height, null); |
350 lautaDim = dim; | 345 lautaDim = dim; |
351 | 346 |
347 widgets.setScale(dim.width, dim.height); | |
352 System.out.print("scale changed\n"); | 348 System.out.print("scale changed\n"); |
353 | |
354 btnNewGame.move(dim.width - 200, dim.height - 150); | |
355 btnSwapPiece.move(dim.width - 200, dim.height - 400); | |
356 } | 349 } |
357 | 350 |
358 // Background, pieces | 351 // Background, pieces |
359 g2.drawImage(lautaBGScaled, 0, 0, null); | 352 g2.drawImage(lautaBGScaled, 0, 0, null); |
360 lauta.paint(g2, 100, 150, 60); | 353 lauta.paint(g2, 100, 150, 60); |
461 } | 454 } |
462 } | 455 } |
463 | 456 |
464 class BtnNewGame extends IDMButton | 457 class BtnNewGame extends IDMButton |
465 { | 458 { |
466 public BtnNewGame() | 459 public BtnNewGame(float x, float y) |
467 { | 460 { |
468 super(0, 0, KeyEvent.VK_ESCAPE, font1, "New Game"); | 461 super(x, y, KeyEvent.VK_ESCAPE, font1, "Uusi peli"); |
469 } | 462 } |
470 | 463 |
471 public void clicked() | 464 public void clicked() |
472 { | 465 { |
473 startNewGame(); | 466 startNewGame(); |
474 } | 467 } |
475 } | 468 } |
476 | 469 |
477 class BtnSwapPiece extends IDMButton | 470 class BtnSwapPiece extends IDMButton |
478 { | 471 { |
479 public BtnSwapPiece() | 472 public BtnSwapPiece(float x, float y) |
480 { | 473 { |
481 super(0, 0, KeyEvent.VK_SPACE, font1, "Swap Piece"); | 474 super(x, y, KeyEvent.VK_SPACE, font1, "Vaihda"); |
482 } | 475 } |
483 | 476 |
484 public void clicked() | 477 public void clicked() |
485 { | 478 { |
486 } | 479 } |