Advertisement
FAB181

Untitled

Nov 18th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 51.58 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. #include<string.h>
  7. #include<SDL2/SDL_ttf.h>
  8.  
  9. enum keys{
  10.     useless, left, right, up, back, end, show_high_score, anything,
  11.     start, rstart,
  12.     quitbutton, rquit,
  13.     instructions, rinstructions,
  14.     highscore_e, rhighscore,
  15.     bouncee,
  16.     gameover,
  17.     nextlevel, rnextlevel,
  18.     menu, rmenu,
  19.     Score, score__,
  20.     background, greendot,
  21.     level_one, level_two, level_three,
  22.     rback,
  23.     description, originalback, box, text, input,
  24.     bomb
  25. , point, ticks, no, yes, rno, ryes, another_text
  26. };
  27.  
  28. const int screen_width=1280;
  29. const int screen_height=680;
  30. const int gravity=2;
  31.  
  32. int score=0, cnt=0, prevscore=0;
  33. int high_score;
  34. int a[1000], b[1000], death_x[1000], death_y[1000];
  35. int tick, tick1, tick2;
  36. char times[100];
  37. bool saved_game=false, load_saved_game=false, saved_state=false;
  38. int initialTime=0;
  39. int level_id=0;
  40.  
  41. SDL_Window* window=NULL;
  42. SDL_Renderer* game_renderer=NULL;
  43. SDL_Texture* tex=NULL;
  44. TTF_Font *gFont = NULL;
  45.  
  46. bool init();
  47. bool loadMedia();
  48. void closes();
  49.  
  50. //functions handling movement, collision and platform detections, score, poison, time
  51. bool detect(SDL_Rect, SDL_Rect);
  52. void move();
  53. bool x_range(int, int , int);
  54. bool solid_footing();
  55. bool solid_footing_ver();
  56. void set1(int a[], int b[]);
  57. void count_point();
  58. int event_id();
  59. void score_calc();
  60. void score_box();
  61. void sort();
  62. void time_func();
  63. void green();
  64.  
  65. //functions handling displays
  66. int Menu();
  67. int game_over();
  68. int score_display();
  69. int high_score_display();
  70. int save_game();
  71. void game_state_saving();
  72. int load_from_file();
  73. int actual_loading();
  74.  
  75. //levels and level builders
  76. int level1();
  77. int level2();
  78. void build_level1();
  79. void build_level2();
  80. void build_level3();
  81.  
  82. //a function to make rectangle handling easier
  83. void rect(SDL_Rect, int , int, int , int, int, int, int , int);
  84.  
  85. struct score_structure
  86. {
  87.     char a[100];
  88.     int i;
  89. };
  90.  
  91. struct rectangle
  92. {
  93.         SDL_Rect a[300];
  94.         int number_of;
  95.         int id[300], count;
  96. };
  97.  
  98. rectangle platforms, dots, death;
  99.  
  100. class texture
  101. {
  102.     public:
  103.         texture();
  104.         ~texture();
  105.  
  106.         bool loadFromFile( std::string path );
  107.        
  108.         #if defined(_SDL_TTF_H) || defined(SDL_TTF_H)
  109.         //Creates image from font string
  110.         bool loadFromRenderedText( std::string textureText, SDL_Color textColor );
  111.         #endif
  112.  
  113.         void free();
  114.  
  115.         void render( int x, int y, SDL_Rect* clip = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE );
  116.  
  117.         //Gets image dimensions
  118.         int getWidth();
  119.         int getHeight();
  120.  
  121.     private:
  122.         //The actual hardware texture
  123.         SDL_Texture* mTexture;
  124.  
  125.         //Image dimensions
  126.         int mWidth;
  127.         int mHeight;
  128. };
  129.  
  130. texture::texture()
  131. {
  132.     //Initialize
  133.     mTexture = NULL;
  134.     mWidth = 0;
  135.     mHeight = 0;
  136. }
  137.  
  138. texture::~texture()
  139. {
  140.     //Deallocate
  141.     free();
  142. }
  143.  
  144. bool texture::loadFromFile( std::string path )
  145. {
  146.     //Get rid of preexisting texture
  147.     free();
  148.  
  149.     //The final texture
  150.     SDL_Texture* newTexture = NULL;
  151.  
  152.     //Load image at specified path
  153.     SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
  154.     if( loadedSurface == NULL )
  155.     {
  156.         printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
  157.     }
  158.     else
  159.     {
  160.         //Color key image
  161.         if(path!="description.png")
  162.         SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0xFF, 0xFF, 0xFF ) );
  163.  
  164.         //Create texture from surface pixels
  165.         newTexture = SDL_CreateTextureFromSurface( game_renderer, loadedSurface );
  166.         if( newTexture == NULL )
  167.         {
  168.             printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
  169.         }
  170.         else
  171.         {
  172.             //Get image dimensions
  173.             mWidth = loadedSurface->w;
  174.             mHeight = loadedSurface->h;
  175.         }
  176.  
  177.         //Get rid of previous loaded surface
  178.         SDL_FreeSurface( loadedSurface );
  179.     }
  180.  
  181.     //Return success
  182.     mTexture = newTexture;
  183.     return mTexture != NULL;
  184. }
  185.  
  186. #if defined(_SDL_TTF_H) || defined(SDL_TTF_H)
  187. bool texture::loadFromRenderedText( std::string textureText, SDL_Color textColor )
  188. {
  189.     //Get rid of pre-existing texture
  190.     free();
  191.  
  192.     //Render text surface
  193.     SDL_Surface* textSurface = TTF_RenderText_Solid( gFont, textureText.c_str(), textColor );
  194.     if( textSurface != NULL )
  195.     {
  196.         //Create texture from surface pixels
  197.         mTexture = SDL_CreateTextureFromSurface( game_renderer, textSurface );
  198.         if( mTexture == NULL )
  199.         {
  200.             printf( "%s\n", SDL_GetError() );
  201.         }
  202.         else
  203.         {
  204.             //Get image dimensions
  205.             mWidth = textSurface->w;
  206.             mHeight = textSurface->h;
  207.         }
  208.         //Get rid of previous surface
  209.         SDL_FreeSurface( textSurface );
  210.     }
  211.     else
  212.     {
  213.         printf( "%s\n", TTF_GetError() );
  214.     }
  215.     //Return success
  216.     return mTexture != NULL;
  217. }
  218. #endif
  219.  
  220. void texture::free()
  221. {
  222.     //Frees texture if it exists
  223.     if( mTexture != NULL )
  224.     {
  225.         SDL_DestroyTexture( mTexture );
  226.         mTexture = NULL;
  227.         mWidth = 0;
  228.         mHeight = 0;
  229.     }
  230. }
  231.  
  232. void texture::render( int x, int y, SDL_Rect* clip, double angle, SDL_Point* center, SDL_RendererFlip flip )
  233. {
  234.     //Set rendering space and render to screen
  235.     SDL_Rect renderQuad = { x, y, mWidth, mHeight };
  236.  
  237.     //Set clip rendering dimension
  238.     if( clip != NULL )
  239.     {
  240.         renderQuad.w = clip->w;
  241.         renderQuad.h = clip->h;
  242.     }
  243.  
  244.     //Render to screen
  245.     SDL_RenderCopyEx( game_renderer, mTexture, clip, &renderQuad, angle, center, flip );
  246. }
  247.  
  248. int texture::getWidth()
  249. {
  250.     return mWidth;
  251. }
  252.  
  253. int texture::getHeight()
  254. {
  255.     return mHeight;
  256. }
  257.  
  258.  
  259. texture character_texture;
  260.  
  261. texture backgrounds[100];
  262.  
  263. struct dummy
  264. {
  265.        
  266.         static const int dummyw = 20;
  267.         static const int dummyh = 20;
  268.  
  269.         static const int vel = 10;
  270.  
  271.  
  272.         void detect_points();
  273.         void detect_death();
  274.  
  275.         void render();
  276.  
  277.         void handle(int, int);
  278.  
  279.         int posX, posY;
  280.         int velX, velY;
  281. };
  282.  
  283. void green()
  284. {
  285.     char s[100];
  286.             sprintf(s, "POISON: %d", cnt);
  287.             SDL_Color t={2, 36, 37};
  288.             backgrounds[greendot].loadFromRenderedText(s, t);
  289.             if(cnt!=0) backgrounds[greendot].render(1000, 630);
  290. }
  291.  
  292. dummy character;
  293. void dummy::detect_death()
  294. {
  295.     SDL_Rect a={character.posX, character.posY, dummyw, character.dummyh};
  296.     for(int i=0; i<=death.number_of; i++)
  297.     {
  298.     SDL_Rect b={ death.a[i].x , death.a[i].y , 20, 20};
  299.     if(detect(a, b))
  300.         {
  301.             if(death.id[i]==-1)
  302.             {
  303.             cnt++;
  304.             green();
  305.             }
  306.             death.id[i]=0;
  307.         }
  308.  
  309.     }
  310. }
  311.  
  312. void dummy::detect_points() //x=character.posX of char y=character.posY of char
  313. {  
  314.     SDL_Rect a={character.posX, character.posY, dummyw, character.dummyh};
  315.     for(int i=0; i<=dots.number_of; i++)
  316.     {
  317.     SDL_Rect b={ dots.a[i].x , dots.a[i].y , 20, 20};
  318.     if(detect(a, b))
  319.         {
  320.             dots.id[i]=0;
  321.         }
  322.     }
  323. }
  324.  
  325. void dummy::render()
  326. {
  327.     //Show the dot
  328.     character_texture.render( character.posX, character.posY );
  329. }
  330.  
  331.  
  332.  
  333. void dummy::handle(int keynum, int level)
  334. {
  335.     if(keynum==right)
  336.     {
  337.         velX=vel;
  338.         character.velY=0;
  339.         move();
  340.         if(!solid_footing_ver())
  341.         {
  342.             velX=0;
  343.             while(!solid_footing_ver())
  344.             {
  345.                 character.velY+=gravity;
  346.                 move();
  347.                 backgrounds[background].render(0, 0);
  348.             if(level ==1) build_level1();
  349.             else if(level ==2) build_level2();
  350.             else build_level3();
  351.             character.render();
  352.             backgrounds[back].render(20, 630);
  353.             time_func();
  354.             score_box();
  355.            
  356.             if(cnt!=0) green();
  357.             SDL_RenderPresent(game_renderer);
  358.             SDL_Delay(25);
  359.  
  360.  
  361.             }
  362.         }
  363.     }
  364.     if(keynum==left)
  365.     {
  366.         velX=-vel;
  367.         character.velY=0;
  368.         move();
  369.         if(!solid_footing_ver())
  370.         {
  371.             velX=0;
  372.             while(!solid_footing_ver())
  373.             {
  374.                 character.velY+=gravity;
  375.                 move();
  376.                     backgrounds[background].render(0, 0);
  377.             if(level ==1) build_level1();
  378.             else if(level ==2) build_level2();
  379.             else build_level3();
  380.            
  381.             character.render();
  382.             backgrounds[back].render(20, 630);
  383.             time_func();
  384.             score_box();
  385.            
  386.             if(cnt!=0) green();
  387.             SDL_RenderPresent(game_renderer);
  388.             SDL_Delay(25);
  389.                
  390.  
  391.             }
  392.         }
  393.     }
  394.     if(keynum==up)
  395.     {
  396.         velX=0;
  397.         character.velY=-22;
  398.         bool jump=true;
  399.         while(jump)
  400.         {
  401.             character.velY+=gravity;
  402.             move();
  403.  
  404.             backgrounds[background].render(0, 0);
  405.             if(level ==1) build_level1();
  406.             else if(level ==2) build_level2();
  407.             else build_level3();
  408.                
  409.             character.render();
  410.             backgrounds[back].render(20, 630);
  411.             time_func();
  412.             score_box();
  413.            
  414.             if(cnt!=0) green();
  415.             SDL_RenderPresent(game_renderer);
  416.             SDL_Delay(25);
  417.  
  418.             if(velY>=0)
  419.             {
  420.                 if(solid_footing_ver()) jump=false;
  421.             }
  422.         }
  423.     }
  424.     if(keynum==up+right || keynum==up+left)
  425.     {
  426.         if(keynum==up+right) velX=vel;
  427.         else if(keynum==up+left) velX=0-vel;
  428.         character.velY=-22;
  429.         bool jump=true;
  430.         while(jump)
  431.         {
  432.             character.velY+=gravity;
  433.             move();
  434.  
  435.                 backgrounds[background].render(0, 0);
  436.             if(level ==1) build_level1();
  437.             else if(level ==2) build_level2();
  438.             else build_level3();
  439.            
  440.             character.render();
  441.             backgrounds[back].render(20, 630);
  442.             time_func();
  443.             score_box();
  444.            
  445.             if(cnt!=0) green();
  446.             SDL_RenderPresent(game_renderer);
  447.             SDL_Delay(25);
  448.  
  449.  
  450.             if(velY>=0)
  451.             {
  452.                 if(solid_footing()) jump=false;
  453.             }
  454.         }
  455.     }
  456. }
  457.  
  458. void game_state_saving()
  459. {
  460.     FILE *gameS = fopen("game_save_info.txt", "w");
  461.     fprintf(gameS, "%d\n", level_id);
  462.     fprintf(gameS, "%d %d\n", character.posX, character.posY);
  463.     fprintf(gameS, "%d\n", dots.number_of);
  464.     for(int n=0; n<=dots.number_of; n++)
  465.     {
  466.         fprintf(gameS, "%d %d %d\n", a[n], b[n], dots.id[n]);
  467.     }
  468.     fprintf(gameS, "%d\n", death.number_of);
  469.     for(int n=0; n<=death.number_of; n++)
  470.     {
  471.         fprintf(gameS, "%d %d %d\n", death_x[n], death_y[n], death.id[n]);
  472.     }
  473.     fprintf(gameS, "%d %d\n", score, prevscore);
  474.     fprintf(gameS, "%d\n", tick);
  475.     fprintf(gameS, "%d\n", cnt);
  476.     fclose(gameS);
  477.     return;
  478. }
  479.  
  480. int save_game()
  481. {
  482.    
  483.     char s[100]="Save the game for later?";
  484.     SDL_Color co={255, 255, 255};
  485.     backgrounds[another_text].loadFromRenderedText(s, co);
  486.  
  487.     bool yes_button=false, no_button=false;
  488.  
  489.     bool stop = false;
  490.     SDL_Event e;
  491.     while(!stop)
  492.     {
  493.         while(SDL_PollEvent(&e)!=0)
  494.         {
  495.             if(e.type == SDL_QUIT)
  496.                 return end;
  497.             else if(e.type == SDL_MOUSEBUTTONDOWN)
  498.             {
  499.                 int p, q;
  500.                 SDL_GetMouseState(&p, &q);
  501.                 if(p>380 && p<280+252 && q>270 && q<270+205)
  502.                     {
  503.                         game_state_saving();
  504.                         return menu;
  505.                     }
  506.                 else if(p>700 && p<700+252 && q>270 && q<270+205)
  507.                     {
  508.                         FILE *p=fopen("game_save_info.txt", "w");
  509.                         fprintf(p, "%d\n", 0);
  510.                         fclose(p);
  511.                         return no;
  512.                     }
  513.             }
  514.         }
  515.         int p, q;
  516.         SDL_GetMouseState(&p, &q);
  517.         if(p>380 && p<280+252 && q>270 && q<270+205)
  518.             yes_button=true;
  519.         else if(p>700 && p<700+252 && q>270 && q<270+205)
  520.             no_button=true;
  521.  
  522.         SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  523.         SDL_RenderClear(game_renderer);
  524.  
  525.         backgrounds[background].render(0, 0);
  526.         backgrounds[another_text].render(200, 150);
  527.  
  528.         if(yes_button) backgrounds[ryes].render(380, 270);
  529.         else backgrounds[yes].render(380, 270);
  530.  
  531.         if(no_button) backgrounds[rno].render(700, 270);
  532.         else
  533.             {
  534.                 backgrounds[no].render(700, 270);
  535.             }
  536.         SDL_RenderPresent(game_renderer);
  537.         yes_button=false;
  538.         no_button=false;
  539.     }
  540. }
  541.  
  542. int event_id(int level,const Uint8* ks, SDL_Event e)
  543. {
  544.             if(ks[SDL_SCANCODE_RIGHT] && !ks[SDL_SCANCODE_UP] && !ks[SDL_SCANCODE_LEFT])
  545.             {
  546.                 character.handle(right, level);
  547.             }
  548.             else if(!ks[SDL_SCANCODE_RIGHT] && !ks[SDL_SCANCODE_UP] && ks[SDL_SCANCODE_LEFT])
  549.             {
  550.                 character.handle(left, level);
  551.             }
  552.             else if(ks[SDL_SCANCODE_UP] && !ks[SDL_SCANCODE_RIGHT] && !ks[SDL_SCANCODE_LEFT])
  553.             {
  554.                 character.handle(up, level);
  555.             }
  556.             else if(ks[SDL_SCANCODE_UP] && ks[SDL_SCANCODE_RIGHT] && !ks[SDL_SCANCODE_LEFT])
  557.             {
  558.                 character.handle(up+right, level);
  559.             }
  560.             else if(ks[SDL_SCANCODE_UP] && !ks[SDL_SCANCODE_RIGHT] && ks[SDL_SCANCODE_LEFT])
  561.             {
  562.                 character.handle(up+left, level);
  563.             }
  564. }
  565.  
  566. bool x_range(int x, int sth, int wi)
  567. {
  568.     if(x>sth-18 && x<sth+wi-2)
  569.         return true;
  570.     return false;
  571. }
  572. bool solid_footing()
  573. {
  574.     int top=character.posY, bottom=character.posY+character.dummyh;
  575.     for(int i=0; i<=platforms.number_of; i++)
  576.     {
  577.         if(x_range(character.posX, platforms.a[i].x, platforms.a[i].w))
  578.         {
  579.             if(bottom==platforms.a[i].y) return true;
  580.             else if(top<=platforms.a[i].y && bottom>platforms.a[i].y)
  581.             {
  582.                 character.posY=platforms.a[i].y-character.dummyh;
  583.                                 return true;
  584.             }
  585.             else if(bottom + character.velY + gravity <= platforms.a[i].y) continue;
  586.             else if((platforms.a[i].y-bottom)<(character.velY+gravity) && x_range(character.posX+character.velX, platforms.a[i].x, platforms.a[i].w) && character.posY<platforms.a[i].y)
  587.             {
  588.                 character.posY=platforms.a[i].y-character.dummyh;
  589.                 return true;
  590.             }
  591.         }
  592.     }
  593.     return false;
  594. }
  595. bool solid_footing_ver()
  596. {
  597.     int top=character.posY, bottom=character.posY+character.dummyh;
  598.     for(int i=0; i<=platforms.number_of; i++)
  599.     {
  600.         if(x_range(character.posX, platforms.a[i].x, platforms.a[i].w))
  601.         {
  602.             if(bottom==platforms.a[i].y) return true;
  603.             else if(top<platforms.a[i].y && bottom>platforms.a[i].y)
  604.             {
  605.                 character.posY=platforms.a[i].y-character.dummyh;
  606.                                 return true;
  607.             }
  608.             else if(bottom + character.velY + gravity <= platforms.a[i].y) continue;
  609.             else if((platforms.a[i].y-bottom)<(bottom+character.velY+gravity) && character.posY<platforms.a[i].y)
  610.             {
  611.                 character.posY=platforms.a[i].y-character.dummyh;
  612.                                 return true;
  613.             }
  614.         }
  615.     }
  616.     return false;  
  617. }
  618. void move()
  619. {
  620.     //Move the dot left or right
  621.     character.posX += character.velX;
  622.  
  623.     //If the dot went too far to the left or right
  624.     if( ( character.posX < 0 ) || ( character.posX + character.dummyh > screen_width ) )
  625.     {
  626.         //Move back
  627.         character.posX -= character.velX;
  628.     }
  629.  
  630.     character.posY += character.velY;
  631.  
  632.  
  633.     //If the dot went too far up or down
  634.     if( ( character.posY < 0 ) || ( character.posY + character.dummyh > screen_height ) )
  635.     {
  636.         //Move back
  637.         if(character.posY<0)
  638.         character.posY -= character.velY;
  639.         else
  640.         {
  641.             character.posY=screen_height-character.dummyh;
  642.         }
  643.     }
  644.     character.detect_points();
  645.     character.detect_death();
  646. }
  647.  
  648. bool detect (SDL_Rect a, SDL_Rect b)
  649. {
  650.     int leftA, leftB;
  651.     int rightA, rightB;
  652.     int topA, topB;
  653.     int bottomA, bottomB;
  654.  
  655.     //Calculate the sides of rect A
  656.     leftA = a.x;
  657.     rightA = a.x + a.w;
  658.     topA = a.y;
  659.     bottomA = a.y + a.h;
  660.  
  661.     //Calculate the sides of rect B
  662.     leftB = b.x;
  663.     rightB = b.x + b.w;
  664.     topB = b.y;
  665.     bottomB = b.y + b.h;
  666.  
  667.     //If any of the sides from A are outside of B
  668.     if( bottomA <= topB )
  669.     {
  670.         return false;
  671.     }
  672.  
  673.     if( topA >= bottomB )
  674.     {
  675.         return false;
  676.     }
  677.  
  678.     if( rightA <= leftB )
  679.     {
  680.         return false;
  681.     }
  682.  
  683.     if( leftA >= rightB )
  684.     {
  685.         return false;
  686.     }
  687.  
  688.     //If none of the sides from A are outside B
  689.     return true;
  690. }
  691.  
  692.  
  693. bool init()
  694. {
  695.     bool success = true;
  696.     if(SDL_Init(SDL_INIT_VIDEO)<0)
  697.     {
  698.         success= false;
  699.         printf("%s\n", SDL_GetError());
  700.     }
  701.     else
  702.     {
  703.  
  704.         if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
  705.             {
  706.                 printf( "Warning: Linear texture filtering not enabled!" );
  707.             }
  708.         window= SDL_CreateWindow("Bouncee", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen_width, screen_height, SDL_WINDOW_SHOWN);
  709.  
  710.         if(window==NULL)
  711.         {
  712.             success =false;
  713.             printf("%s\n", SDL_GetError());
  714.         }
  715.         else
  716.         {
  717.             game_renderer=SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
  718.             if(game_renderer==NULL)
  719.             {
  720.                 success=false;
  721.                 printf("%s\n", SDL_GetError());
  722.             }
  723.             else
  724.             {
  725.                 SDL_SetRenderDrawColor( game_renderer, 0x66, 0xF2, 0xFF, 0xFF );
  726.  
  727.                 int imgFlags = IMG_INIT_PNG;
  728.                 if( !( IMG_Init( imgFlags ) & imgFlags ) )
  729.                 {
  730.                     printf( "%s\n", IMG_GetError() );
  731.                     success = false;
  732.                 }
  733.                 if( TTF_Init() == -1 )
  734.                 {
  735.                     printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
  736.                     success = false;
  737.                 }
  738.             }
  739.         }
  740.     }
  741.     return success;
  742. }
  743.  
  744. bool loadMedia()
  745. {
  746.     bool success=true;
  747.     gFont = TTF_OpenFont( "berkshireswash-regular.ttf", 40 );
  748.     if( gFont == NULL )
  749.     {
  750.         printf( "Failed to load lazy font! SDL_ttf Error: %s\n", TTF_GetError() );
  751.         success = false;
  752.     }
  753.     if(!backgrounds[no].loadFromFile( "no.bmp" ))
  754.     {
  755.         printf("no\n");
  756.         success=false;
  757.     }
  758.     if(!backgrounds[rno].loadFromFile( "no_red.bmp" ))
  759.     {
  760.         printf("red no\n");
  761.         success=false;
  762.     }
  763.     if(!backgrounds[yes].loadFromFile( "yes.bmp" ))
  764.     {
  765.         printf("yes\n");
  766.         success=false;
  767.     }
  768.     if(!backgrounds[ryes].loadFromFile( "yes_red.bmp" ))
  769.     {
  770.         printf("yes red\n");
  771.         success=false;
  772.     }
  773.     if(!backgrounds[point].loadFromFile("14.png"))
  774.     {
  775.         success=false;
  776.     }
  777.     if(!backgrounds[bomb].loadFromFile( "bomb.png" ))
  778.     {
  779.         printf("failed ot load bomb\n");
  780.         success=false;
  781.     }
  782.     if(!backgrounds[description].loadFromFile( "description.png" ))
  783.     {
  784.         printf("failed to load description\n");
  785.         success=false;
  786.     }
  787.     if(!backgrounds[originalback].loadFromFile( "bouncee.png" ))
  788.     {
  789.         printf("failed to load bouncee\n");
  790.         success=false;
  791.     }
  792.     if(!backgrounds[back].loadFromFile( "back.bmp" ))
  793.     {
  794.         printf("failed to load back button\n");
  795.         success=false;
  796.     }
  797.     if(!backgrounds[rback].loadFromFile( "back_red.bmp" ))
  798.     {
  799.         printf("failed to load red back button\n");
  800.         success=false;
  801.     }
  802.     if( !character_texture.loadFromFile( "dot1.bmp" ) )
  803.     {
  804.         printf( "Failed to load dot texture!\n" );
  805.         success = false;
  806.     }
  807.     if(!backgrounds[start].loadFromFile("start.bmp"))
  808.     {
  809.         printf("failed to load start texture\n");
  810.         success = false;
  811.     }
  812.     if(!backgrounds[quitbutton].loadFromFile( "quit.bmp" ))
  813.     {
  814.         printf("failed to load quit texture\n");
  815.         success = false;
  816.     }
  817.     if(!backgrounds[instructions].loadFromFile( "instructions.bmp" ))
  818.     {
  819.         printf("failed to load instructions texture\n");
  820.         success = false;
  821.     }
  822.     if(!backgrounds[highscore_e].loadFromFile( "highscore.bmp" ))
  823.     {
  824.         printf("failed to load highscore texture\n");
  825.         success = false;
  826.     }
  827.     if(!backgrounds[rstart].loadFromFile( "start_red.bmp" ))
  828.     {
  829.         printf("failed to load red start texture\n");
  830.         success = false;
  831.     }
  832.     if(!backgrounds[rquit].loadFromFile( "quit_red.bmp" ))
  833.     {
  834.         printf("failed to load quit red texture\n");
  835.         success = false;
  836.     }
  837.     if(!backgrounds[rinstructions].loadFromFile( "instructions_red.bmp" ))
  838.     {
  839.         printf("failed to load red instrucitons texture\n");
  840.         success = false;
  841.     }
  842.     if(!backgrounds[rhighscore].loadFromFile( "highscore_red.bmp" ))
  843.     {
  844.         printf("failed to load red highscore texture\n");
  845.         success = false;
  846.     }
  847.     if(!backgrounds[bouncee].loadFromFile("menubackground.bmp"))
  848.     {
  849.         printf("failed to load bouncee texture\n");
  850.         success=false;
  851.     }
  852.     if(!backgrounds[menu].loadFromFile("menu.bmp"))
  853.     {
  854.         printf("failed to lead menu tecx\n");
  855.         success=false;
  856.     }
  857.     if(!backgrounds[rmenu].loadFromFile("menu_red.bmp"))
  858.     {
  859.         printf("failed to load red menu\n");
  860.         success=false;
  861.     }
  862.     if(!backgrounds[nextlevel].loadFromFile("nextlevel.bmp"))
  863.     {
  864.         printf("failed to laod next level te\n");
  865.         success=false;
  866.     }
  867.     if(!backgrounds[rnextlevel].loadFromFile("nextlevel_red.bmp"))
  868.     {
  869.         printf("failed to load red next level\n");
  870.         success=false;
  871.     }
  872.     if(!backgrounds[gameover].loadFromFile("gameover.bmp"))
  873.     {
  874.         printf("failed to load game over tec\n");
  875.         success=false;
  876.     }
  877.     if(!backgrounds[score__].loadFromFile( "score.bmp" ) )
  878.     {
  879.         printf("failed to load score bg\n");
  880.         success=false;
  881.     }
  882.     if(!backgrounds[background].loadFromFile( "background.bmp" ))
  883.     {
  884.         printf("failed to load last background?");
  885.         success=false;
  886.     }
  887.     return success;
  888. }
  889.  
  890. void closes()
  891. {
  892.     character_texture.free();
  893.     SDL_DestroyTexture(tex);
  894.     tex=NULL;
  895.     SDL_DestroyRenderer(game_renderer);
  896.     game_renderer=NULL;
  897.     SDL_DestroyWindow(window);
  898.     window=NULL;
  899.     IMG_Quit();
  900.     SDL_Quit();
  901. }
  902.  
  903. int high_score_display()
  904. {
  905.     int x, y, k;
  906.     score_structure sc[10];
  907.     char dis[1000];
  908.     SDL_Color textColor={255, 255, 255};
  909.     FILE *p=fopen("score.txt", "r");
  910.  
  911.     for(k=0; k<=4; k++)
  912.     {
  913.         fscanf(p, "%d %s", &sc[k].i, sc[k].a);
  914.     }
  915.    
  916.     fclose(p);
  917.  
  918.     SDL_SetRenderDrawColor(game_renderer, 0, 255, 237, 255);
  919.     SDL_RenderClear(game_renderer);
  920.     backgrounds[background].render(0, 0);
  921.    
  922.  
  923.     sprintf(dis, "HIGH SCORE", high_score);
  924.     backgrounds[Score].loadFromRenderedText(dis, textColor);
  925.     backgrounds[Score].render((screen_width/4)-50, screen_height/4);
  926.  
  927.     for(k=0, x=(screen_width/4)-50, y=screen_height/4 + 50; k<=4; k++, y+=50)
  928.     {
  929.         sprintf(dis, "%d. %d %s", k+1, sc[k].i, sc[k].a);
  930.         backgrounds[Score].loadFromRenderedText(dis, textColor);
  931.         backgrounds[Score].render(x, y);
  932.     }
  933.    
  934.  
  935.     SDL_RenderPresent(game_renderer);
  936.  
  937.     bool quit=false;
  938.     SDL_Event e;
  939.     while(!quit)
  940.     {
  941.         while(SDL_PollEvent(&e)!=0)
  942.         {
  943.             if(e.type==SDL_QUIT)
  944.             {  
  945.                 quit=true;
  946.                 return end;
  947.             }
  948.             if(e.type==SDL_KEYDOWN)
  949.             {
  950.                 if(e.key.keysym.sym==SDLK_RETURN)
  951.                 {
  952.                     quit=true;
  953.                     return useless;
  954.                 }
  955.             }
  956.         }
  957.         SDL_SetRenderDrawColor(game_renderer, 0, 255, 237, 255);
  958.         SDL_RenderClear(game_renderer);
  959.         backgrounds[background].render(0, 0);
  960.         sprintf(dis, "HIGH SCORE", high_score);
  961.        
  962.         backgrounds[Score].loadFromRenderedText(dis, textColor);
  963.         backgrounds[Score].render((screen_width/4)-50, screen_height/4);
  964.  
  965.         for(k=0, x=(screen_width/4)-50, y=screen_height/4 + 50; k<=4; k++, y+=50)
  966.         {
  967.             sprintf(dis, "%d. %d %s", k+1, sc[k].i, sc[k].a);
  968.             backgrounds[Score].loadFromRenderedText(dis, textColor);
  969.             backgrounds[Score].render(x, y);
  970.         }
  971.  
  972.         SDL_RenderPresent(game_renderer);
  973.     }
  974. }
  975. int description_()
  976. {
  977.     SDL_RenderClear(game_renderer);
  978.     backgrounds[description].render(0, 0);
  979.     SDL_RenderPresent(game_renderer);
  980.     SDL_Event e;
  981.     bool quit=false;
  982.     while(!quit)
  983.     {
  984.         while(SDL_PollEvent(&e)!=0)
  985.         {
  986.             if(e.type==SDL_QUIT)
  987.                 return end;
  988.             else if(e.type==SDL_KEYDOWN)
  989.             {
  990.                 if(e.key.keysym.sym==SDLK_RETURN)
  991.                     return anything;
  992.             }
  993.         }
  994.         backgrounds[description].render(0, 0);
  995.         SDL_RenderPresent(game_renderer);
  996.     }
  997. }
  998. int actual_loading()
  999. {
  1000.     int read, level;
  1001.  
  1002.     FILE *gameFile = fopen("game_save_info.txt", "r");
  1003.    
  1004.     fscanf(gameFile, "%d", &level);
  1005.     fscanf(gameFile, "%d %d", &character.posX, &character.posY);
  1006.     fscanf(gameFile, "%d", &dots.number_of);
  1007.     for(int m=0; m<= dots.number_of; m++)
  1008.     {
  1009.         fscanf(gameFile, "%d %d %d", &a[m], &b[m], &dots.id[m]);
  1010.     }
  1011.     fscanf(gameFile, "%d", &death.number_of);
  1012.     for(int m=0; m <= death.number_of; m++)
  1013.     {
  1014.         fscanf(gameFile, "%d %d %d", &death_x[m], &death_y[m], &death.id[m]);
  1015.     }
  1016.     fscanf(gameFile, "%d %d", &score, &prevscore);
  1017.     fscanf(gameFile, "%d", &initialTime);
  1018.     fscanf(gameFile, "%d", &cnt);
  1019.     fclose(gameFile);
  1020.  
  1021.     load_saved_game = true;
  1022.     return level;
  1023. }
  1024.  
  1025. int load_from_file()
  1026. {
  1027.     char s[]="Load previously saved game?";
  1028.     SDL_Color co={255, 255, 255};
  1029.     backgrounds[another_text].loadFromRenderedText(s, co);
  1030.  
  1031.     bool yes_button=false, no_button=false;
  1032.  
  1033.     bool stop = false;
  1034.     SDL_Event e;
  1035.     while(!stop)
  1036.     {
  1037.         while(SDL_PollEvent(&e)!=0)
  1038.         {
  1039.             if(e.type == SDL_QUIT)
  1040.                 return end;
  1041.             else if(e.type == SDL_MOUSEBUTTONDOWN)
  1042.             {
  1043.                 int p, q;
  1044.                 SDL_GetMouseState(&p, &q);
  1045.                 if(p>380 && p<280+252 && q>270 && q<270+205)
  1046.                     {
  1047.                         int level=actual_loading();
  1048.                         load_saved_game=true;
  1049.                         return level;
  1050.                     }
  1051.                 else if(p>700 && p<700+252 && q>270 && q<270+205)
  1052.                     {
  1053.                         return no;
  1054.                     }
  1055.             }
  1056.         }
  1057.         int p, q;
  1058.         SDL_GetMouseState(&p, &q);
  1059.         if(p>380 && p<280+252 && q>270 && q<270+205)
  1060.             yes_button=true;
  1061.         else if(p>700 && p<700+252 && q>270 && q<270+205)
  1062.             no_button=true;
  1063.  
  1064.         SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1065.         SDL_RenderClear(game_renderer);
  1066.  
  1067.         backgrounds[background].render(0, 0);
  1068.         backgrounds[another_text].render(200, 150);
  1069.  
  1070.         if(yes_button) backgrounds[ryes].render(380, 270);
  1071.         else backgrounds[yes].render(380, 270);
  1072.  
  1073.         if(no_button) backgrounds[rno].render(700, 270);
  1074.         else backgrounds[no].render(700, 270);
  1075.  
  1076.         SDL_RenderPresent(game_renderer);
  1077.         yes_button=false;
  1078.         no_button=false;
  1079.     }
  1080.  
  1081. }
  1082.  
  1083. int Menu()
  1084. {
  1085.     FILE *gameS=fopen("game_save_info.txt", "r");
  1086.     int read;
  1087.     fscanf(gameS, "%d", &read);
  1088.     fclose(gameS);
  1089.  
  1090.     if(read!=0) {saved_game=true;}
  1091.     else saved_game=false;
  1092.  
  1093.     bool start_button=false, quit_button=false, description_button = false, highscore_button=false;
  1094.     int success=1;
  1095.  
  1096.     SDL_Event e;
  1097.     bool cancel=false;
  1098.  
  1099.  
  1100.     while(!cancel)
  1101.     {
  1102.         while(SDL_PollEvent(&e)!=0)
  1103.         {
  1104.             if(e.type==SDL_QUIT)
  1105.                 return 0;
  1106.             else if(e.type== SDL_MOUSEBUTTONDOWN)
  1107.             {
  1108.                 int x, y;
  1109.                 SDL_GetMouseState( &x, &y );
  1110.  
  1111.                 if(x>=60 && x<=260 && y>=320 && y<=520)
  1112.                     {
  1113.                         if(saved_game)
  1114.                         {
  1115.                             int display1 = load_from_file();
  1116.                             if(display1==no) return level_one;
  1117.                             else
  1118.                             return display1;
  1119.                         }
  1120.                         else
  1121.                         return level_one;
  1122.                     }
  1123.                 else if(x>=1020 && x<=1220 && y>=320 && y<=520) return end;
  1124.                 else if(x>=34+320 && x<=34+320+252 && y>=320 && y<=520)
  1125.                 {
  1126.                     int display2=description_();
  1127.                     if(display2==end)
  1128.                         return end;
  1129.                     else if(display2==anything)
  1130.                         continue;
  1131.                 }
  1132.                 else if(x>=700 && x<=900 && y>=320 && y<=520)
  1133.                 {
  1134.                     int display3=high_score_display();
  1135.                     if(display3==end)
  1136.                         return end;
  1137.                     else continue;
  1138.                 }
  1139.             }
  1140.         }
  1141.  
  1142.         int x, y;
  1143.                 SDL_GetMouseState( &x, &y );
  1144.  
  1145.                 if(x>=34 && x<=34+252 && y>=320 && y<=520)
  1146.                 {
  1147.                     start_button=true;
  1148.                 }
  1149.                 else if(x>=34+320 && x<=34+320+252 && y>=320 && y<=520)
  1150.                 {
  1151.                     description_button=true;
  1152.                 }
  1153.                 else if(x>=34+(320*2) && x<=34+(320*2)+252 && y>=320 && y<=520)
  1154.                 {
  1155.                     highscore_button=true;
  1156.                 }
  1157.                 else if(x>=34+(320*3) && x<=34+(320*3)+252 && y>=320 && y<=520)
  1158.                 {
  1159.                     quit_button=true;
  1160.                 }
  1161.  
  1162.    
  1163.     SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1164.     SDL_RenderClear(game_renderer);
  1165.    
  1166.     backgrounds[bouncee].render(0,0);
  1167.     backgrounds[originalback].render(0, 0);
  1168.     if(start_button) backgrounds[rstart].render(34, 320);
  1169.     else
  1170.     backgrounds[start].render(34, 320);
  1171.     if(description_button) backgrounds[rinstructions].render(34+320, 320);
  1172.     else
  1173.     backgrounds[instructions].render(34+320, 320);
  1174.     if(highscore_button) backgrounds[rhighscore].render(34+(320*2), 320);
  1175.     else
  1176.     backgrounds[highscore_e].render(34+(320*2), 320);
  1177.     if(quit_button) backgrounds[rquit].render(34+(320*3), 320);
  1178.     else
  1179.     backgrounds[quitbutton].render(34+(320*3), 320);
  1180.  
  1181.     SDL_RenderPresent(game_renderer);
  1182.  
  1183.     start_button=false; quit_button=false; description_button = false; highscore_button=false;
  1184.  
  1185.     }
  1186.         /*
  1187.         four options: start , instructions, high score, quit
  1188.         start returns 1
  1189.         quit returns 0
  1190.         instructions renders an image with instructions
  1191.         high score displays a list with three names/only the high score
  1192.         */
  1193.     return success;
  1194. }
  1195.  
  1196.  
  1197. void set_death(int i[], int j[])
  1198. {
  1199.     srand(SDL_GetTicks());
  1200.     for(int k=0; k<=death.number_of; k++)
  1201.     {
  1202.  
  1203.         i[k]=rand();
  1204.         i[k]%=1200;
  1205.         j[k]=rand();
  1206.         j[k]%=500;
  1207.     }
  1208. }
  1209. void score_calc()
  1210. {
  1211.     score=0;
  1212.     for(int i=0; i<=dots.number_of-1; i++)
  1213.     {
  1214.         if(dots.id[i]==0)
  1215.         {
  1216.             score+=2500;
  1217.         }
  1218.     }
  1219.     if(prevscore!=0) score+=prevscore;
  1220.     score-=((cnt*811)+(((tick*(tick+1))/2)*11));
  1221. }
  1222.  
  1223. void time_func()
  1224. {
  1225.     tick2=SDL_GetTicks();
  1226.     tick = initialTime + ( ( tick2 - tick1 ) / 1000 );
  1227.     sprintf(times, "TIME: %ds", tick);
  1228.     SDL_Color c={2, 36, 37};
  1229.     backgrounds[ticks].loadFromRenderedText(times, c);
  1230.     backgrounds[ticks].render(screen_width/2 -50, 630);
  1231. }
  1232. void clear_file()
  1233. {
  1234.     FILE *p=fopen("game_save_info.txt", "w");
  1235.     fprintf(p, "%d\n", 0);
  1236.     fclose(p);
  1237.     return ;
  1238. }
  1239.  
  1240. int level1()
  1241. {  
  1242.  
  1243.     tick1=SDL_GetTicks();
  1244.     SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1245.     SDL_RenderClear(game_renderer);
  1246.     bool back_button=false;
  1247.     int level=1, ano;
  1248.  
  1249.     level_id = level_one;
  1250.  
  1251.     if(!load_saved_game)
  1252.     {
  1253.         score=0; prevscore=0;
  1254.  
  1255.    
  1256.     dots.number_of=30;
  1257.     cnt=0;
  1258.  
  1259.     platforms.number_of=25;
  1260.     death.number_of=15;
  1261.  
  1262.         set1(a, b);
  1263.         set_death(death_x, death_y);
  1264.    
  1265.     character.posX=0;
  1266.     character.posY=580;
  1267.     character.velX=0;
  1268.     character.velY=0;
  1269.  
  1270.     memset(dots.id, -1, sizeof(dots.id));
  1271.     memset(death.id, -1, sizeof(death.id));
  1272.     }
  1273.     else load_saved_game=false;
  1274.  
  1275.     character.velX=0;
  1276.     character.velY=0;
  1277.     platforms.number_of=25;
  1278.  
  1279.     bool quit=false;
  1280.  
  1281.     SDL_Event e;
  1282.     while(!quit)
  1283.     {
  1284.         const Uint8* ks = SDL_GetKeyboardState( NULL );
  1285.         while(SDL_PollEvent(&e)!=0)
  1286.         {
  1287.  
  1288.             if(e.type==SDL_QUIT)
  1289.             {
  1290.                 quit=true;
  1291.                 return end;
  1292.             }
  1293.             else if(e.type==SDL_MOUSEBUTTONDOWN)
  1294.             {
  1295.                 int x, y;
  1296.                 SDL_GetMouseState(&x, &y);
  1297.                 if(x>20 && x<100 && y>620 && y<680)
  1298.                 {
  1299.                    
  1300.                     int save_game_response = save_game();
  1301.                     if(save_game_response==no)
  1302.                         {
  1303.                             clear_file();
  1304.                             initialTime=0;
  1305.                             score_calc();
  1306.                             return menu;
  1307.                         }
  1308.                     else if(save_game_response==end)
  1309.                     {
  1310.                         return end;
  1311.                     }
  1312.                     else
  1313.                     {
  1314.                         return menu;
  1315.                     }
  1316.                 }
  1317.             }
  1318.             else ano=event_id(level, ks, e);
  1319.         }
  1320.         int x, y;
  1321.         SDL_GetMouseState(&x, &y);
  1322.         if(x>20 && x<100 && y>620 && y<680)
  1323.             back_button=true;
  1324.  
  1325.            if(ano==end) return end;
  1326.             int count=0;
  1327.             for(int k=0; k<=death.number_of; k++)
  1328.             {
  1329.                 if(death.id[k]==0)
  1330.                     count++;
  1331.                 if(count==5)
  1332.                     {
  1333.                         clear_file();
  1334.                         score_calc();
  1335.                         initialTime=0;
  1336.                        
  1337.                         return gameover;
  1338.                     }
  1339.             }
  1340.  
  1341.             if(dots.id[30]==0)
  1342.             {
  1343.                 clear_file();
  1344.                 score_calc();
  1345.                 initialTime=0;
  1346.                
  1347.                 return nextlevel;
  1348.             }
  1349.  
  1350.             SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1351.             SDL_RenderClear(game_renderer);
  1352.  
  1353.             backgrounds[background].render(0, 0);
  1354.  
  1355.             build_level1();
  1356.                
  1357.             character.render();
  1358.             if(back_button) backgrounds[rback].render(20, 630);
  1359.             else
  1360.             backgrounds[back].render(20, 630);
  1361.             time_func();
  1362.             score_box();
  1363.            
  1364.             if(cnt!=0) green();
  1365.            
  1366.  
  1367.             SDL_RenderPresent(game_renderer);
  1368.             back_button=false;
  1369.        
  1370.     }
  1371. }
  1372.  
  1373. void rect(SDL_Rect ground[], int index, int x, int y, int w, int h, int i, int j, int k, int show_flag)
  1374. {
  1375.     if(show_flag){
  1376.         ground[index]={x, y, w, h};
  1377.         SDL_SetRenderDrawColor(game_renderer, i , j , k , 255);
  1378.         SDL_RenderFillRect(game_renderer, &ground[index]);
  1379.     }
  1380.  
  1381. }
  1382. void set1(int a[], int b[])
  1383. {
  1384.     srand(SDL_GetTicks());
  1385.     for(int i=0; i<=dots.number_of-1; i++)
  1386.         {
  1387.             a[i]=rand();
  1388.             a[i]%=1270;
  1389.             b[i]=rand();
  1390.             b[i]%=570;
  1391.         }
  1392. }
  1393.  
  1394. void build_level1()
  1395. {
  1396.      
  1397.  
  1398.  
  1399.         a[30]=1270; b[30]=150;
  1400.  
  1401.         int c[50], d[50];
  1402.  
  1403.         c[0]=170; d[0]=580;
  1404.         c[1]=190; d[1]=480;
  1405.         c[2]=300; d[2]=500;
  1406.         c[3]=500; d[3]=540;
  1407.         c[4]=640; d[4]=510;
  1408.         c[5]=780; d[5]=490;
  1409.         c[6]=900; d[6]=530;
  1410.         c[7]=1180; d[7]=490;
  1411.         c[8]=220; d[8]=410;
  1412.         c[9]=20; d[9]=220;
  1413.         c[10]=150; d[10]=300;
  1414.         c[11]=780; d[11]=350;
  1415.         c[12]=0; d[12]=410;
  1416.         c[13]=800; d[13]=150;
  1417.         c[14]=1230; d[14]=430;
  1418.         c[15]=1020; d[15]=350;
  1419.         c[16]=690; d[16]=400;
  1420.         c[17]=910; d[17]=160;
  1421.         c[18]=480; d[18]=220;
  1422.         c[19]=1100; d[19]=50;
  1423.         c[20]=440; d[20]=340;
  1424.         c[21]=900; d[21]=250;
  1425.         c[22]=700; d[22]=250;
  1426.         c[23]=210; d[23]=150;
  1427.         c[24]=580; d[24]=50;
  1428.         c[25]=0; d[25]=600;
  1429.  
  1430.         for(int k=0; k<=dots.number_of-1; k++)
  1431.         {
  1432.             for(int m=0; m<platforms.number_of; m++)
  1433.             {
  1434.                 if(a[k]>(c[m]-20) && a[k]<(c[m]+80) && b[k]>(d[m]-20) && b[k]<(d[m]+5))
  1435.                     {
  1436.                         b[k]-=20;
  1437.                     }
  1438.             }
  1439.         }
  1440.  
  1441.         for(int k=0; k<=death.number_of; k++)
  1442.         {
  1443.             for(int m=0; m<platforms.number_of; m++)
  1444.             {
  1445.                 if(death_x[k]>(c[m]-20) && death_x[k]<(c[m]+80) && death_y[k]>(d[m]-20) && death_y[k]<(d[m]+5))
  1446.                     {
  1447.                         death_y[k]-=20;
  1448.                     }
  1449.             }
  1450.         }
  1451.        
  1452.         int i;
  1453.         for(i=0; i<=dots.number_of-1; i++)
  1454.         {
  1455.             rect(dots.a, i, a[i], b[i], 20, 20, 255, 106, 128, dots.id[i]);
  1456.             if(dots.id[i])backgrounds[point].render(a[i], b[i]);
  1457.         }
  1458.  
  1459.         rect(dots.a, i, a[i], b[i], 10, 20, 68, 85, 90, dots.id[i]);
  1460.  
  1461.         for(i=0; i<=24; i++)
  1462.         {
  1463.             rect(platforms.a, i, c[i], d[i], 50, 5, 175, 175, 175, 1);
  1464.         }
  1465.         rect(platforms.a, i, c[i], d[i], screen_width, 80, 2, 36, 47, 1);
  1466.         rect(platforms.a, i+1, 0, 625, screen_width, 680-625, 175, 175, 199,  1);
  1467.  
  1468.         for(i=0; i<=death.number_of; i++)
  1469.         {
  1470.             rect(death.a, i, death_x[i], death_y[i], 20, 20, 100, 255, 50, death.id[i]);
  1471.             if(death.id[i])backgrounds[bomb].render(death_x[i], death_y[i]);
  1472.            
  1473.         }
  1474. }
  1475. int game_over()
  1476. {
  1477.     bool menu_button=false;
  1478.  
  1479.  
  1480.     bool quit=false;
  1481.     SDL_Event e;
  1482.  
  1483.     while(!quit)
  1484.     {
  1485.         while(SDL_PollEvent(&e)!=0)
  1486.         {
  1487.             if(e.type==SDL_QUIT)
  1488.                 return end;
  1489.             if(e.type== SDL_MOUSEBUTTONDOWN)
  1490.             {
  1491.                 int x, y;
  1492.                 SDL_GetMouseState(&x, &y);
  1493.  
  1494.                 if(x>700 && x<(700+200) && y>270 && y<470)
  1495.                     return menu;
  1496.             }
  1497.         }
  1498.  
  1499.         int x, y;
  1500.                 SDL_GetMouseState(&x, &y);
  1501.                 if(x>700 && x<(700+200) && y>270 && y<470)
  1502.                 {
  1503.                     menu_button=true;
  1504.                 }
  1505.  
  1506.         SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1507.     SDL_RenderClear(game_renderer);
  1508.  
  1509.     backgrounds[background].render(0, 0);
  1510.     backgrounds[gameover].render(380, 270);
  1511.     if(menu_button) backgrounds[rmenu].render(700, 270);
  1512.     else
  1513.     backgrounds[menu].render(700, 270);
  1514.  
  1515.     SDL_RenderPresent(game_renderer);
  1516.     menu_button=false; 
  1517.     }
  1518.  
  1519. }
  1520. void build_level2()
  1521. {
  1522.         a[dots.number_of]=1270; b[dots.number_of]=150;
  1523.  
  1524.         int c[500], d[500];
  1525.  
  1526.         c[0]=0; d[0]=340;
  1527.         c[1]=60; d[1]=280;
  1528.         c[2]=120; d[2]=220;
  1529.         c[3]=180; d[3]=160;
  1530.         c[4]=240; d[4]=100;
  1531.         c[5]=360; d[5]=100;
  1532.  
  1533.         c[6]=420; d[6]=160;
  1534.         c[7]=480; d[7]=220;
  1535.         c[8]=540; d[8]=280;
  1536.         c[9]=600; d[9]=340;
  1537.         c[10]=660; d[10]=400;
  1538.         c[11]=720; d[11]=460;
  1539.  
  1540.         c[12]=780; d[12]=520;
  1541.         c[13]=840; d[13]=580;
  1542.         c[14]=970; d[14]=580;
  1543.         c[15]=1030; d[15]=520;
  1544.         c[16]=1090; d[16]=460;
  1545.         c[17]=1150; d[17]=400;
  1546.         c[18]=1210; d[18]=340;
  1547.  
  1548.         c[19]=60; d[19]=400;
  1549.         c[20]=120; d[20]=460;
  1550.         c[21]=180; d[21]=520;
  1551.         c[22]=240; d[22]=580;
  1552.         c[23]=360; d[23]=580;
  1553.         c[24]=420; d[24]=520;
  1554.         c[25]=480; d[25]=460;
  1555.         c[26]=540; d[26]=400;
  1556.         c[27]=600; d[27]=340;
  1557.         c[28]=660; d[28]=280;
  1558.         c[29]=720; d[29]=220;
  1559.  
  1560.         c[30]=780; d[30]=160;
  1561.         c[31]=840; d[31]=100;
  1562.         c[32]=970; d[32]=100;
  1563.         c[33]=1030; d[33]=160;
  1564.         c[34]=1090; d[34]=220;
  1565.         c[35]=1150; d[35]=280;
  1566.         c[36]=1210; d[36]=340;
  1567.  
  1568.         c[37]=0; d[37]=620;
  1569.         c[38]=0; d[38]=600;
  1570.  
  1571.         for(int k=0; k<=dots.number_of-1; k++)
  1572.         {
  1573.             for(int m=0; m<platforms.number_of; m++)
  1574.             {
  1575.                 if(a[k]>(c[m]-20) && a[k]<(c[m]+80) && b[k]>(d[m]-20) && b[k]<(d[m]+5))
  1576.                     {
  1577.                         b[k]-=20;
  1578.                     }
  1579.             }
  1580.         }
  1581.  
  1582.         for(int k=0; k<=death.number_of; k++)
  1583.         {
  1584.             for(int m=0; m<platforms.number_of; m++)
  1585.             {
  1586.                 if(death_x[k]>(c[m]-20) && death_x[k]<(c[m]+80) && death_y[k]>(d[m]-20) && death_y[k]<(d[m]+5))
  1587.                     {
  1588.                         death_y[k]-=20;
  1589.                     }
  1590.             }
  1591.         }
  1592.  
  1593.         int i;
  1594.         for(i=0; i<dots.number_of; i++)
  1595.         {
  1596.             rect(dots.a, i, a[i], b[i], 20, 20, 255, 106, 128, dots.id[i]);
  1597.             if(dots.id[i]) backgrounds[point].render(a[i], b[i]);
  1598.  
  1599.         }
  1600.  
  1601.         rect(dots.a, i, a[i], b[i], 10, 20, 68, 85, 90, dots.id[i]);
  1602.         //rect(dots.a, i+1, a[i+1], b[i+1], screen_width, 40, 21, 244, 238, dots.id[i+1]);
  1603.  
  1604.         for(i=0; i<platforms.number_of; i++)
  1605.         {
  1606.             rect(platforms.a, i, c[i], d[i], 80, 5, 175, 175, 175, 1);
  1607.         }
  1608.         rect(platforms.a, i, c[i], d[i], screen_width, 80, 175, 175, 175, 1);
  1609.         rect(platforms.a, i, c[i+1], d[i+1], screen_width, 20, 0xa1, 0x24, 0x24, 1);
  1610.         for(i=0; i<=death.number_of; i++)
  1611.         {
  1612.             rect(death.a, i, death_x[i], death_y[i], 10, 10, 100, 255, 50, death.id[i]);
  1613.             if(death.id[i])backgrounds[bomb].render(death_x[i], death_y[i]);
  1614.         }
  1615. }
  1616.  
  1617. int level2()
  1618. {
  1619.     tick1=SDL_GetTicks();
  1620.  
  1621.     bool back_button = false;
  1622.     level_id=level_two;
  1623.  
  1624.     int level=2, ano;
  1625.    
  1626.     if(!load_saved_game)
  1627.     {
  1628.     cnt=0; prevscore=score;
  1629.     dots.number_of=35;
  1630.     platforms.number_of=37;
  1631.     death.number_of=17;
  1632.  
  1633.     set1(a, b);
  1634.     set_death(death_x, death_y);
  1635.  
  1636.     character.posX=0;
  1637.     character.posY=320;
  1638.     character.velX=0;
  1639.     character.velY=0;
  1640.  
  1641.     memset(dots.id, -1, sizeof(dots.id));
  1642.     memset(death.id, -1, sizeof(death.id));
  1643.     }
  1644.     else load_saved_game=false;
  1645.  
  1646.     character.velX=0;
  1647.     character.velY=0;
  1648.     platforms.number_of=37;
  1649.  
  1650.  
  1651.     bool quit=false;
  1652.  
  1653.     SDL_Event e;
  1654.     while(!quit)
  1655.     {
  1656.         const Uint8* ks = SDL_GetKeyboardState( NULL );
  1657.         while(SDL_PollEvent(&e)!=0)
  1658.         {
  1659.  
  1660.             if(e.type==SDL_QUIT)
  1661.             {
  1662.                 quit=true;
  1663.                 return end;
  1664.             }
  1665.             else if(e.type==SDL_MOUSEBUTTONDOWN)
  1666.             {
  1667.                 int x, y;
  1668.                 SDL_GetMouseState(&x, &y);
  1669.                 if(x>20 && x<100 && y>620 && y<680)
  1670.                 {
  1671.  
  1672.                     int save_game_response = save_game();
  1673.                     if(save_game_response==no)
  1674.                         {
  1675.                             clear_file();
  1676.                             score_calc();
  1677.                             initialTime=0;
  1678.                             return menu;
  1679.                         }
  1680.                     else if(save_game_response==end)
  1681.                     {
  1682.                         return end;
  1683.                     }
  1684.                     else
  1685.                     {
  1686.                         return menu;
  1687.                     }
  1688.                 }
  1689.             }
  1690.             else ano=event_id(level, ks, e);
  1691.         }
  1692.         int x, y;
  1693.         SDL_GetMouseState(&x, &y);
  1694.         if(x>20 && x<100 && y>620 && y<680)
  1695.             back_button=true;
  1696.             if(ano==end)
  1697.                 return end;
  1698.             int count=0;
  1699.  
  1700.             for(int k=0; k<=death.number_of; k++)
  1701.             {
  1702.                 if(death.id[k]==0)
  1703.                     count++;
  1704.                 if(count==5)
  1705.                     {
  1706.                         score_calc();
  1707.                         initialTime=0;
  1708.                         clear_file();
  1709.                         return gameover;
  1710.                     }
  1711.             }
  1712.  
  1713.             if(dots.id[dots.number_of]==0)
  1714.             {
  1715.                 score_calc();
  1716.                 initialTime=0;
  1717.                 clear_file();
  1718.                
  1719.                 return nextlevel;
  1720.             }
  1721.             if(level==2 && character.posY>=580)
  1722.                 {
  1723.                     score_calc();
  1724.                     initialTime=0;
  1725.                     clear_file();
  1726.  
  1727.                    
  1728.                     return gameover;
  1729.                 }
  1730.             SDL_RenderClear(game_renderer);
  1731.             backgrounds[background].render(0, 0);
  1732.             build_level2();
  1733.            
  1734.             character.render();
  1735.             if(back_button) backgrounds[rback].render(20, 630);
  1736.             else
  1737.             backgrounds[back].render(20, 630);
  1738.             time_func();
  1739.             score_box();
  1740.            
  1741.             if(cnt!=0) green();
  1742.             SDL_RenderPresent(game_renderer);
  1743.         back_button=false;
  1744.     }
  1745. }
  1746. int next_level()
  1747. {
  1748.     bool next_level_button=false, menu_button=false;
  1749.    
  1750.  
  1751.     bool quit=false;
  1752.     SDL_Event e;
  1753.  
  1754.     while(!quit)
  1755.     {
  1756.         while(SDL_PollEvent(&e)!=0)
  1757.         {
  1758.             if(e.type==SDL_QUIT)
  1759.                 return end;
  1760.             if(e.type== SDL_MOUSEBUTTONDOWN)
  1761.             {
  1762.                 int x, y;
  1763.                 SDL_GetMouseState(&x, &y);
  1764.  
  1765.                 if(x>700 && x<(700+200) && y>270 && y<470)
  1766.                     return menu;
  1767.                 if(x>380 && x<(580) && y>270 && y<470)
  1768.                     return nextlevel;
  1769.             }
  1770.         }
  1771.  
  1772.         int x, y;
  1773.                 SDL_GetMouseState(&x, &y);
  1774.                 if(x>700 && x<(700+200) && y>270 && y<470)
  1775.                 {
  1776.                     menu_button=true;
  1777.                 }
  1778.                 else if(x>380 && x<(580) && y>270 && y<470)
  1779.                 {
  1780.                     next_level_button=true;
  1781.                 }
  1782.  
  1783.         SDL_SetRenderDrawColor(game_renderer, 255, 255, 255, 255);
  1784.     SDL_RenderClear(game_renderer);
  1785.     backgrounds[background].render(0, 0);
  1786.  
  1787.     if(next_level_button) backgrounds[rnextlevel].render(380, 270);
  1788.     else
  1789.     backgrounds[nextlevel].render(380, 270);
  1790.    
  1791.     if(menu_button) backgrounds[rmenu].render(700, 270);
  1792.     else
  1793.     backgrounds[menu].render(700, 270);
  1794.  
  1795.     SDL_RenderPresent(game_renderer);
  1796.  
  1797.     next_level_button=false;
  1798.     menu_button=false;
  1799.     }
  1800. }
  1801.  
  1802. void sort(score_structure a[])
  1803. {
  1804.     for(int b=1; b<=6; b++)
  1805.     {
  1806.         for(int k=1; k<6-b+1; k++)
  1807.         {
  1808.             if(a[k].i<a[k+1].i)
  1809.             {
  1810.                 score_structure temp=a[k];
  1811.                 a[k]=a[k+1];
  1812.                 a[k+1]=temp;
  1813.             }
  1814.         }
  1815.     }
  1816. }
  1817.  
  1818. int input_name(score_structure sc[], int k)
  1819. {
  1820.     bool quit = false;
  1821.  
  1822.             //Event handler
  1823.             SDL_Event e;
  1824.  
  1825.             //Set text color as black
  1826.             SDL_Color textColor = { 255, 255, 255, 0xFF };
  1827.  
  1828.             //The current input text.
  1829.             std::string inputText = "Anonymous";
  1830.             backgrounds[input].loadFromRenderedText( inputText.c_str(), textColor );
  1831.             backgrounds[text].loadFromRenderedText("NEW HIGH SCORE ! ENTER NAME : ", textColor);
  1832.  
  1833.             //Enable text input
  1834.             SDL_StartTextInput();
  1835.  
  1836.             //While application is running
  1837.             while( !quit )
  1838.             {
  1839.                 //The rerender text flag
  1840.                 bool renderText = false;
  1841.  
  1842.                 //Handle events on queue
  1843.                 while( SDL_PollEvent( &e ) != 0 )
  1844.                 {
  1845.                     //User requests quit
  1846.                     if( e.type == SDL_QUIT )
  1847.                     {
  1848.                         quit = true;
  1849.                         return end;
  1850.                     }
  1851.                     //Special key input
  1852.                     else if( e.type == SDL_KEYDOWN )
  1853.                     {
  1854.                         //Handle backspace
  1855.                         if( e.key.keysym.sym == SDLK_BACKSPACE && inputText.length() > 0 )
  1856.                         {
  1857.                             //lop off character
  1858.                             inputText.pop_back();
  1859.                             renderText = true;
  1860.                         }
  1861.                         //Handle copy
  1862.                         else if( e.key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL )
  1863.                         {
  1864.                             SDL_SetClipboardText( inputText.c_str() );
  1865.                         }
  1866.                         //Handle paste
  1867.                         else if( e.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL )
  1868.                         {
  1869.                             inputText = SDL_GetClipboardText();
  1870.                             renderText = true;
  1871.                         }
  1872.                         else if(e.key.keysym.sym==SDLK_RETURN)
  1873.                         {
  1874.                             SDL_StopTextInput();
  1875.                             strcpy(sc[k].a, inputText.c_str());
  1876.                             return anything;
  1877.                         }
  1878.                     }
  1879.                     //Special text input event
  1880.                     else if( e.type == SDL_TEXTINPUT )
  1881.                     {
  1882.                         //Not copy or pasting
  1883.                         if( !( SDL_GetModState() & KMOD_CTRL && ( e.text.text[ 0 ] == 'c' || e.text.text[ 0 ] == 'C' || e.text.text[ 0 ] == 'v' || e.text.text[ 0 ] == 'V' ) ) )
  1884.                         {
  1885.                             //Append character
  1886.                             inputText += e.text.text;
  1887.                             renderText = true;
  1888.                         }
  1889.                     }
  1890.                 }
  1891.  
  1892.                 //Rerender text if needed
  1893.                 if( renderText )
  1894.                 {
  1895.                     //Text is not empty
  1896.                     if( inputText != "" )
  1897.                     {
  1898.                         //Render new text
  1899.                         backgrounds[input].loadFromRenderedText( inputText.c_str(), textColor );
  1900.                     }
  1901.                     //Text is empty
  1902.                     else
  1903.                     {
  1904.                         //Render space texture
  1905.                         backgrounds[input].loadFromRenderedText( " ", textColor );
  1906.                     }
  1907.                 }
  1908.  
  1909.                 //Clear screen
  1910.                 SDL_SetRenderDrawColor( game_renderer, 0xFF, 0xFF, 0xFF, 0xFF );
  1911.                 SDL_RenderClear(game_renderer );
  1912.  
  1913.                 //Render text textures
  1914.                 backgrounds[background].render(0, 0);
  1915.                 backgrounds[text].render( ( screen_width - backgrounds[text].getWidth() ) / 2, 100 );
  1916.                 backgrounds[input].render( ( screen_width - backgrounds[input].getWidth() ) / 2, 200 );
  1917.  
  1918.                 //Update screen
  1919.                 SDL_RenderPresent( game_renderer);
  1920.             }
  1921.            
  1922. }
  1923.  
  1924.  
  1925. int score_display()
  1926. {
  1927.         char dis[1000], temp[100];
  1928.         score_structure sc[10];
  1929.         SDL_Color textColor;
  1930.         int k;
  1931.     FILE *p=fopen("score.txt", "r");
  1932.     for(k=1; k<=5; k++)
  1933.     {
  1934.         fscanf(p, "%d %s", &sc[k].i, sc[k].a);
  1935.     }
  1936.     sc[k].i=score; strcpy(sc[k].a, "aiosd");
  1937.  
  1938.     sort(sc);
  1939.     for(k=1; k<=5; k++)
  1940.     {
  1941.         if(sc[k].i==score)
  1942.         {
  1943.             int ret=input_name(sc, k);
  1944.             if(ret==end) return end;
  1945.            
  1946.             sprintf(dis, "NEW HIGH SCORE : %d", score);
  1947.             break;
  1948.         }
  1949.     }
  1950.     p=fopen("score.txt", "w");
  1951.     for(k=1; k<=5; k++){
  1952.             fprintf(p, "%d %s\n", sc[k].i, sc[k].a);
  1953.  
  1954.         }
  1955.     fclose(p);
  1956.     if(score>=0 && k>5)
  1957.     {
  1958.             sprintf(dis, "SCORE : %d", score);
  1959.     }
  1960.     else if(score<0)
  1961.     {
  1962.         SDL_Color textColor={0xa1, 0x24, 0x24};
  1963.         sprintf(dis, "SCORE : %d EPIC FAILURE", score);
  1964.     }  
  1965.  
  1966.     if(score>=0) textColor={255, 255, 255};
  1967.  
  1968.  
  1969.     bool quit=false;
  1970.     SDL_Event e;
  1971.     while(!quit)
  1972.     {
  1973.         while(SDL_PollEvent(&e)!=0)
  1974.         {
  1975.             if(e.type==SDL_QUIT)
  1976.             {
  1977.                 quit=true;
  1978.                 return end;
  1979.             }
  1980.             if(e.type==SDL_KEYDOWN)
  1981.             {
  1982.                 if(e.key.keysym.sym==SDLK_RETURN)
  1983.                 {
  1984.                     quit=true;
  1985.                     return menu;
  1986.                 }
  1987.             }
  1988.         }
  1989.         SDL_SetRenderDrawColor(game_renderer, 0, 255, 237, 255);
  1990.         SDL_RenderClear(game_renderer);
  1991.         backgrounds[score__].render(0, 0);
  1992.         backgrounds[Score].loadFromRenderedText(dis, textColor);
  1993.         backgrounds[Score].render(screen_width/4, screen_height/4);
  1994.  
  1995.         SDL_RenderPresent(game_renderer);
  1996.     }
  1997. }
  1998. void score_box()
  1999. {
  2000.     score_calc();
  2001.     char s[100];
  2002.     sprintf(s, "SCORE:%d", score);
  2003.     SDL_Color c={2, 36, 37};
  2004.     backgrounds[box].loadFromRenderedText(s, c);
  2005.     backgrounds[box].render(200, 630);
  2006. }
  2007. void build_level3()
  2008. {
  2009.     a[dots.number_of]=1270; b[dots.number_of]=150;
  2010.  
  2011.         int c[500], d[500];
  2012.  
  2013.         for(int k=0; k<platforms.number_of; k++)
  2014.         {
  2015.             if(k%2==0) c[k]=0;
  2016.             else c[k]=screen_width/2 + 60;
  2017.         }
  2018.         int h=70; int k;
  2019.         for(k=0; k<platforms.number_of-1; k++)
  2020.         {
  2021.             if(k==0) d[k]=h;
  2022.             else {
  2023.                 d[k]=h+d[k-1];
  2024.             }
  2025.         }
  2026.         c[k]=0; d[k]=600;
  2027.         c[k+1]=0; d[k+1]=620;
  2028.         for(k=0; k<platforms.number_of-1; k++)
  2029.         {
  2030.             rect(platforms.a, k, c[k], d[k], screen_width/2, 5, 175, 175 ,175, 1);
  2031.         }
  2032.         rect(platforms.a, k, c[k], d[k], screen_width, 20, 0xa1, 0x24, 0x24, 1);
  2033.         rect(platforms.a, k+1, c[k+1], d[k+1], screen_width, 60, 175, 175, 175, 1 );
  2034.  
  2035.         for( k=0; k<=dots.number_of-1; k++)
  2036.         {
  2037.             for(int m=0; m<platforms.number_of; m++)
  2038.             {
  2039.                 if(a[k]>(c[m]-20) && a[k]<(c[m]+80) && b[k]>(d[m]-20) && b[k]<(d[m]+5))
  2040.                     {
  2041.                         b[k]-=20;
  2042.                     }
  2043.             }
  2044.         }
  2045.  
  2046.         for( k=0; k<=death.number_of; k++)
  2047.         {
  2048.             for(int m=0; m<platforms.number_of; m++)
  2049.             {
  2050.                 if(death_x[k]>(c[m]-20) && death_x[k]<(c[m]+80) && death_y[k]>(d[m]-20) && death_y[k]<(d[m]+5))
  2051.                     {
  2052.                         death_y[k]-=20;
  2053.                     }
  2054.             }
  2055.         }
  2056.         int i;
  2057.         for(i=0; i<=death.number_of; i++)
  2058.         {
  2059.             rect(death.a, i, death_x[i], death_y[i], 10, 10, 100, 255, 50, death.id[i]);
  2060.             if(death.id[i])backgrounds[bomb].render(death_x[i], death_y[i]);
  2061.         }
  2062.  
  2063.         for(i=0; i<dots.number_of; i++)
  2064.         {
  2065.             rect(dots.a, i, a[i], b[i], 20, 20, 255, 106, 128, dots.id[i]);
  2066.             if(dots.id[i]) backgrounds[point].render(a[i], b[i]);
  2067.  
  2068.         }
  2069.         rect(dots.a, i, a[i], b[i], 20, 20, 255, 106, 128, dots.id[i]);
  2070. }
  2071.  
  2072. int level3()
  2073. {
  2074.     tick1=SDL_GetTicks();
  2075.  
  2076.     bool back_button = false;
  2077.     level_id=level_two;
  2078.  
  2079.     int level=3, ano;
  2080.    
  2081.     if(!load_saved_game)
  2082.     {
  2083.     cnt=0; prevscore=score;
  2084.     dots.number_of=35;
  2085.     platforms.number_of=10;
  2086.     death.number_of=17;
  2087.  
  2088.     set1(a, b);
  2089.     set_death(death_x, death_y);
  2090.  
  2091.     character.posX=1250;
  2092.     character.posY=520;
  2093.     character.velX=0;
  2094.     character.velY=0;
  2095.  
  2096.     memset(dots.id, -1, sizeof(dots.id));
  2097.     memset(death.id, -1, sizeof(death.id));
  2098.     }
  2099.     else load_saved_game=false;
  2100.  
  2101.     character.velX=0;
  2102.     character.velY=0;
  2103.     platforms.number_of=10;
  2104.  
  2105.  
  2106.     bool quit=false;
  2107.  
  2108.     SDL_Event e;
  2109.     while(!quit)
  2110.     {
  2111.         const Uint8* ks = SDL_GetKeyboardState( NULL );
  2112.         while(SDL_PollEvent(&e)!=0)
  2113.         {
  2114.  
  2115.             if(e.type==SDL_QUIT)
  2116.             {
  2117.                 quit=true;
  2118.                 return end;
  2119.             }
  2120.             else if(e.type==SDL_MOUSEBUTTONDOWN)
  2121.             {
  2122.                 int x, y;
  2123.                 SDL_GetMouseState(&x, &y);
  2124.                 if(x>20 && x<100 && y>620 && y<680)
  2125.                 {
  2126.  
  2127.                     int save_game_response = save_game();
  2128.                     if(save_game_response==no)
  2129.                         {
  2130.                             clear_file();
  2131.                             score_calc();
  2132.                             initialTime=0;
  2133.                             return menu;
  2134.                         }
  2135.                     else if(save_game_response==end)
  2136.                     {
  2137.                         return end;
  2138.                     }
  2139.                     else
  2140.                     {
  2141.                         return menu;
  2142.                     }
  2143.                 }
  2144.             }
  2145.             else ano=event_id(level, ks, e);
  2146.         }
  2147.         int x, y;
  2148.         SDL_GetMouseState(&x, &y);
  2149.         if(x>20 && x<100 && y>620 && y<680)
  2150.             back_button=true;
  2151.             if(ano == end)
  2152.                 return end;
  2153.             int count=0;
  2154.  
  2155.             for(int k=0; k<=death.number_of; k++)
  2156.             {
  2157.                 if(death.id[k]==0)
  2158.                     count++;
  2159.                 if(count==5)
  2160.                     {
  2161.                         score_calc();
  2162.                         initialTime=0;
  2163.                         clear_file();
  2164.                         return gameover;
  2165.                     }
  2166.             }
  2167.  
  2168.             if(dots.id[dots.number_of]==0)
  2169.             {
  2170.                 score_calc();
  2171.                 initialTime=0;
  2172.                 clear_file();
  2173.                
  2174.                 return nextlevel;
  2175.             }
  2176.             if(level==3 && character.posY>=580)
  2177.                 {
  2178.                     score_calc();
  2179.                     initialTime=0;
  2180.                     clear_file();
  2181.  
  2182.                    
  2183.                     return gameover;
  2184.                 }
  2185.             SDL_RenderClear(game_renderer);
  2186.             backgrounds[background].render(0, 0);
  2187.             build_level3();
  2188.            
  2189.             character.render();
  2190.             if(back_button) backgrounds[rback].render(20, 630);
  2191.             else
  2192.             backgrounds[back].render(20, 630);
  2193.             time_func();
  2194.             score_box();
  2195.            
  2196.             if(cnt!=0) green();
  2197.             SDL_RenderPresent(game_renderer);
  2198.         back_button=false;
  2199.     }
  2200. }
  2201.  
  2202.  
  2203. int main(int argc, char* args[])
  2204. {
  2205.  
  2206.     int indicator=1;
  2207.     int levelUpVar=menu;
  2208.     if(init())
  2209.     {
  2210.         if(loadMedia())
  2211.         {
  2212.             while(levelUpVar)
  2213.             {
  2214.                 if(levelUpVar==menu)
  2215.                 {
  2216.                     score=0; prevscore=0;
  2217.                     levelUpVar=Menu();
  2218.                 }
  2219.                 if(levelUpVar==level_one)
  2220.                 {
  2221.                     levelUpVar=level1();
  2222.  
  2223.                     if(levelUpVar!=end && levelUpVar!=nextlevel) indicator=score_display();
  2224.                     if(indicator==end) levelUpVar=end;
  2225.  
  2226.                     if(levelUpVar==gameover)
  2227.                     {
  2228.                         cnt=0;
  2229.                         levelUpVar=game_over();
  2230.                     }
  2231.                     else if(levelUpVar==nextlevel)
  2232.                     {
  2233.                        
  2234.                         levelUpVar=next_level();
  2235.                         if(levelUpVar==menu)
  2236.                             levelUpVar=score_display();
  2237.                         if(levelUpVar==nextlevel)
  2238.                         {
  2239.                             levelUpVar=level_two;
  2240.                         }
  2241.                     }
  2242.                 }
  2243.                 if(levelUpVar==level_two)
  2244.                 {
  2245.                     levelUpVar=level2();
  2246.  
  2247.                     if(levelUpVar!=end && levelUpVar!=nextlevel) indicator=score_display();
  2248.                     if(indicator==end) levelUpVar=end;
  2249.  
  2250.                     if(levelUpVar==gameover)
  2251.                     {
  2252.                         levelUpVar=game_over();
  2253.                     }
  2254.                     else if(levelUpVar==nextlevel)
  2255.                     {
  2256.                         levelUpVar=next_level();
  2257.                         if(levelUpVar==menu)
  2258.                             levelUpVar=score_display();
  2259.                         if(levelUpVar==nextlevel)
  2260.                         {
  2261.                             levelUpVar=level_three;
  2262.                         }
  2263.                     }
  2264.                 }
  2265.                 if(levelUpVar==level_three)
  2266.                 {
  2267.                     levelUpVar=level3();
  2268.  
  2269.                     if(levelUpVar!=end) indicator=score_display();
  2270.                     if(indicator==end) levelUpVar=end;
  2271.  
  2272.                     if(levelUpVar==gameover)
  2273.                     {
  2274.                         levelUpVar=game_over();
  2275.                     }
  2276.                     else if(levelUpVar==nextlevel)
  2277.                     {
  2278.                         levelUpVar=next_level();
  2279.                         if(levelUpVar==menu)
  2280.                             levelUpVar=score_display();
  2281.                         if(levelUpVar==nextlevel)
  2282.                         {
  2283.                             levelUpVar=menu;
  2284.                         }
  2285.                     }
  2286.                 }
  2287.                 if(levelUpVar==end)
  2288.                 {
  2289.                     levelUpVar=0;
  2290.                 }
  2291.                
  2292.  
  2293.             }
  2294.         }
  2295.     }
  2296.     closes();
  2297.     return 0;
  2298. }
  2299.  
  2300. /*
  2301. (prototypes)
  2302. texture class
  2303. init
  2304. close
  2305. loadfromfile
  2306. ttf
  2307. free
  2308. render
  2309. getwidth
  2310. getheight
  2311. dummy class
  2312. init
  2313. move()
  2314. render()
  2315. init(SDL)
  2316. loadMedia
  2317. closes()
  2318. menu()
  2319. dummy: handle
  2320. level1
  2321. rect
  2322. build_level1
  2323. main
  2324. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement