2007-03-07 21:42:12 +00:00
|
|
|
package ei.engine.state;
|
|
|
|
|
|
2007-04-28 22:09:39 +00:00
|
|
|
import ei.engine.LWJGLGameWindow;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.engine.input.InputHandler;
|
2007-04-28 22:09:39 +00:00
|
|
|
import ei.engine.renderer.Camera;
|
2007-04-12 13:07:35 +00:00
|
|
|
import ei.engine.util.MultiPrintStream;
|
2007-03-29 23:21:00 +00:00
|
|
|
|
2007-03-12 19:13:08 +00:00
|
|
|
public abstract class GameState {
|
2007-03-07 21:42:12 +00:00
|
|
|
private String name;
|
2007-03-29 23:21:00 +00:00
|
|
|
private InputHandler input;
|
2007-03-07 21:42:12 +00:00
|
|
|
private boolean enabled = false;
|
2007-04-28 22:09:39 +00:00
|
|
|
private boolean init;
|
|
|
|
|
private Camera cam;
|
2007-03-07 21:42:12 +00:00
|
|
|
|
2007-03-12 19:13:08 +00:00
|
|
|
public GameState(String name){
|
|
|
|
|
this.name = name;
|
2007-03-29 23:21:00 +00:00
|
|
|
input = new InputHandler();
|
2007-04-28 22:09:39 +00:00
|
|
|
init = false;
|
|
|
|
|
cam = new Camera();
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the input handler of this state
|
|
|
|
|
*
|
|
|
|
|
* @return The input handler
|
|
|
|
|
*/
|
|
|
|
|
public InputHandler getInput(){
|
|
|
|
|
return input;
|
2007-03-12 19:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
2007-03-07 21:42:12 +00:00
|
|
|
/**
|
|
|
|
|
* set if this State is enabled
|
|
|
|
|
* @param b
|
|
|
|
|
*/
|
|
|
|
|
public void setEnabled(boolean b){
|
|
|
|
|
enabled = b;
|
2007-04-28 22:09:39 +00:00
|
|
|
if(enabled){
|
|
|
|
|
if(!init){
|
|
|
|
|
init();
|
|
|
|
|
init = true;
|
|
|
|
|
}
|
|
|
|
|
if(LWJGLGameWindow.getCamera() != cam){
|
|
|
|
|
LWJGLGameWindow.setCamera(cam);
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-04-12 13:07:35 +00:00
|
|
|
MultiPrintStream.out.println("Enabling("+b+") State: "+getName());
|
2007-03-07 21:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the status of the GameState
|
|
|
|
|
*/
|
|
|
|
|
public boolean isEnabled(){
|
|
|
|
|
return enabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return the name of the GameState
|
|
|
|
|
*/
|
|
|
|
|
public String getName(){
|
|
|
|
|
return name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-03-29 23:21:00 +00:00
|
|
|
/**
|
|
|
|
|
* Updates the State
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void stateUpdate(){
|
|
|
|
|
input.update();
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renders the state
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public void stateRender(){
|
|
|
|
|
render();
|
|
|
|
|
input.render();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-28 22:09:39 +00:00
|
|
|
public abstract void init();
|
|
|
|
|
|
2007-03-12 19:13:08 +00:00
|
|
|
public abstract void update();
|
2007-03-07 21:42:12 +00:00
|
|
|
|
2007-03-12 19:13:08 +00:00
|
|
|
public abstract void render();
|
2007-03-07 21:42:12 +00:00
|
|
|
}
|