Subversion Repositories AndroidProjects

Rev

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

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