Subversion Repositories AndroidProjects

Rev

Rev 193 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
155 chris 1
package com.gebauz.Bauzoid.app;
2
 
157 chris 3
import android.content.Context;
4
import android.content.res.Resources;
5
 
155 chris 6
import com.gebauz.Bauzoid.audio.Audio;
7
import com.gebauz.Bauzoid.gamestates.GameStateManager;
160 chris 8
import com.gebauz.Bauzoid.graphics.Graphics;
155 chris 9
 
192 chris 10
/** Root object for the game. Manages game-global objects, acts as the root of the game graph, and kicks off update and render calls.
11
 *
12
 * This is the parent class for the following subsystems:
13
 * - GameStateManager: Root object for game states.
14
 * - Graphics: Root object for all graphics objects
15
 * - Audio: Root object for all audio objects
16
 * - ..
17
 *
18
 * It also offers convenient access to the Android application's Context
19
 */
155 chris 20
public class Game
21
{
184 chris 22
        //public static Game sInstance = null;
157 chris 23
 
24
        private Context mContext = null;
155 chris 25
        private GameStateManager mGameStateManager = null;
160 chris 26
 
27
        private Graphics mGraphics = null;
155 chris 28
        private Audio mAudio = null;
192 chris 29
        // TODO: font
155 chris 30
 
192 chris 31
        /** Constructor. */
157 chris 32
        public Game(Context context)
155 chris 33
        {
157 chris 34
                mContext = context;
35
 
186 chris 36
                // Set the context to use for engine exceptions
37
                BauzoidException.setContext(context);
38
 
155 chris 39
                mGameStateManager = new GameStateManager(this);
40
 
160 chris 41
                mGraphics = new Graphics(this);
155 chris 42
                mAudio = new Audio(this);
156 chris 43
 
184 chris 44
                //sInstance = this;
155 chris 45
        }
46
 
156 chris 47
        /** Called for game-global initialization. */
48
        public void init()
49
        {
192 chris 50
                mGameStateManager.init();
156 chris 51
        }
52
 
53
        /** Called for game-global destruction. */
54
        public void exit()
55
        {
192 chris 56
                mGameStateManager.exit();
156 chris 57
        }
58
 
192 chris 59
        /** Update game logic state. */
155 chris 60
        public void update(float deltaTime)
61
        {
157 chris 62
                mGameStateManager.update(deltaTime);
63
                mAudio.update(deltaTime);
155 chris 64
        }
65
 
192 chris 66
        /** Render game. */
155 chris 67
        public void render()
68
        {
157 chris 69
                mGameStateManager.render();
70
                mAudio.render();
155 chris 71
        }
157 chris 72
 
193 chris 73
        /** Called when the surface dimensions have changed. */
192 chris 74
        public void onSurfaceChanged(int w, int h)
75
        {
76
                mGraphics.updateSurfaceDimensions(w, h);
77
                mGameStateManager.onSurfaceChanged(w, h);
78
        }
79
 
193 chris 80
        /** Called when the OpenGL Context is about to be destroyed. */
81
        public void onSurfaceLost()
82
        {
83
                mGraphics.onSurfaceLost();
84
        }
85
 
86
        /** Called when the OpenGL Context has been recreated after onSurfaceLost(). */
87
        public void onSurfaceRecreated()
88
        {
89
                mGraphics.onSurfaceRecreated();
90
        }
91
 
192 chris 92
        /** Retrieve Context. */
184 chris 93
        public final Context getContext()
157 chris 94
        {
184 chris 95
                return mContext;
157 chris 96
        }
97
 
192 chris 98
        /** Retrieve the Android app resources. */
184 chris 99
        public final Resources getResources()
157 chris 100
        {
184 chris 101
                return mContext.getResources();
157 chris 102
        }
160 chris 103
 
192 chris 104
        /** Get the main graphics object. */
184 chris 105
        public final Graphics getGraphics()
160 chris 106
        {
184 chris 107
                return mGraphics;
160 chris 108
        }
109
 
192 chris 110
        /** Get the main audio object. */
184 chris 111
        public final Audio getAudio()
160 chris 112
        {
184 chris 113
                return mAudio;
160 chris 114
        }
115
 
192 chris 116
        /** Get the GameStateManager. */
184 chris 117
        public final GameStateManager getGameStateManager()
160 chris 118
        {
184 chris 119
                return mGameStateManager;
160 chris 120
        }
155 chris 121
 
122
}