TitleState.java 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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;
  29. int indexKast = 0;
  30. int xKast=0;
  31. public TitleState(GameStateManager gsm, SongHandler sh, SQLConnector sql){
  32. super(gsm, sh, sql);
  33. createBackground();
  34. }
  35. @Override
  36. public void init() {
  37. sh.play();
  38. }
  39. @Override
  40. public void update(float factor) {
  41. frame++;
  42. indexKast++;
  43. }
  44. @Override
  45. public void draw(Graphics2D g2) {
  46. g2.drawImage(background, 0, 0, 1280, 1024, null);
  47. int image_x = ((frame / 6) % 6) * 49;
  48. g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640-122, 512, 245, 130, null);
  49. xKast = indexKast/10;
  50. xKast%=4;
  51. //g2.drawImage(kast.getSubimage(xKast*300,0,300,400), 640-122,650,300,400,null);
  52. g2.drawImage(kast.getSubimage(xKast*300,0,300,400), 100,300,300,400,null);
  53. }
  54. @Override
  55. public void buttonPressed(ButtonEvent e) {
  56. switch (e.getButton().getButtonID()) {
  57. case 0:
  58. gsm.setState(State.MENU_STATE);
  59. break;
  60. }
  61. }
  62. @Override
  63. public void buttonReleased(ButtonEvent e) {
  64. }
  65. @Override
  66. public void onJoystickMoved(JoystickEvent e) {
  67. }
  68. public void createBackground() {
  69. background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
  70. Graphics2D g2 = background.createGraphics();
  71. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  72. g2.setRenderingHints(rh);
  73. g2.setColor(new Color(1, 1, 1, 0.3f));
  74. g2.fillRect(0, 0, 1280, 1024);
  75. g2.setColor(new Color(0, 1, 0, 0.7f));
  76. g2.fillRect(0, 0, 100, 1024);
  77. g2.fillRect(1180, 0, 100, 1024);
  78. g2.setColor(new Color(1, 1, 0, 0.7f));
  79. g2.fillRect(100, 0, 100, 1024);
  80. g2.fillRect(1080, 0, 100, 1024);
  81. g2.setColor(new Color(1, 0, 0, 0.7f));
  82. g2.fillRect(200, 0, 100, 1024);
  83. g2.fillRect(980, 0, 100, 1024);
  84. g2.setPaint(gp);
  85. g2.fillRect(300, 0, 680, 1024);
  86. g2.setFont(textFont);
  87. g2.setColor(Color.WHITE);
  88. g2.drawString("©2015 Team Hamtaro", 550, 1012);
  89. g2.setColor(Color.RED);
  90. g2.setFont(textFont2);
  91. g2.drawString("Color", 385, 212);
  92. g2.drawString("Strike", 390, 342);
  93. g2.dispose();
  94. background.createGraphics();
  95. }
  96. }