Advertisement
Al99

main.cpp

Nov 11th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. // the basic functions of a game engine
  2.  
  3. #include "Enemy.h"
  4. #include "Game.h"
  5. #include "GameObject.h"
  6. #include "InputHandler.h"
  7. #include "Player.h"
  8. #include "LoaderParams.h"
  9. #include "TextureManager.h"
  10. #include "SDLGameObject.h"
  11. #include "Vector2d.h"
  12.  
  13. //our game object
  14.  
  15. Game* g_game = 0;
  16.  
  17. const int FPS = 60;
  18. const int DELAY_TIME = 1000.0f / FPS;
  19.  
  20. int main(int argc, char* argv[])
  21. {
  22.     Uint32 frameStart, frameTime;
  23.    
  24.     std::cout <<"game init attempt";
  25.     if(TheGame::Instance()->init("Chapter 1", 100, 100, 640, 480,
  26.     false))
  27.     {
  28.         frameStart = SDL_GetTicks();
  29.        
  30.         std::cout <<"game init success!\n";
  31.         while(TheGame::Instance()->running())
  32.         {
  33.         TheGame::Instance()->handleEvents();
  34.         TheGame::Instance()->update();
  35.         TheGame::Instance()->render();
  36.        
  37.         frameTime = SDL_GetTicks() - frameStart;
  38.        
  39.         if(frameTime< DELAY_TIME)
  40.         {
  41.             SDL_Delay((int) (DELAY_TIME - frameTime));     
  42.         }
  43.     }
  44. }
  45.     else
  46.     {
  47.         std::cout<<"game init failure - " << SDL_GetError() << "\n";
  48.         return -1;
  49.     }
  50.     std::cout<<"game closing";
  51.     TheGame::Instance()->clean();
  52.    
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement