00001
00027 #ifndef _CGAMESTATE_H_
00028 #define _CGAMESTATE_H_
00029
00030 #include "TextureManager.h"
00031 #include "Renderer.h"
00032 #include "GameObject3DManager.h"
00033 #include "GameObject2DManager.h"
00034 #include "Camera.h"
00035 #include "Font.h"
00036
00037 #include "GUIHeaders.h"
00038
00039 #include "Mouseable.h"
00040 #include "KeyListener.h"
00041
00042 class CGameState: public CMouseable, public CKeyListener {
00043
00044 public:
00045
00046 virtual ~CGameState(){
00047 if( m_referencesObject2D != NULL ){
00048 delete [] m_referencesObject2D;
00049 m_referencesObject2D = NULL;
00050 }
00051 }
00052
00053 virtual void init(void) = 0;
00054 virtual void clear(void) = 0;
00055 virtual void updateScene(void) = 0;
00056
00057 void update() {
00058
00059 updateScene();
00060
00061 if (m_gameObject3DManager != NULL) {
00062 m_gameObject3DManager->update();
00063 }
00064
00065 if (m_gameObject2DManager != NULL) {
00066 m_gameObject2DManager->update();
00067 }
00068 }
00069
00070 void render(void) {
00071 if (initialized && m_running) {
00072 m_renderer -> render();
00073 }
00074 }
00075
00076 void keyboard(unsigned char key, int x, int y) {
00077 if (m_gameObject3DManager != NULL) {
00078 m_gameObject3DManager->keyboard(key, x, y);
00079 }
00080
00081 if (m_gameObject2DManager != NULL) {
00082 m_gameObject2DManager->keyboard(key, x, y);
00083 }
00084 }
00085 ;
00086
00087 void keyboardSpecial(int key, int x, int y) {
00088 if (m_gameObject3DManager != NULL) {
00089 m_gameObject3DManager->keyboardSpecial(key, x, y);
00090 }
00091
00092 if (m_gameObject2DManager != NULL) {
00093 m_gameObject2DManager->keyboardSpecial(key, x, y);
00094 }
00095 }
00096
00097 void mouseMove(int x, int y) {
00098 if (m_gameObject3DManager != NULL) {
00099 m_gameObject3DManager->mouseMove(x, y);
00100 }
00101
00102 if (m_gameObject2DManager != NULL) {
00103 m_gameObject2DManager->mouseMove(x, y);
00104 }
00105 }
00106
00107 void mouseButtons(int button, int state, int x, int y) {
00108 if (m_gameObject3DManager != NULL) {
00109 m_gameObject3DManager->mouseButtons(button, state, x, y);
00110 }
00111
00112 if (m_gameObject2DManager != NULL) {
00113 m_gameObject2DManager->mouseButtons(button, state, x, y);
00114 }
00115 }
00116
00122 void showSceneObject2D(int id) {
00123 CGameObject2D* object = this->getReferencedObject2D(id);
00124 if (object != NULL) {
00125 object->show();
00126 }
00127 }
00128
00134 void hideSceneObject2D(int id) {
00135 CGameObject2D* object = this->getReferencedObject2D(id);
00136 if (object != NULL) {
00137 object->hide();
00138 }
00139 }
00140
00146 CGameObject2D* getReferencedObject2D(int index) {
00147
00148 if (index < 0 || m_referencesObject2DSize <= index ) {
00149 return NULL;
00150 }
00151
00152 CGameObject2D* object = NULL;
00153 if ((object = this->m_gameObject2DManager->get(
00154 m_referencesObject2D[index])) != NULL) {
00155 return object;
00156 }
00157
00158 return NULL;
00159 }
00160
00166 void createObject2DReferences( int size ){
00167 if( this->m_referencesObject2D == NULL){
00168
00169 this->m_referencesObject2D = new int[size];
00170 this->m_referencesObject2DSize = size;
00171
00172 for( int i = 0; i < m_referencesObject2DSize; i++ ){
00173 this->m_referencesObject2D[i] = -1;
00174 }
00175
00176 }
00177 }
00178
00179 bool isRunning() {
00180 return m_running;
00181 }
00182
00183 int getNextState() {
00184 return m_nextStateId;
00185 }
00186
00187 void setNextState(int nextStateId) {
00188 m_nextStateId = nextStateId;
00189 }
00190
00191 protected:
00192 CGameState() :
00193 initialized(false), m_nextStateId(-1) {
00194
00195 m_renderer = CRenderer::getInstance();
00196 m_gameObject3DManager = CGameObject3DManager::getInstance();
00197 m_gameObject2DManager = CGameObject2DManager::getInstance();
00198 m_camera = CCamera::getInstance();
00199
00200 m_renderer->setObject3DManager(m_gameObject3DManager);
00201 m_renderer->setObject2DManager(m_gameObject2DManager);
00202
00203 m_referencesObject2D = NULL;
00204
00205 }
00206
00207 bool initialized;
00208 bool m_running;
00209 int m_nextStateId;
00210
00211 int* m_referencesObject2D;
00212 int m_referencesObject2DSize;
00213
00214 CRenderer* m_renderer;
00215 CGameObject3DManager* m_gameObject3DManager;
00216 CGameObject2DManager* m_gameObject2DManager;
00217 CCamera* m_camera;
00218
00219 };
00220
00221 #endif
00222