InfoPanel.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 int tempComboScore;
  19. private CoinAnimation coinAnimation = new CoinAnimation(125, 250);
  20. public InfoPanel(int x, int y, SongHandler sh){
  21. this.x = x;
  22. this.y = y;
  23. this.sh = sh;
  24. updateIPanel();
  25. generateInfoPanel();
  26. }
  27. public void updateIPanel() {
  28. totalHighscore = "" + PlayState.currentScore;
  29. // time = "";
  30. // long progress = (sh.getProgress() / 1000);
  31. // time = progress%1000 + time;
  32. // progress /= 1000;
  33. // time = progress%1000 + ":" + time;
  34. // progress /= 1000;
  35. // time = progress + ":" + time;
  36. long progress = (sh.getProgress() / 1000);
  37. String millis = ((progress) % 1000) + "".length() > 3 ? ("" +((progress) % 1000)).substring(0, 2) : "" + ((progress) % 1000);
  38. String second = ((progress / 1000) % 60 + "").length() <= 1 ? "0" +((progress / 1000) % 60) : "" + ((progress / 1000) % 60);
  39. String minute = ((progress / (1000 * 60)) % 60 + "").length() <= 1 ? "0" +((progress / (1000 * 60)) % 60) : "" + ((progress / (1000 * 60)) % 60);
  40. time = minute + ":" + second + ":" + millis;
  41. generateInfoPanel();
  42. }
  43. private void generateInfoPanel(){
  44. infoPanel = Images.initVolatileImage(256, 1024, Transparency.OPAQUE);
  45. Graphics2D g2 = infoPanel.createGraphics();
  46. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  47. g2.setRenderingHints(rh);
  48. g2.setColor(Color.BLACK);
  49. g2.fillRect(x, y, 256, 1024);
  50. Font scoreFont = new Font("OCR A Extended", Font.BOLD, 30);
  51. g2.setFont(scoreFont);
  52. g2.setColor(Color.GREEN);
  53. g2.fillRect(25, 100, (int)(2 * PlayState.lifePoints), 30);
  54. g2.setColor(Color.ORANGE);
  55. g2.drawString("Score: " + totalHighscore, 25, 75);
  56. g2.drawRect(25, 100, 200, 30);
  57. g2.drawRect(25, 300, 200, 700);
  58. g2.drawString(sh.getCurrentSong().getTitle(), 25, 200);
  59. if(sh.getCurrentSong().getSubtitle() != "") {
  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. g2.drawString(sh.getCurrentSong().getAuthor(), 25, 230);
  66. g2.drawString(time, 25, 260);
  67. }
  68. if (!coinAnimation.areWeDoneYet()) {
  69. coinAnimation.draw(g2);
  70. if (coinAnimation.isLastLoop())
  71. tempComboScore = PlayState.comboScore;
  72. }
  73. g2.fillRect(25, 1000 - 7 * tempComboScore, 200, 7 * tempComboScore);
  74. g2.setColor(Color.YELLOW);
  75. g2.dispose();
  76. infoPanel.createGraphics();
  77. }
  78. public void throwACoin() {
  79. coinAnimation.start();
  80. }
  81. public void draw(Graphics2D g2){
  82. g2.drawImage(infoPanel, 0, 0, 256,1024,null);
  83. }
  84. public static String getTotalHighscore()
  85. {
  86. return totalHighscore;
  87. }
  88. }