Rev 193 |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
package com.gebauz.Bauzoid.app;
import android.content.Context;
import android.content.res.Resources;
import com.gebauz.Bauzoid.audio.Audio;
import com.gebauz.Bauzoid.gamestates.GameStateManager;
import com.gebauz.Bauzoid.graphics.Graphics;
/** Root object for the game. Manages game-global objects, acts as the root of the game graph, and kicks off update and render calls.
*
* This is the parent class for the following subsystems:
* - GameStateManager: Root object for game states.
* - Graphics: Root object for all graphics objects
* - Audio: Root object for all audio objects
* - ..
*
* It also offers convenient access to the Android application's Context
*/
public class Game
{
//public static Game sInstance = null;
private Context mContext =
null;
private GameStateManager mGameStateManager =
null;
private Graphics mGraphics =
null;
private Audio mAudio =
null;
// TODO: font
/** Constructor. */
public Game
(Context context
)
{
mContext = context
;
// Set the context to use for engine exceptions
BauzoidException.
setContext(context
);
mGameStateManager =
new GameStateManager
(this);
mGraphics =
new Graphics(this);
mAudio =
new Audio
(this);
//sInstance = this;
}
/** Called for game-global initialization. */
public void init
()
{
mGameStateManager.
init();
}
/** Called for game-global destruction. */
public void exit
()
{
mGameStateManager.
exit();
}
/** Update game logic state. */
public void update
(float deltaTime
)
{
mGameStateManager.
update(deltaTime
);
mAudio.
update(deltaTime
);
}
/** Render game. */
public void render
()
{
mGameStateManager.
render();
mAudio.
render();
}
/** Called when the surface dimensions have changed. */
public void onSurfaceChanged
(int w,
int h
)
{
mGraphics.
updateSurfaceDimensions(w, h
);
mGameStateManager.
onSurfaceChanged(w, h
);
}
/** Called when the OpenGL Context is about to be destroyed. */
public void onSurfaceLost
()
{
mGraphics.
onSurfaceLost();
}
/** Called when the OpenGL Context has been recreated after onSurfaceLost(). */
public void onSurfaceRecreated
()
{
mGraphics.
onSurfaceRecreated();
}
/** Retrieve Context. */
public final Context getContext
()
{
return mContext
;
}
/** Retrieve the Android app resources. */
public final Resources getResources
()
{
return mContext.
getResources();
}
/** Get the main graphics object. */
public final Graphics getGraphics
()
{
return mGraphics
;
}
/** Get the main audio object. */
public final Audio getAudio
()
{
return mAudio
;
}
/** Get the GameStateManager. */
public final GameStateManager getGameStateManager
()
{
return mGameStateManager
;
}
}