TitleState.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. package model.gameState;
  2. import image.Images;
  3. import image.Images.ImageType;
  4. import java.awt.Color;
  5. import java.awt.Font;
  6. import java.awt.GradientPaint;
  7. import java.awt.Graphics2D;
  8. import java.awt.RenderingHints;
  9. import java.awt.Transparency;
  10. import java.awt.image.BufferedImage;
  11. import java.awt.image.VolatileImage;
  12. import model.SongHandler;
  13. import control.GameStateManager;
  14. import control.GameStateManager.State;
  15. import control.button.ButtonEvent;
  16. import control.joystick.JoystickEvent;
  17. import data.io.SQLConnector;
  18. public class TitleState extends GameState {
  19. BufferedImage pressStart = Images.getImage(ImageType.pressstart);
  20. BufferedImage colorStrike = Images.getImage(ImageType.colorstrike);
  21. BufferedImage kast = Images.getImage(ImageType.kast);
  22. VolatileImage background;
  23. Font textFont = new Font("OCR A Extended", Font.BOLD, 15);
  24. Font textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
  25. GradientPaint gp = new GradientPaint(300, 0, new Color(0, 0, 1, 0.6f), 980, 1024, new Color(0, 0, 1, 0.2f));
  26. int index = 0;
  27. int varx = 0;
  28. int frame = 0;
  29. int image_x = 0;
  30. int indexKast = 0;
  31. int xKast=0;
  32. public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
  33. super(gsm, sh, sql);
  34. if(!sh.isPlaying())
  35. sh.play();
  36. createBackground();
  37. }
  38. @Override
  39. public void init() {
  40. if(!sh.isPlaying())
  41. sh.play();
  42. frame = 0;
  43. image_x = 0;
  44. indexKast = 0;
  45. xKast = 0;
  46. }
  47. @Override
  48. public void update(float factor) {
  49. image_x = ((frame / 6) % 6) * 49;
  50. frame++;
  51. indexKast++;
  52. xKast = indexKast/10;
  53. xKast%=4;
  54. }
  55. @Override
  56. public void draw(Graphics2D g2) {
  57. g2.drawImage(background, 0, 0, 1280, 1024, null);
  58. g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640-122, 512, 245, 130, null);
  59. g2.drawImage(kast.getSubimage(xKast*600,0,600,800), 490,624,300,400,null);
  60. g2.setFont(textFont);
  61. g2.setColor(Color.WHITE);
  62. g2.drawString("©2015 Team Hamtaro", 550, 1012);
  63. }
  64. @Override
  65. public void buttonPressed(ButtonEvent e) {
  66. switch (e.getButton().getButtonID()) {
  67. case 0:
  68. gsm.setState(State.MENU_STATE);
  69. break;
  70. }
  71. }
  72. @Override
  73. public void buttonReleased(ButtonEvent e) {
  74. }
  75. @Override
  76. public void onJoystickMoved(JoystickEvent e) {
  77. }
  78. public void createBackground() {
  79. background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
  80. Graphics2D g2 = background.createGraphics();
  81. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  82. g2.setRenderingHints(rh);
  83. g2.setColor(new Color(1, 1, 1, 0.3f));
  84. g2.fillRect(0, 0, 1280, 1024);
  85. g2.setColor(new Color(0, 1, 0, 0.7f));
  86. g2.fillRect(0, 0, 100, 1024);
  87. g2.fillRect(1180, 0, 100, 1024);
  88. g2.setColor(new Color(1, 1, 0, 0.7f));
  89. g2.fillRect(100, 0, 100, 1024);
  90. g2.fillRect(1080, 0, 100, 1024);
  91. g2.setColor(new Color(1, 0, 0, 0.7f));
  92. g2.fillRect(200, 0, 100, 1024);
  93. g2.fillRect(980, 0, 100, 1024);
  94. g2.setPaint(gp);
  95. g2.fillRect(300, 0, 680, 1024);
  96. g2.setColor(Color.RED);
  97. g2.setFont(textFont2);
  98. g2.drawString("Color", 385, 212);
  99. g2.drawString("Strike", 390, 342);
  100. g2.dispose();
  101. background.createGraphics();
  102. }
  103. }