Advertisement
Kondensator

Main.cpp

Jul 7th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.44 KB | None | 0 0
  1.  
  2. #include "Headers.h"
  3. #include "GlobalVar.h"
  4. #include "functions.h"
  5.  
  6. using namespace std;
  7.  
  8. class LTexture;
  9. class CharProp;
  10.  
  11. int main( int argc, char* argv[] )
  12. {
  13.         //Properties of character
  14.         gracz.x = 0;
  15.         gracz.y = 0;
  16.         gracz.h = 64;
  17.         gracz.w = 64;
  18.        
  19.         //Initialisation
  20.         if ( !init() )
  21.         {
  22.                 cout << "Could not init\n";
  23.         }
  24.         else
  25.         {
  26.                 if ( !loadMedia() )
  27.                 {
  28.                         cout << "Could not load media\n";
  29.                 }
  30.                 else
  31.                 {
  32.                         SDL_SetWindowIcon( gWindow, Icon);
  33.                         SDL_FreeSurface( Icon );
  34.                        
  35.                         bool quit = false;
  36.  
  37.                         SDL_Event e;
  38.  
  39.                         SDL_RenderClear( gRenderer );
  40.  
  41.                         renderAll();
  42.                         SDL_RenderPresent(gRenderer);
  43.                        
  44.                         while ( !quit )
  45.                         {
  46.                             short MoveMultiplier = 32;
  47.  
  48.                                 while( SDL_PollEvent( &e )  )
  49.                                 {
  50.                                        if ( e.type == SDL_QUIT )
  51.                                         {
  52.                                                 quit = true;
  53.                                         }
  54.                                         switch ( e.key.keysym.sym )
  55.                                         {
  56.                                                 case SDLK_UP:
  57.                                                 {
  58.                                                         if( gracz.y > 0 && gracz.y != 0)
  59.                                                         {
  60.                                                                 gracz.y -= MoveMultiplier;
  61.                                                                 std::cout<<gracz.x<<" "<<gracz.y<<endl;
  62.                                                                 renderAll();
  63.                                                         }
  64.                                                 }
  65.                                                 break;
  66.                                                 case SDLK_DOWN:
  67.                                                 {
  68.                                                         if( gracz.y+gracz.h < SCREEN_HEIGHT && gracz.y+gracz.h != SCREEN_HEIGHT)
  69.                                                         {
  70.                                                                 gracz.y += MoveMultiplier;
  71.                                                                 std::cout<<gracz.x<<" "<<gracz.y<<endl;
  72.                                                                 renderAll();
  73.                                                         }
  74.  
  75.                                                 }
  76.                                                 break;
  77.                                                 case SDLK_LEFT:
  78.                                                 {
  79.                                                         if( gracz.x- MoveMultiplier >= 0 )
  80.                                                         {
  81.                                                                 gracz.x -= MoveMultiplier;
  82.                                                                 std::cout<<gracz.x<<" "<<gracz.y<<endl;
  83.                                                                 renderAll();
  84.                                                         }
  85.  
  86.                                                 }
  87.                                                 break;
  88.                                                 case SDLK_RIGHT:
  89.                                                 {
  90.                                                         if( gracz.x+gracz.w+ MoveMultiplier <= SCREEN_WIDTH)
  91.                                                         {
  92.                                                                 gracz.x += MoveMultiplier;
  93.                                                                 std::cout<<gracz.x<<" "<<gracz.y<<endl;
  94.                                                                 renderAll();
  95.                                                         }
  96.  
  97.                                                 }
  98.                                                 break;
  99.  
  100.                                         }
  101.                                 }
  102.                         }
  103.                 }
  104.         }
  105.         close();
  106.         return 0;
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement