Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.44 KB | None | 0 0
  1. /*
  2. ** EPITECH PROJECT, 2019
  3. ** guitarhero
  4. ** File description:
  5. ** main
  6. */
  7.  
  8. #include <unistd.h>
  9. #include <iostream>
  10. #include <algorithm>
  11. #include "SDLDisplay.hpp"
  12. #include "Input.hpp"
  13. #include "Colors.hpp"
  14. #include "RNG.hpp"
  15.  
  16. bool RNG::_initialized = false;
  17.  
  18. typedef struct barre_s barre_t;
  19.  
  20. struct barre_s{
  21.   const int w = 150;
  22.   const int h = 150;
  23.   const int y = 750;
  24. };
  25.  
  26. typedef struct note_s note_t;
  27.  
  28. struct note_s{
  29.   const int w = 10;
  30.   const int h = 10;
  31.   int x = 0;
  32.   double v = 1.0;
  33.   int couleur = 0;
  34.   bool i = false;
  35. };
  36.  
  37. void afficher_note(int colonne, int &y, int largeur, int longueur, int vitesse_descente, SDLDisplay &display);
  38. void afficher_barre(barre_t selectionBarre, SDLDisplay &display);
  39. void afficher_vie(int vie, SDLDisplay &display);
  40. void afficher_lettres(SDLDisplay &display);
  41.  
  42. int     main()
  43. {
  44.   SDLDisplay    display("minijeu", 1000, 900);
  45.   Input     input;
  46.  
  47.   // Les déclarations de variables se font ici
  48.  
  49.   bool continuer = false;
  50.   int random = 0;
  51.   int vie = 10;
  52.   int score = 0;
  53.   double tempsEcart = 2000;
  54.   double lastTime = SDL_GetTicks();
  55.   double lastTimeNote_1 = SDL_GetTicks();
  56.   double lastTimeNote_2 = SDL_GetTicks();
  57.   double lastTimeNote_3 = SDL_GetTicks();
  58.   double lastTimeNote_4 = SDL_GetTicks();
  59.   double lastTimeNote_5 = SDL_GetTicks();
  60.   double lastTimeNote_6 = SDL_GetTicks();
  61.   barre_t selectionBarre;
  62.   note_t note_1;
  63.   note_t note_2;
  64.   note_t note_3;
  65.   note_t note_4;
  66.   note_t note_5;
  67.   note_t note_6;
  68.  
  69.   note_2.couleur = 1;
  70.   note_3.couleur = 2;
  71.   note_4.couleur = 3;
  72.   note_5.couleur = 4;
  73.   note_6.couleur = 5;
  74.  
  75.   while(!continuer)
  76.     {
  77.  
  78.       display.clearScreen();
  79.  
  80.       display.putText("Press 'E' to start", 450, 450, Colors::Red);
  81.      
  82.       if(input.getKeyStateOnce(SDL_SCANCODE_E)){
  83.     continuer = true;
  84.       }
  85.  
  86.       display.refreshScreen();
  87.       input.flushEvents();
  88.      
  89.     }
  90.  
  91.   while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
  92.     {
  93.       display.clearScreen();
  94.       // DEBUT DU CODE
  95.  
  96.       //FAIRE APPARAITRE LA BARRE EN BAS
  97.  
  98.      
  99.       afficher_barre(selectionBarre, display);
  100.      
  101.      
  102.  
  103.       //APPARITION DES NOTES
  104.       if(SDL_GetTicks()-lastTime > 100 && (note_1.i == false && note_2.i == false && note_3.i == false && note_4.i == false && note_5.i == false && note_6.i == false)){
  105.     random = RNG::generate(6);
  106.     lastTime = SDL_GetTicks();
  107.       }
  108.  
  109.       //NOTE 1
  110.       if(random == 0){
  111.     note_1.i = true;
  112.     if(SDL_GetTicks()-lastTimeNote_1 >= tempsEcart){
  113.       afficher_note(0, note_1.x, 130, 130, note_1.v, display);
  114.     }
  115.       }
  116.  
  117.       //NOTE 2
  118.       if(random == 1){
  119.     note_2.i = true;
  120.     if(SDL_GetTicks()-lastTimeNote_2 >= tempsEcart){
  121.       afficher_note(1, note_2.x, 130, 130, note_2.v, display);
  122.     }
  123.       }
  124.  
  125.       //NOTE 3
  126.       if(random == 2){
  127.     note_3.i = true;
  128.     if(SDL_GetTicks()-lastTimeNote_3 >= tempsEcart){
  129.       afficher_note(2, note_3.x, 130, 130, note_3.v, display);
  130.     }
  131.       }
  132.  
  133.       //NOTE 4
  134.       if(random == 3){
  135.     note_4.i = true;
  136.     if(SDL_GetTicks()-lastTimeNote_4 >= tempsEcart){
  137.       afficher_note(3, note_4.x, 130, 130, note_4.v, display);
  138.     }
  139.       }
  140.  
  141.       //NOTE 5
  142.       if(random == 4){
  143.     note_5.i = true;
  144.     if(SDL_GetTicks()-lastTimeNote_5 >= tempsEcart){
  145.       afficher_note(4, note_5.x, 130, 130, note_5.v, display);
  146.     }
  147.       }
  148.  
  149.       //NOTE 6
  150.       if(random == 5){
  151.     note_6.i = true;
  152.     if(SDL_GetTicks()-lastTimeNote_6 >= tempsEcart){
  153.       afficher_note(5, note_6.x, 130, 130, note_6.v, display);
  154.     }
  155.       }
  156.  
  157.       //FIN APPARITION DES NOTES
  158.      
  159.       //RESET LES BOOL
  160.       if((note_1.x >= 650 && note_1.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_Q)){
  161.     note_1.i = false;
  162.     note_1.x = 0;
  163.     score += 2;
  164.     if(tempsEcart > 100){
  165.       tempsEcart -= 10;
  166.       note_1.v += 0.2;
  167.     }
  168.       }
  169.  
  170.       if((note_2.x >= 650 && note_2.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_W)){
  171.     note_2.i = false;
  172.     note_2.x = 0;
  173.     score += 2;
  174.     if(tempsEcart > 100){
  175.       tempsEcart -= 10;
  176.       note_2.v += 0.2;
  177.     }
  178.       }
  179.  
  180.       if((note_3.x >= 650 && note_3.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_E)){
  181.     note_3.i = false;
  182.     note_3.x = 0;
  183.     score += 2;
  184.     if(tempsEcart > 100){
  185.       tempsEcart -= 10;
  186.       note_3.v += 0.2;
  187.     }
  188.       }
  189.  
  190.       if((note_4.x >= 650 && note_4.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_R)){
  191.     note_4.i = false;
  192.     note_4.x = 0;
  193.     score += 2;
  194.     if(tempsEcart > 100){
  195.       tempsEcart -= 10;
  196.       note_4.v += 0.2;
  197.     }
  198.       }
  199.  
  200.       if((note_5.x >= 650 && note_5.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_T)){
  201.     note_5.i = false;
  202.     note_5.x = 0;
  203.     score += 2;
  204.     if(tempsEcart > 100){
  205.       tempsEcart -= 10;
  206.       note_5.v += 0.2;
  207.     }
  208.       }
  209.  
  210.       if((note_6.x >= 650 && note_6.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_Y)){
  211.     note_6.i = false;
  212.     note_6.x = 0;
  213.     score += 2;
  214.     if(tempsEcart > 100){
  215.       tempsEcart -= 10;
  216.       note_6.v += 0.2;
  217.     }
  218.       }
  219.      
  220.       if(note_1.x >= 900){
  221.     note_1.i = false;
  222.     note_1.x = 0;
  223.     vie--;
  224.       }
  225.  
  226.       if(note_2.x >= 900){
  227.     note_2.i = false;
  228.     note_2.x = 0;
  229.     vie--;
  230.       }
  231.  
  232.       if(note_3.x >= 900){
  233.     note_3.i = false;
  234.     note_3.x = 0;
  235.     vie--;
  236.       }
  237.  
  238.       if(note_4.x >= 900){
  239.     note_4.i = false;
  240.     note_4.x = 0;
  241.     vie--;
  242.       }
  243.  
  244.       if(note_5.x >= 900){
  245.     note_5.i = false;
  246.     note_5.x = 0;
  247.     vie--;
  248.       }
  249.  
  250.       if(note_6.x >= 900){
  251.     note_6.i = false;
  252.     note_6.x = 0;
  253.     vie--;
  254.       }
  255.  
  256.       if(input.getKeyStateOnce(SDL_SCANCODE_SPACE)){
  257.     note_1.i = false;
  258.     note_2.i = false;
  259.     note_3.i = false;
  260.     note_4.i = false;
  261.     note_5.i = false;
  262.     note_6.i = false;
  263.       }
  264.  
  265.       if(vie == 0){
  266.     display.clearScreen();
  267.     display.putRect(300, 300, 300, 300, Colors::Red);
  268.     display.refreshScreen();
  269.     SDL_Delay(2000);
  270.     exit(0);
  271.       }
  272.  
  273.       afficher_vie(vie, display);
  274.       afficher_lettres(display);
  275.      
  276.       display.refreshScreen();
  277.       input.flushEvents();
  278.     }
  279.   return (0);
  280. }
  281.  
  282. void afficher_barre(barre_t selectionBarre, SDLDisplay &display)
  283. {
  284.   //std::cout << "ICI C'EST POUR LA BARRE" << std::endl;
  285.   //INITIALISATION DE L'ECRAN
  286.   display.putRect(0, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Blue);
  287.   display.putRect(10, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  288.   display.putRect(150, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Yellow);
  289.   display.putRect(160, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  290.   display.putRect(300, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Red);
  291.   display.putRect(310, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  292.   display.putRect(450, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Orange);
  293.   display.putRect(460, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  294.   display.putRect(600, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Cyan);
  295.   display.putRect(610, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  296.   display.putRect(750, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Violet);
  297.   display.putRect(760, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
  298.   //FIN INITIALISATION
  299. }
  300.  
  301.  
  302. void afficher_note(int colonne, int &y, int largeur, int hauteur, int vitesse_descente, SDLDisplay &display)
  303. {
  304.   switch(colonne){
  305.    
  306.   case 0:
  307.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Blue);
  308.     break;
  309.  
  310.   case 1:
  311.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Yellow);
  312.     break;
  313.  
  314.   case 2:
  315.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Red);
  316.     break;
  317.  
  318.   case 3:
  319.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Orange);
  320.     break;
  321.  
  322.   case 4:
  323.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Cyan);
  324.     break;
  325.  
  326.   case 5:
  327.     display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Violet);
  328.     break;
  329.    
  330.   }
  331.   y += vitesse_descente;
  332.  
  333. }
  334.  
  335. void afficher_vie(int vie, SDLDisplay &display)
  336. {
  337.   for(int i (0); i < vie; i++){
  338.     display.putImage("assets/coeur.png", 900, 100 * i);
  339.   }
  340.  
  341. }
  342.  
  343. void afficher_lettres(SDLDisplay &display)
  344. {
  345.   display.putImage("assets/A.png",30,760);
  346.   display.putImage("assets/Z.png", 160, 760);
  347.   display.putImage("assets/E.png", 310, 760);
  348.   display.putImage("assets/R.png", 460, 760);
  349.   display.putImage("assets/T.png", 610, 760);
  350.   display.putImage("assets/Y.png", 760, 760);
  351. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement