Guest User

Untitled

a guest
Feb 8th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. /*
  2.  * Game.cpp
  3.  *  Holds info for main game loop
  4.  *
  5.  *
  6.  *
  7.  */
  8.  
  9. #include <SDL2/SDL.h>
  10. #include <iostream>
  11.  
  12. #include "Game.h"
  13. #include "Graphics.h"
  14. #include "functions.h"
  15.  
  16. Game::Game() {
  17.     if(SDL_Init(SDL_INIT_EVERYTHING) == -1){
  18.         printError("SDL_Init()");
  19.         SDL_Quit();
  20.     }
  21.  
  22.     _isRunning= true;
  23. }
  24.  
  25. Game::~Game() {
  26.     SDL_Quit();
  27. }
  28.  
  29. void Game::run(){
  30.     Graphics graphics;
  31.     Layer background(graphics.getRenderer(), graphics._windowWidth, graphics._windowHeight);
  32.  
  33.     while(_isRunning){
  34.         while(SDL_PollEvent(&_ev) != 0){
  35.             if(_ev.type == SDL_QUIT)
  36.                 _isRunning= false;
  37.         }
  38.  
  39.         if(SDL_RenderClear(graphics.getRenderer()) == -1)
  40.             printError("SDL_RenderClear()");
  41.  
  42.         if( SDL_RenderCopy(graphics.getRenderer(), background.getTexture(), NULL, NULL) == -1)
  43.             printError("SDL_RenderCopy()");
  44.  
  45.         SDL_RenderPresent(graphics.getRenderer());
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment