TitleState.java 3.0 KB

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