package com.gebauz.Bauzoid.app;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.gebauz.Bauzoid.game.Game;
/** Base class for applications using Bauzoid engine.
* Implemented as a Generic, T is reached through to Game<T>
*/
public abstract class BauzoidApp
implements ApplicationListener
{
private String mGameTitle =
"BauzoidGame";
protected Game mGame =
null;
private long mSystemTimeMs =
System.
currentTimeMillis();
private boolean mAdsEnabled =
false;
private Input mAlternateInput =
null;
public BauzoidApp
(String title,
boolean adsEnabled
)
{
this(title, adsEnabled,
null);
}
public BauzoidApp
(String title,
boolean adsEnabled, Input alternateInput
)
{
mGameTitle = title
;
mAdsEnabled = adsEnabled
;
mAlternateInput = alternateInput
;
}
@
Override
public void create
()
{
if (mAlternateInput
!=
null)
{
Gdx.
input = mAlternateInput
;
}
mGame =
new Game
(this, mGameTitle, mAdsEnabled
);
mGame.
init();
initGame
();
mSystemTimeMs =
System.
currentTimeMillis();
}
@
Override
public void dispose
()
{
exitGame
();
mGame.
exit();
mGame =
null;
}
@
Override
public void pause
()
{
mGame.
pause();
}
@
Override
public void resume
()
{
mGame.
resume();
}
@
Override
public void resize
(int w,
int h
)
{
mGame.
resize(w, h
);
}
@
Override
public void render
()
{
long currentTimeMs =
System.
currentTimeMillis();
long deltaTimeMs = currentTimeMs - mSystemTimeMs
;
mSystemTimeMs = currentTimeMs
;
mGame.
update((float)deltaTimeMs / 1000.0f
);
mGame.
render();
}
/** Called after the engine internals have been initialized - this is the point to kick off the initial game state. */
public abstract void initGame
();
/** Called before the engine internals are cleaned up. */
public abstract void exitGame
();
/** Get the instance of the game. */
public Game getGame
()
{
return mGame
;
}
public long getSystemTimeMs
()
{
return mSystemTimeMs
;
}
}