Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #include<stdio.h>
  3. #include<string>
  4. #include<SDL2/SDL.h>
  5. #include<SDL2/SDL_image.h>
  6.  
  7. const int screen_width=1280;
  8. const int screen_height=680;
  9.  
  10. SDL_Window* window=NULL;
  11. SDL_Renderer* render=NULL;
  12. SDL_Texture* tex=NULL;
  13.  
  14.  
  15.  
  16. bool init();
  17. bool loadMedia();
  18. void closes();
  19. int Menu();
  20. int level1();
  21. void build_level1();
  22.  
  23. bool init()
  24. {
  25.     bool success = true;
  26.     if(SDL_Init(SDL_INIT_VIDEO)<0)
  27.     {
  28.         success= false;
  29.         printf("%s\n", SDL_GetError());
  30.     }
  31.     else
  32.     {
  33.  
  34.         if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
  35.             {
  36.                 printf( "Warning: Linear texture filtering not enabled!" );
  37.             }
  38.         window= SDL_CreateWindow("Bouncee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, SDL_WINDOW_SHOWN);
  39.  
  40.         if(window==NULL)
  41.         {
  42.             success =false;
  43.             printf("%s\n", SDL_GetError());
  44.         }
  45.         else
  46.         {
  47.             render=SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
  48.             if(render==NULL)
  49.             {
  50.                 success=false;
  51.                 printf("%s\n", SDL_GetError());
  52.             }
  53.             else
  54.             {
  55.                 SDL_SetRenderDrawColor( render, 0x66, 0xF2, 0xFF, 0xFF );
  56.  
  57.                 int imgFlags = IMG_INIT_PNG;
  58.                 if( !( IMG_Init( imgFlags ) & imgFlags ) )
  59.                 {
  60.                     printf( "%s\n", IMG_GetError() );
  61.                     success = false;
  62.                 }
  63.             }
  64.         }
  65.     }
  66.     return success;
  67. }
  68.  
  69. bool loadMedia()
  70. {
  71.     bool success=true;
  72.     {
  73.             //I'll have to worry about this part later
  74.     }
  75.  
  76.     return success;
  77. }
  78.  
  79. void closes()
  80. {
  81.     SDL_DestroyTexture(tex);
  82.     tex=NULL;
  83.     SDL_DestroyRenderer(render);
  84.     render=NULL;
  85.     SDL_DestroyWindow(window);
  86.     window=NULL;
  87.     IMG_Quit();
  88.     SDL_Quit();
  89. }
  90.  
  91. int Menu()
  92. {
  93.     int success=1;
  94.         //I'll have to worry about this part later
  95.     return success;
  96. }
  97.  
  98. int level1()
  99. {  
  100.     printf("aisdhfiasdfa\n");
  101.     bool quit=false;
  102.  
  103.     SDL_Event e;
  104.     while(!quit)
  105.     {
  106.         while(SDL_PollEvent(&e)!=0)
  107.         {
  108.             if(e.type==SDL_QUIT)
  109.             {
  110.                 quit=true;
  111.                 return 3;
  112.             }
  113.            
  114.  
  115.             build_level1();
  116.  
  117.  
  118.  
  119.            
  120.  
  121.  
  122.  
  123.  
  124.             SDL_RenderPresent(render);
  125.  
  126.         }
  127.     }
  128.     if(quit==true) {return 3;}
  129. }
  130.  
  131. void build_level1()
  132. {
  133.     SDL_Rect ground[10];
  134.  
  135.         SDL_SetRenderDrawColor( render, 0x66, 0xFF, 0xFF, 0xFF );
  136.         SDL_RenderClear(render);
  137.  
  138.         ground[0]={0, 600, 100, 40};
  139.         SDL_SetRenderDrawColor(render, 0x66, 0xFF, 0x66, 0xFF);
  140.         SDL_RenderFillRect(render, &ground[0]);
  141.  
  142.         ground[1]={120, 480, 100, 40};
  143.         SDL_SetRenderDrawColor(render, 0x00, 0x00, 0x00, 0xFF);
  144.         SDL_RenderFillRect(render, &ground[1]);
  145.  
  146.         ground[2]={180, 400, 100, 40};
  147.         SDL_SetRenderDrawColor(render, 0x66, 0x00, 0x00, 0xFF);
  148.         SDL_RenderFillRect(render, &ground[2]);
  149.  
  150.         ground[3]={240, 320, 1000, 40};
  151.         SDL_SetRenderDrawColor(render, 0x66, 0x00, 0x00, 0xFF);
  152.         SDL_RenderFillRect(render, &ground[3]);
  153.  
  154.         ground[4]={320, 400, 100, 40};
  155.         SDL_SetRenderDrawColor(render, 0x66, 0x00, 0x00, 0xFF);
  156.         SDL_RenderFillRect(render, &ground[4]);
  157.  
  158.         ground[5]={400, 300, 100, 40};
  159.         SDL_SetRenderDrawColor(render, 0x66, 0x00, 0x00, 0xFF);
  160.         SDL_RenderFillRect(render, &ground[5]);
  161. }
  162.  
  163. int main()
  164. {
  165.     printf("in main\n");
  166.     int indicator=1;
  167.     int levelUpVar;
  168.     if(init())
  169.     {
  170.         printf("in init()\n");
  171.         if(loadMedia())
  172.         {
  173.             printf("in loadMedia()\n");
  174.             while(indicator)
  175.             {
  176.                 if(Menu())
  177.                 {
  178.                     levelUpVar=level1();
  179.                     printf("crossed level\n");
  180.                     if(levelUpVar==1)
  181.                     {
  182.                        
  183.                     }
  184.                     else if(levelUpVar==2)
  185.                     {
  186.                         //display_Game_over();
  187.  
  188.                     }
  189.                     else if(levelUpVar==3)
  190.                     {
  191.                         closes();
  192.                         return 0;
  193.                     }
  194.                 }
  195.                 else indicator=0;
  196.             }
  197.         }
  198.     }
  199.     closes();
  200.     return 0;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement