TitleState.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.image.BufferedImage;
  13. import java.awt.image.VolatileImage;
  14. import model.SongHandler;
  15. import control.GameStateManager;
  16. import control.GameStateManager.State;
  17. import control.button.ButtonEvent;
  18. import control.joystick.JoystickEvent;
  19. import javax.swing.*;
  20. public class TitleState extends GameState implements ActionListener {
  21. BufferedImage pressStart = Images.getImage(ImageType.pressstart);
  22. BufferedImage colorStrike = Images.getImage(ImageType.colorstrike);
  23. BufferedImage kast = Images.getImage(ImageType.kast);
  24. VolatileImage background;
  25. Font textFont = new Font("OCR A Extended", Font.BOLD, 15);
  26. Font textFont2 = new Font("OCR A Extended", Font.BOLD, 130);
  27. GradientPaint gp = new GradientPaint(300, 0, new Color(0, 0, 1, 0.6f), 980, 1024, new Color(0, 0, 1, 0.2f));
  28. int index = 0;
  29. int varx = 0;
  30. int frame;
  31. private Timer timer;
  32. int showInLoops = 1;
  33. int indexKast = 0;
  34. int xKast=0;
  35. public TitleState(GameStateManager gsm, SongHandler sh){
  36. super(gsm, sh);
  37. // Logica zit in ActionListener (dus actionPerformed())
  38. (timer = new Timer(1000/3, this)).start();
  39. }
  40. @Override
  41. public void init() {
  42. sh.play();
  43. }
  44. @Override
  45. public void update(float factor) {
  46. frame++;
  47. indexKast++;
  48. }
  49. @Override
  50. public void draw(Graphics2D g2) {
  51. // Scherm beelt wat kleurrijke rectangles op het scherm.
  52. if (showInLoops > 0) {
  53. g2.drawImage(background, 0, 0, 1280, 1024, null);
  54. createBackground();
  55. }
  56. if (showInLoops > 18) {
  57. // Code die de arcadekast en 'Press Start' toont.
  58. int image_x = ((frame / 6) % 6) * 49;
  59. g2.drawImage(pressStart.getSubimage(image_x, 0, 49, 26), 640 - 122, 512, 245, 130, null);
  60. xKast = indexKast / 10;
  61. xKast %= 4;
  62. g2.drawImage(kast.getSubimage(xKast * 300, 0, 300, 400), 100, 300, 300, 400, null);
  63. }
  64. }
  65. @Override
  66. public void buttonPressed(ButtonEvent e) {
  67. switch (e.getButton().getButtonID()) {
  68. case 0:
  69. gsm.setState(State.MENU_STATE);
  70. break;
  71. }
  72. }
  73. @Override
  74. public void buttonReleased(ButtonEvent e) {
  75. }
  76. @Override
  77. public void onJoystickMoved(JoystickEvent e) {
  78. }
  79. public void createBackground() {
  80. background = Images.initVolatileImage(1280, 1024, Transparency.OPAQUE);
  81. Graphics2D g2 = background.createGraphics();
  82. if (showInLoops > 0) {
  83. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  84. g2.setRenderingHints(rh);
  85. }
  86. if (showInLoops > 2) {
  87. g2.setColor(new Color(1, 1, 1, 0.3f));
  88. g2.fillRect(0, 0, 1280, 1024);
  89. }
  90. if (showInLoops > 4) {
  91. g2.setColor(new Color(0, 1, 0, 0.7f));
  92. g2.fillRect(0, 0, 100, 1024);
  93. g2.fillRect(1180, 0, 100, 1024);
  94. }
  95. if (showInLoops > 6) {
  96. g2.setColor(new Color(1, 1, 0, 0.7f));
  97. g2.fillRect(100, 0, 100, 1024);
  98. g2.fillRect(1080, 0, 100, 1024);
  99. }
  100. if (showInLoops > 8) {
  101. g2.setColor(new Color(1, 0, 0, 0.7f));
  102. g2.fillRect(200, 0, 100, 1024);
  103. g2.fillRect(980, 0, 100, 1024);
  104. }
  105. if (showInLoops > 12) {
  106. g2.setPaint(gp);
  107. g2.fillRect(300, 0, 680, 1024);
  108. }
  109. if (showInLoops > 14) {
  110. g2.setFont(textFont);
  111. g2.setColor(Color.WHITE);
  112. g2.drawString("©2015 Team Hamtaro", 550, 1012);
  113. }
  114. if (showInLoops > 16) {
  115. g2.setColor(Color.RED);
  116. g2.setFont(textFont2);
  117. g2.drawString("Color", 385, 212);
  118. g2.drawString("Strike", 390, 342);
  119. g2.dispose();
  120. }
  121. if (showInLoops > 18) {
  122. timer.stop();
  123. }
  124. background.createGraphics();
  125. }
  126. @Override
  127. public void actionPerformed(ActionEvent e) {
  128. createBackground();
  129. showInLoops++;
  130. }
  131. }