Blame |
Last modification |
View Log
| RSS feed
package com.gebauz.bauzoid.gamestates;
import com.badlogic.gdx.Gdx;
import com.gebauz.bauzoid.game.Game;
import com.gebauz.bauzoid.game.GameObject;
import com.gebauz.bauzoid.math.Vector4;
/** Game state base class. */
public abstract class BaseGameState
extends GameObject
{
// Fields===========================================================================================
private Vector4 mFadeInColor =
new Vector4
(0,
0,
0,
0);
private Vector4 mFadeOutColor =
new Vector4
(0,
0,
0,
0);
private boolean mDoFadeIn =
false;
private boolean mDoFadeOut =
false;
private boolean mHaveLoadingScreen =
false;
// Methods==========================================================================================
/** Constructor. */
public BaseGameState
(Game game
)
{
super(game
);
}
/** Called for any asynchronous loading. Called before init().
* @param param Parameter specified for state switching. Same as in init().
*/
public void initAsync
(String param
) {}
/** Called when game state is initialized.
* @param param Parameter specified for state switching. Same as in initAsync().
*/
public abstract void init
(String param
);
/** Called when game state is exited and destroyed. */
public abstract void exit
();
/** Update game logic. */
public abstract void update
(float deltaTime
);
/** Update game logic during fading for animations that may continue even during fading. */
public void updateFading
(float deltaTime
) {}
/** Render the game. */
public abstract void render
();
/** Called when the app is paused. */
public void onPause
() {}
/** Called when the app is resumed. */
public void onResume
() {}
/** Called when the surface has been destroyed and recreated. */
public void onSurfaceChanged
(int w,
int h
)
{
// Standard implementation sets the viewport
Gdx.
gl.
glViewport(0,
0, w, h
);
}
public final void switchTo
(String nextState,
String param
)
{
getGameStateManager
().
switchTo(nextState, param
);
}
public final void switchTo
(Class<? extends BaseGameState
> nextState,
String param
)
{
getGameStateManager
().
switchTo(nextState, param
);
}
// Getters/Setters==================================================================================
/** Check if the specific game state requires fading in. */
public final boolean doFadeIn
()
{
return mDoFadeIn
;
}
/** Check if the specific game state requires fading out. */
public final boolean doFadeOut
()
{
return mDoFadeOut
;
}
/** Set fading modes. */
public final void setFading
(boolean fadeIn,
boolean fadeOut
)
{
mDoFadeIn = fadeIn
;
mDoFadeOut = fadeOut
;
}
/** Set fade in color. */
public final void setFadeInColor
(Vector4 fadeInColor
)
{
mFadeInColor = fadeInColor
;
}
/** Get fade in color. */
public final Vector4 getFadeInColor
()
{
return mFadeInColor
;
}
/** Set fade out color. */
public final void setFadeOutColor
(Vector4 fadeOutColor
)
{
mFadeOutColor = fadeOutColor
;
}
/** Get fade out color. */
public final Vector4 getFadeOutColor
()
{
return mFadeOutColor
;
}
/** Check if the GameState requires a loading screen. */
public final boolean haveLoadingScreen
()
{
return mHaveLoadingScreen
;
}
public void enableLoadingScreen
(boolean haveLoadingScreen
)
{
mHaveLoadingScreen = haveLoadingScreen
;
}
}