InfoPanel.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package model.objects;
  2. import image.Images;
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics2D;
  6. import java.awt.RenderingHints;
  7. import java.awt.Transparency;
  8. import java.awt.image.VolatileImage;
  9. import model.SongHandler;
  10. import model.drawObjects.CoinAnimation;
  11. import model.gameState.PlayState;
  12. public class InfoPanel {
  13. private static String totalHighscore = "000000";
  14. private int x, y;
  15. private VolatileImage infoPanel;
  16. private SongHandler sh;
  17. private String time;
  18. private CoinAnimation coinAnimation = new CoinAnimation(150, 200);
  19. public InfoPanel(int x, int y, SongHandler sh){
  20. this.x = x;
  21. this.y = y;
  22. this.sh = sh;
  23. updateIPanel();
  24. generateInfoPanel();
  25. }
  26. public void updateIPanel() {
  27. totalHighscore = "" + PlayState.currentScore;
  28. // time = "";
  29. // long progress = (sh.getProgress() / 1000);
  30. // time = progress%1000 + time;
  31. // progress /= 1000;
  32. // time = progress%1000 + ":" + time;
  33. // progress /= 1000;
  34. // time = progress + ":" + time;
  35. long progress = (sh.getProgress() / 1000);
  36. String millis = ((progress) % 1000) + "".length() >= 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
  37. String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
  38. String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
  39. time = minute + ":" + second + ":" + millis;
  40. generateInfoPanel();
  41. }
  42. private void generateInfoPanel(){
  43. infoPanel = Images.initVolatileImage(256, 1024, Transparency.OPAQUE);
  44. Graphics2D g2 = infoPanel.createGraphics();
  45. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  46. g2.setRenderingHints(rh);
  47. g2.setColor(Color.BLACK);
  48. g2.fillRect(x, y, 256, 1024);
  49. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
  50. g2.setFont(scoreFont);
  51. g2.setColor(Color.GREEN);
  52. g2.fillRect(25, 100, (int)(2 * PlayState.lifePoints), 30);
  53. g2.setColor(Color.ORANGE);
  54. g2.drawString("Score: " + totalHighscore, 25, 75);
  55. g2.drawRect(25, 100, 200, 30);
  56. g2.drawRect(25, 300, 200, 700);
  57. g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
  58. if(sh.getCurrentSong().getSubtitle() != "")
  59. {
  60. g2.drawString(sh.getCurrentSong().getSubtitle(), 25, 230);
  61. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 260);
  62. g2.drawString(time, 25, 290);
  63. }
  64. else
  65. {
  66. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230);
  67. g2.drawString(time, 25, 260);
  68. }
  69. if (!coinAnimation.areWeDoneYet())
  70. coinAnimation.draw(g2);
  71. g2.setColor(Color.YELLOW);
  72. g2.fillRect(25, 1000 - 7 * PlayState.comboScore, 200, 0 + 7 * PlayState.comboScore);
  73. g2.dispose();
  74. infoPanel.createGraphics();
  75. }
  76. public void throwACoin() {
  77. coinAnimation.start();
  78. }
  79. public void draw(Graphics2D g2){
  80. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  81. }
  82. public static String getTotalHighscore()
  83. {
  84. return totalHighscore;
  85. }
  86. }