package ei.game.gamestate; import java.io.File; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.LinkedList; import java.util.Queue; import ei.engine.effects.BitmapProgressBar; import ei.engine.scene.Sprite; import ei.engine.sound.SoundLoader; import ei.engine.state.GameState; import ei.engine.state.GameStateManager; import ei.engine.texture.TextureLoader; import ei.engine.util.FileFinderHasher; /** * This class handels the loading of the * images and sounds to the memmory. * * @author Ziver */ public class LoadingState extends GameState{ //The extensions of the files private static final String[] TEXTURES = { "jpg","png","bmp" }; private static final String[] SOUNDS = { "wav","ogg" }; // The things to load private Queue loadTextures; private Queue loadSounds; // The name of the next state to activate after loading private String nextState; private BitmapProgressBar progress; /** * Creates a loadingstate * @param name The name of the state */ public LoadingState(String name,String nextState) { super(name); this.nextState = nextState; } @Override public void init() { loadTextures = new LinkedList(); loadSounds = new LinkedList(); progress = new BitmapProgressBar("Loading"); progress.centerToScreen(); progress.setBarTexture(new Sprite("ProgressBar","data/loadbar_front.png")); progress.setProgressTexture(new Sprite("Progress","data/loadbar.png")); progress.setBackgroundTexture(new Sprite("progressBackground","data/loadbar_back.png")); try { File dir = new File(getClass().getClassLoader().getResource("data/").toURI()); ArrayList files = FileFinderHasher.Search(dir); for(int i=0; i= 100){ //deactivate this state and activate the next one GameStateManager.getInstance().removeState(this); GameStateManager.getInstance().setActive(nextState); } } progress.update(); } /** * Render the load bar */ public void render() { progress.render(); } }