Subversion Repositories AndroidProjects

Rev

Rev 226 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.gebauz.Bauzoid.app;

import com.gebauz.Bauzoid.audio.Audio;
import com.gebauz.Bauzoid.gamestates.GameStateManager;
import com.gebauz.Bauzoid.graphics.Graphics;
import com.gebauz.Bauzoid.input.Input;

/** 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
{
        private GameStateManager mGameStateManager = null;
       
        private Graphics mGraphics = null;
        private Audio mAudio = null;
        private Input mInput = null;
       
        /** Constructor. */
        public Game()
        {
                // Set the context to use for engine exceptions

                mGameStateManager = new GameStateManager(this);
               
                mGraphics = new Graphics(this);
                mAudio = new Audio(this);
                mInput = new Input(this);
        }
       
        /** Called for game-global initialization. */
        public void init()
        {
                mGraphics.init();
                mAudio.init();
                mInput.init();
                mGameStateManager.init();
        }
       
        /** Called for game-global destruction. */
        public void exit()
        {              
                mGameStateManager.exit();
                mInput.exit();
                mAudio.exit();
                mGraphics.exit();
        }
       
        /** Update game logic state. */
        public void update(float deltaTime)
        {
                mGameStateManager.update(deltaTime);
                mAudio.update(deltaTime);
                mInput.update(deltaTime);
        }
       
        /** Render game. */
        public void render()
        {
                mGameStateManager.render();
                mAudio.render();
                mInput.render();
        }
       
        /** Called when the surface dimensions have changed. */
        public void resize(int w, int h)
        {
                mGraphics.updateSurfaceDimensions(w, h);
                mGameStateManager.onSurfaceChanged(w, h);
        }
       
        /** Called when the OpenGL Context is about to be destroyed. */
        public void pause()
        {
                mGraphics.onSurfaceLost();
                mAudio.onPause();
                mInput.onPause();
        }
       
        /** Called when the OpenGL Context has been recreated after onSurfaceLost(). */
        public void resume()
        {
                mGraphics.onSurfaceRecreated();
                mAudio.onResume();
                mAudio.onResume();
        }
       
        /** Get the main graphics object. */
        public final Graphics getGraphics()
        {
                return mGraphics;
        }
       
        /** Get the main audio object. */
        public final Audio getAudio()
        {
                return mAudio;
        }

        /** Get the main input object. */
        public final Input getInput()
        {
                return mInput;
        }
       
        /** Get the GameStateManager. */
        public final GameStateManager getGameStateManager()
        {
                return mGameStateManager;
        }

}