/*! -------------------------------------------------------------------- \file game.h \brief Encapsulate game data \author Roy Thompson \date 2002-11-09 // -------------------------------------------------------------------*/ #ifndef __GAME_H__ #define __GAME_H__ #include "camera.h" #include "world.h" #include "input.h" //! convenience definition for the Game singleton #define theGame Game::getInstance() //--------------------------------------------------------------------- // Game // //! Class to encapsulate all game data // //--------------------------------------------------------------------- class Game { public: Game(); virtual ~Game(); //! returns a handle to the singleton instance of Game (use "theGame") static Game& getInstance() { if (!s_pGame) s_pGame = new Game(); return *s_pGame; } //! default game window size and title static const int DEFAULT_WINDOW_WIDTH = 1024; static const int DEFAULT_WINDOW_HEIGHT = 768; static const int MIN_WINDOW_SIZE = 5; static const char* WINDOW_TITLE; //! initialize game data bool Init(const char* levelFilename, bool soundOn); //! exectute main game loop void Run(); unsigned short GetWidth() { return _iWindowWidth; } unsigned short GetHeight() { return _iWindowHeight; } //! takes a snapshot of the current window and saves it into // filename in jpg format. returns true if saved successfully, // false otherwise. // NOTE: when saving image files, try to use a local path, // such as /usr/tmp instead of your andrew space, for better speed. bool _CaptureImage(const char *filename); private: //! initialize main window bool _InitWindow(); //! initialize the popup menu bool _InitPopupMenu(); //! read level description file bool _ReadLevel(const char* levelFilename); //! renders world contents to windows void _Render(); //! update game state for single game loop iteration void _UpdateState(); //! update the state of the cameras void _UpdateCameraLocations(); //! resize window void _ReshapeWindow(int w, int h); #if 1 //! process keyboard events void _ProcessKeyDown(unsigned char key, int w, int h); void _ProcessKeyUp(unsigned char key, int w, int h); void _ProcessSpecialDown(int key, int x, int y); void _ProcessSpecialUp(int ket, int x, int y); #endif //! checks if a certain char key is being pressed bool _IsKeyPressed(unsigned char key) { return _bKeyPressed[(int) key]; } bool _IsSpecialPressed(int key) { return _bSpecPressed[key]; } //! callback processing static Game* s_pGame; static void _DisplayCB() { s_pGame->_Render(); } static void _IdleCB() { s_pGame->_UpdateState(); } static void _ReshapeCB(int w, int h) { s_pGame->_ReshapeWindow(w, h); } static void _KeyDownCB(unsigned char key, int x, int y) // { s_pGame->_ProcessKeyDown(key, x, y); } { Input::KeyDownCallback(key, x, y); } static void _KeyUpCB(unsigned char key, int x, int y) // { s_pGame->_ProcessKeyUp(key, x, y); } { Input::KeyUpCallback(key, x, y); } static void _SpecialDownCB(int key, int x, int y) // { s_pGame->_ProcessSpecialDown(key, x, y); } { Input::KeySpecialDownCallback(key, x, y); } static void _SpecialUpCB(int key, int x, int y) // { s_pGame->_ProcessSpecialUp(key, x, y); } { Input::KeySpecialUpCallback(key, x, y); } static void _MenuCB(int value) { s_pGame->_ProcessKeyDown((unsigned char)value, 0, 0); } //! window identifiers enum RenderView { TOP_VIEW=0, BOT_VIEW, NUM_VIEWS }; //! main window identifier int _mainWindow; //! stores window size in pixels unsigned short _iWindowWidth; unsigned short _iWindowHeight; unsigned short _iHalfHeight; //! array to store which char keys are being pressed static const int MAX_KEYS = 256; bool _bKeyPressed[MAX_KEYS]; enum SpecialKey { KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT, NUM_SPECIAL}; bool _bSpecPressed[NUM_SPECIAL]; //! data filenames static const int MAX_LEN = 256; char _skyboxPath[MAX_LEN]; char _musicFile[MAX_LEN]; // char _courseFilename[MAX_LEN]; float _timeElapsed; //!< time elapsed since last update (sec) float _lastTime; int _numLevels; int _currentLevel; enum GameState { GAME_START = 0, GAME_INLEVEL, GAME_BWLEVEL, GAME_OVER, NUM_STATES}; }; #endif // __GAME_H__