TitleState.java 2.7 KB

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