Advertisement
Guest User

Untitled

a guest
Jan 30th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. package rpc;
  2.  
  3. import java.util.HashMap;
  4. import java.util.WeakHashMap;
  5.  
  6. import org.newdawn.slick.Color;
  7. import org.newdawn.slick.GameContainer;
  8. import org.newdawn.slick.Graphics;
  9. import org.newdawn.slick.SlickException;
  10. import org.newdawn.slick.state.StateBasedGame;
  11.  
  12. import rpc.launcher.Game;
  13.  
  14. public class TransitionModule {
  15. private static WeakHashMap<Integer, TransitionModule> stateInstance = new WeakHashMap<Integer, TransitionModule>();
  16.  
  17. private SoundModule sound;
  18.  
  19. private GameContainer gc;
  20. private StateBasedGame sbg;
  21. private Color fade = new Color(0,0,0,255);
  22. private boolean fadeIn = false;
  23. private boolean fadeOut = false;
  24. private boolean fadeOutComplete = false;
  25. private int fadeAmount = 0;
  26. private boolean controlLockout = false;
  27. private int stateID = 0;
  28. private int fadeOutSpeed, fadeInSpeed = 25;
  29.  
  30. public TransitionModule(int state){
  31. stateInstance.put(state, this);
  32. }
  33.  
  34. //Initialize universally loaded resources then run initLoad() if exists.
  35. public void initController(GameContainer gc, StateBasedGame sbg) throws SlickException{
  36. this.gc = gc;
  37. this.sbg = sbg;
  38.  
  39. sound = SoundModule.getCurrentState();
  40. }
  41.  
  42. //Fetch this Module
  43. public static TransitionModule getState(int state){return stateInstance.get(state);}
  44. public static TransitionModule getCurrentState(){return stateInstance.get(Game.getCS());}
  45. public static void removeState(){stateInstance.remove(Game.getCS());}
  46.  
  47. //BEGIN MODULE SPECIFIC CODE
  48. public void enter(int i){
  49. fadeInSpeed = i;
  50. fadeAmount = 300;
  51. fadeIn = true;
  52. }
  53.  
  54. public void startTransition(String state, int o){
  55. fadeOutSpeed = o;
  56. fadeOut = true;
  57. sound.fade();
  58.  
  59. if (state.equals("splashState"))
  60. stateID = 0;
  61. if (state.equals("mainMenuState"))
  62. stateID = 1;
  63. if (state.equals("mapEditorState"))
  64. stateID = 2;
  65. if (state.equals("playState"))
  66. stateID = 3;
  67. if (state.equals("exit"))
  68. stateID = 10;
  69. }
  70.  
  71. public void render(Graphics g){
  72. int displayWidth = Game.getInterfaceWidth();
  73. int displayHeight = Game.getInterfaceHeight();
  74. g.setColor(fade);
  75. g.fillRect(-16,-16,displayWidth+32,displayHeight+32);
  76.  
  77. // Start fade
  78. if (fadeOut){
  79. controlLockout = true;
  80. fadeAmount += fadeOutSpeed;
  81. fade = new Color(0,0,0,fadeAmount);
  82. }
  83.  
  84. // Detect fade is completed.
  85. if ((fadeOut) && (fadeAmount >= 300)){
  86. fadeOut = false;
  87. fadeOutComplete = true;
  88. }
  89.  
  90. // Fade in slowly
  91. if (fadeIn){
  92. controlLockout = true;
  93. fadeAmount -= fadeInSpeed;
  94. fade = new Color(0,0,0,fadeAmount);
  95. }
  96. if ((fadeIn) && (fadeAmount <= 0)){
  97. controlLockout = false;
  98. fadeIn = false;
  99. fadeAmount = 0;
  100. }
  101.  
  102. // Exit state, reset FadeOutComplete flag.
  103. if (fadeOutComplete){
  104. fadeOutComplete = false;
  105. fadeAmount = 0;
  106. controlLockout = false;
  107. if (stateID == 10){
  108. gc.exit();
  109. }else{
  110. Game.setCS(stateID);
  111. sbg.enterState(stateID);
  112. }
  113. }
  114. }
  115.  
  116. public boolean getControlLockout(){return controlLockout;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement