Mercurial > hg > ristipolku
comparison game/Engine.java @ 76:43f68fe605de
More cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 03 Mar 2011 04:14:55 +0200 |
parents | b586ce4f6d97 |
children | d17db72ac770 |
comparison
equal
deleted
inserted
replaced
75:b586ce4f6d97 | 76:43f68fe605de |
---|---|
21 class AboutBox extends IDMWidget | 21 class AboutBox extends IDMWidget |
22 { | 22 { |
23 BufferedImage aboutImg; | 23 BufferedImage aboutImg; |
24 boolean aboutSecret; | 24 boolean aboutSecret; |
25 | 25 |
26 public AboutBox() | |
27 { | |
28 try { | |
29 ResourceLoader res = new ResourceLoader("graphics/girl.jpg"); | |
30 aboutImg = ImageIO.read(res.getStream()); | |
31 } | |
32 catch (IOException e) | |
33 { | |
34 } | |
35 | |
36 aboutSecret = false; | |
37 | |
38 setPos(150f, 150f); | |
39 setSize(600f, 400f); | |
40 } | |
41 | |
42 IDMPoint currPos, currOffs; | 26 IDMPoint currPos, currOffs; |
43 Paint textPaint; | 27 Paint textPaint; |
44 Font textFont; | 28 Font textFont; |
45 FontMetrics textMetrics; | 29 FontMetrics textMetrics; |
46 | 30 |
31 | |
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 | |
47 public void setTextFont(Font font, FontMetrics metrics) | 48 public void setTextFont(Font font, FontMetrics metrics) |
48 { | 49 { |
49 textFont = font; | 50 textFont = font; |
50 textMetrics = metrics; | 51 textMetrics = metrics; |
51 } | 52 } |
68 | 69 |
69 public void drawString(Graphics2D g, String text) | 70 public void drawString(Graphics2D g, String text) |
70 { | 71 { |
71 Paint savePaint = g.getPaint(); | 72 Paint savePaint = g.getPaint(); |
72 g.setPaint(textPaint); | 73 g.setPaint(textPaint); |
74 g.setFont(textFont); | |
73 | 75 |
74 int i = 0; | 76 int i = 0; |
75 while (i < text.length()) | 77 while (i < text.length()) |
76 { | 78 { |
77 int p = text.indexOf("\n", i); | 79 int p = text.indexOf("\n", i); |
93 g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y); | 95 g.drawString(str, currPos.x + currOffs.x, currPos.y + currOffs.y); |
94 | 96 |
95 if (linefeed) | 97 if (linefeed) |
96 { | 98 { |
97 currOffs.x = 0; | 99 currOffs.x = 0; |
98 currOffs.y += textMetrics.getMaxDescent();; | 100 currOffs.y += textMetrics.getHeight(); |
99 } | 101 } |
100 else | 102 else |
101 { | 103 { |
102 currOffs.x += textMetrics.stringWidth(str); | 104 currOffs.x += textMetrics.stringWidth(str); |
103 } | 105 } |
112 w = getScaledWidth(), h = getScaledHeight(); | 114 w = getScaledWidth(), h = getScaledHeight(); |
113 | 115 |
114 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f)); | 116 g.setPaint(new Color(0.0f, 0.0f, 0.0f, 0.6f)); |
115 g.fill(new RoundRectangle2D.Float(x, y, w, h, 10, 10)); | 117 g.fill(new RoundRectangle2D.Float(x, y, w, h, 10, 10)); |
116 | 118 |
119 setTextFont(G.fonts[3], G.metrics[3]); | |
120 setTextPaint(Color.white); | |
121 | |
122 setCurrPos(x + 20, y + 30); | |
123 drawString(g, "RistiPolku (CrossPaths) v0.5\n"); | |
124 | |
117 setTextFont(G.fonts[1], G.metrics[1]); | 125 setTextFont(G.fonts[1], G.metrics[1]); |
118 setTextPaint(Color.white); | |
119 | |
120 setCurrPos(x + 15, y + 15); | |
121 drawString(g, "RistiPolku (CrossPaths) v0.5"); | |
122 | |
123 if (aboutSecret) | 126 if (aboutSecret) |
124 { | 127 { |
125 g.drawImage(aboutImg, x + 15, y + 35, aboutImg.getWidth(), aboutImg.getHeight(), null); | 128 g.drawImage(aboutImg, x + 20, y + 55, aboutImg.getWidth(), aboutImg.getHeight(), null); |
126 | 129 |
127 setCurrPos(x + 225, y + 55); | 130 setCurrPos(x + 225, y + 75); |
128 drawString(g, | 131 drawString(g, |
129 "Dedicated to my\n" + | 132 "Dedicated to my\n" + |
130 "favorite woman" + | 133 "favorite woman\n" + |
131 "in the world."); | 134 "in the world."); |
132 | 135 |
133 setCurrPos(x + 350, y + 155); | 136 setCurrPos(x + 370, y + 175); |
134 drawString(g, "- Matti"); | 137 drawString(g, "- Matti"); |
135 } | 138 } |
136 else | 139 else |
137 { | 140 { |
138 setTextPaint(Color.yellow); | 141 setTextPaint(Color.yellow); |
229 } | 232 } |
230 } | 233 } |
231 | 234 |
232 public boolean contains(float x, float y) | 235 public boolean contains(float x, float y) |
233 { | 236 { |
234 boolean foo = (x >= getScaledX() && | 237 return (x >= getScaledX() && |
235 y >= getScaledY() && | 238 y >= getScaledY() && |
236 x < getScaledX() + boardSize * pscale && | 239 x < getScaledX() + boardSize * pscale && |
237 y < getScaledY() + boardSize * pscale); | 240 y < getScaledY() + boardSize * pscale); |
238 System.out.print("contains "+x+", "+y+" ("+getScaledX()+", "+getScaledY()+", "+(getScaledX() + boardSize * pscale)+"): "+foo+"\n"); | |
239 return foo; | |
240 } | 241 } |
241 | 242 |
242 public void animate(float time) | 243 public void animate(float time) |
243 { | 244 { |
244 for (int y = 0; y < boardSize; y++) | 245 for (int y = 0; y < boardSize; y++) |
388 pieceRotate(Piece.RotateDir.RIGHT); | 389 pieceRotate(Piece.RotateDir.RIGHT); |
389 | 390 |
390 return true; | 391 return true; |
391 } | 392 } |
392 | 393 |
393 /* | |
394 public boolean mouseClicked(MouseEvent e) | |
395 { | |
396 if (flagGameOver) | |
397 return false; | |
398 | |
399 if (contains(e.getPoint())) | |
400 { | |
401 pieceFinishTurn(); | |
402 return true; | |
403 } | |
404 else | |
405 return false; | |
406 } | |
407 */ | |
408 | |
409 public void clicked() | 394 public void clicked() |
410 { | 395 { |
411 pieceFinishTurn(); | 396 pieceFinishTurn(); |
412 } | 397 } |
413 | 398 |
414 public boolean keyPressed(KeyEvent e) | 399 public boolean keyPressed(KeyEvent e) |
415 { | 400 { |
416 if (flagGameOver) | 401 if (flagGameOver) |
472 | 457 |
473 G.fonts = new Font[G.numFonts]; | 458 G.fonts = new Font[G.numFonts]; |
474 G.fonts[0] = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); | 459 G.fonts[0] = Font.createFont(Font.TRUETYPE_FONT, res.getStream()); |
475 G.fonts[1] = G.fonts[0].deriveFont(24f); | 460 G.fonts[1] = G.fonts[0].deriveFont(24f); |
476 G.fonts[2] = G.fonts[0].deriveFont(64f); | 461 G.fonts[2] = G.fonts[0].deriveFont(64f); |
462 G.fonts[3] = G.fonts[0].deriveFont(32f); | |
477 | 463 |
478 } | 464 } |
479 catch (FontFormatException e) | 465 catch (FontFormatException e) |
480 { | 466 { |
481 System.out.print("Could not initialize fonts.\n"); | 467 System.out.print("Could not initialize fonts.\n"); |