Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rpc;
- import java.util.HashMap;
- import java.util.WeakHashMap;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.GameContainer;
- import org.newdawn.slick.Graphics;
- import org.newdawn.slick.SlickException;
- import org.newdawn.slick.state.StateBasedGame;
- import rpc.launcher.Game;
- public class TransitionModule {
- private static WeakHashMap<Integer, TransitionModule> stateInstance = new WeakHashMap<Integer, TransitionModule>();
- private SoundModule sound;
- private GameContainer gc;
- private StateBasedGame sbg;
- private Color fade = new Color(0,0,0,255);
- private boolean fadeIn = false;
- private boolean fadeOut = false;
- private boolean fadeOutComplete = false;
- private int fadeAmount = 0;
- private boolean controlLockout = false;
- private int stateID = 0;
- private int fadeOutSpeed, fadeInSpeed = 25;
- public TransitionModule(int state){
- stateInstance.put(state, this);
- }
- //Initialize universally loaded resources then run initLoad() if exists.
- public void initController(GameContainer gc, StateBasedGame sbg) throws SlickException{
- this.gc = gc;
- this.sbg = sbg;
- sound = SoundModule.getCurrentState();
- }
- //Fetch this Module
- public static TransitionModule getState(int state){return stateInstance.get(state);}
- public static TransitionModule getCurrentState(){return stateInstance.get(Game.getCS());}
- public static void removeState(){stateInstance.remove(Game.getCS());}
- //BEGIN MODULE SPECIFIC CODE
- public void enter(int i){
- fadeInSpeed = i;
- fadeAmount = 300;
- fadeIn = true;
- }
- public void startTransition(String state, int o){
- fadeOutSpeed = o;
- fadeOut = true;
- sound.fade();
- if (state.equals("splashState"))
- stateID = 0;
- if (state.equals("mainMenuState"))
- stateID = 1;
- if (state.equals("mapEditorState"))
- stateID = 2;
- if (state.equals("playState"))
- stateID = 3;
- if (state.equals("exit"))
- stateID = 10;
- }
- public void render(Graphics g){
- int displayWidth = Game.getInterfaceWidth();
- int displayHeight = Game.getInterfaceHeight();
- g.setColor(fade);
- g.fillRect(-16,-16,displayWidth+32,displayHeight+32);
- // Start fade
- if (fadeOut){
- controlLockout = true;
- fadeAmount += fadeOutSpeed;
- fade = new Color(0,0,0,fadeAmount);
- }
- // Detect fade is completed.
- if ((fadeOut) && (fadeAmount >= 300)){
- fadeOut = false;
- fadeOutComplete = true;
- }
- // Fade in slowly
- if (fadeIn){
- controlLockout = true;
- fadeAmount -= fadeInSpeed;
- fade = new Color(0,0,0,fadeAmount);
- }
- if ((fadeIn) && (fadeAmount <= 0)){
- controlLockout = false;
- fadeIn = false;
- fadeAmount = 0;
- }
- // Exit state, reset FadeOutComplete flag.
- if (fadeOutComplete){
- fadeOutComplete = false;
- fadeAmount = 0;
- controlLockout = false;
- if (stateID == 10){
- gc.exit();
- }else{
- Game.setCS(stateID);
- sbg.enterState(stateID);
- }
- }
- }
- public boolean getControlLockout(){return controlLockout;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement