Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2019
- ** guitarhero
- ** File description:
- ** main
- */
- #include <unistd.h>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <fstream>
- #include <string>
- #include "SDLDisplay.hpp"
- #include "Input.hpp"
- #include "Colors.hpp" // ici les couleurs
- #include "RNG.hpp"
- bool RNG::_initialized = false;
- #define LIGNE_TEST_CLIC 750
- using namespace std;
- enum Collone
- {
- COLLONE_1,
- COLLONE_2,
- COLLONE_3,
- COLLONE_4,
- COLLONE_5
- };
- class FlashRoug
- {
- public:
- FlashRoug(){}
- static void play() // FlasRoug::play()
- {
- tempsLast = SDL_GetTicks();
- }
- static void affiche(SDLDisplay & a)
- {
- if(SDL_GetTicks() - tempsLast < 50)
- {
- a.putRect(150, 0, 750, 900, Colors::Red);
- }
- }
- private:
- const int duree = 100;
- static int tempsLast;
- };
- int FlashRoug::tempsLast = 0;
- class Score
- {
- public:
- static void reset()
- {
- score = 0;
- }
- static void perfect()
- {
- suite++;
- score += 5000 * multiply();
- cout << "PARFAIT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
- }
- static void normal()
- {
- cout << "touche !!!!!!!!!!!!!!"<<endl;
- suite++;
- score += 1000 * multiply();
- }
- static void rate()
- {
- cout << "rate !" << endl;
- score -= 500;
- suite = 0;
- FlashRoug::play();
- }
- static void malTouche()
- {
- FlashRoug::play();
- cout << "hum hum..." << endl;
- score -= 100;
- suite = 0;
- }
- static int multiply()
- {
- return (suite / 5 )+ 1;
- }
- static long int getScore()
- {
- return score;
- }
- private:
- static long int score;
- static int suite;
- };
- long int Score::score = 0;
- int Score::suite = 0;
- void affichScore(SDLDisplay & a)
- {
- string nbr { to_string( Score::getScore() ) };
- for(unsigned int i = 0 ; i < nbr.size() ; i++)
- {
- string b;
- b += "0";
- b += nbr[i];
- b += ".png";
- a.putImage(b , 40 * i, 0);
- }
- }
- class Carre
- {
- public:
- Carre(Collone c_, int y_, int hauteur_)
- {
- collone = c_;
- y = y_;
- hauteur = hauteur_;
- tempsLast = SDL_GetTicks();
- presence = true;
- }
- void change(Collone c_, int y_, int hauteur_)
- {
- collone = c_;
- y = y_;
- hauteur = hauteur_;
- tempsLast = SDL_GetTicks();
- presence = true;
- }
- void afficher(SDLDisplay & ecran)
- {
- if(presence)
- {
- switch(collone)
- {
- case COLLONE_1:
- ecran.putRect(static_cast<int>(collone) * 150 + 150 + 10, y, largeur, hauteur, Colors::Green);
- break;
- case COLLONE_2:
- ecran.putRect(static_cast<int>(collone) * 150 + 150 + 10, y, largeur, hauteur, Colors::Blue);
- break;
- case COLLONE_3:
- ecran.putRect(static_cast<int>(collone) * 150 + 150 + 10, y, largeur, hauteur, Colors::Yellow);
- break;
- case COLLONE_4:
- ecran.putRect(static_cast<int>(collone) * 150 + 150 + 10, y, largeur, hauteur, Colors::Cyan);
- break;
- case COLLONE_5:
- ecran.putRect(static_cast<int>(collone) * 150 + 150 + 10, y, largeur, hauteur, Colors::Magenta);
- break;
- }
- ecran.putRect(static_cast<int>(collone) * 150 + 150 +10 + 20, y + (45.0 / 100.0 * hauteur), largeur -40, (10.0/100.0 * hauteur), Colors::Fushia);
- }
- }
- void descendre(int nbr)
- {
- if(presence)
- {
- if(SDL_GetTicks() - tempsLast > 20)
- {
- y += nbr;
- tempsLast = SDL_GetTicks();
- }
- if(y >= 900)
- {
- presence = false;
- cout << "a pu" << endl;
- Score::rate();
- }
- }
- }
- bool testPresence()
- {
- return presence;
- }
- bool bienPlace()
- {
- if(LIGNE_TEST_CLIC + 10 > y && LIGNE_TEST_CLIC < y + hauteur + 10 )
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- Collone getCollone()
- {
- return collone;
- }
- void clique()
- {
- cout << "tu te caches maintenant" << endl;
- presence = false;
- }
- bool testPerfect()
- {
- if(y + (45.0 / 100 * hauteur) <= LIGNE_TEST_CLIC && y + (55.0 / 100 * hauteur >= LIGNE_TEST_CLIC ) )//testPerfect
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- private:
- Collone collone;
- int y;
- static const int largeur = 130;
- int hauteur;
- int tempsLast;
- bool presence;
- };
- class ListeCarre
- {
- public:
- void add(Collone c, int y , int hauteur)
- {
- bool fait = false;
- for(int i = 0 ; i < listCarre.size() ; i++)
- {
- if(!listCarre[i].testPresence() && !fait)
- {
- listCarre[i].change(c, y, hauteur);
- fait = true;
- }
- }
- if(!fait)
- {
- listCarre.push_back(Carre {c, y, hauteur});
- }
- }
- void afficher(SDLDisplay & a)
- {
- for(unsigned int i = 0 ; i < listCarre.size() ; i++)
- {
- listCarre[i].afficher(a);
- }
- }
- void descendre(int a)
- {
- for(unsigned int i = 0 ; i < listCarre.size() ; i++)
- {
- listCarre[i].descendre(a);
- }
- }
- void testClic(Input & input)
- {
- bool pasFoire = true;
- if(input.getKeyStateOnce(SDL_SCANCODE_Q) )
- {
- if( !testPosEach(COLLONE_1) )
- {
- pasFoire = false;
- }
- }
- if(input.getKeyStateOnce(SDL_SCANCODE_W) )
- {
- if( !testPosEach(COLLONE_2) )
- {
- pasFoire = false;
- }
- }
- if(input.getKeyStateOnce(SDL_SCANCODE_E) )
- {
- if( !testPosEach(COLLONE_3) )
- {
- pasFoire = false;
- }
- }
- if(input.getKeyStateOnce(SDL_SCANCODE_R) )
- {
- if( !testPosEach(COLLONE_4) )
- {
- pasFoire = false;
- }
- }
- if(input.getKeyStateOnce(SDL_SCANCODE_T) )
- {
- if( !testPosEach(COLLONE_5) )
- {
- pasFoire = false;
- }
- }
- if(!pasFoire)
- {
- Score::malTouche();
- }
- }
- bool testPosEach(Collone const & co)
- {
- for(unsigned int i = 0; i < listCarre.size() ; i++)
- {
- if(listCarre[i].bienPlace() && co == listCarre[i].getCollone() && listCarre[i].testPresence() )
- {
- listCarre[i].clique();
- if(listCarre[i].testPerfect() )
- {
- Score::perfect();
- }
- else
- {
- Score::normal();
- }
- return true;
- }
- }
- cout << "pas chaché mé appuyé" << endl;
- return false;
- }
- private :
- vector<Carre> listCarre;
- };
- class LirMus
- {
- public:
- static void lirNote(ListeCarre & a)
- {
- if(fichier)
- {
- if(SDL_GetTicks() - tempsLast >= 1000)
- {
- string ligne;
- int colloneInt;
- fichier >> colloneInt;
- getline(fichier, ligne);
- Collone c = static_cast<Collone>(colloneInt);
- a.add(c, 0, 100);
- tempsLast = SDL_GetTicks();
- }
- }
- }
- private:
- static int tempsLast;
- static ifstream fichier;
- };
- int LirMus::tempsLast = 0;
- ifstream LirMus::fichier {R"(musique1.mus)"};
- int main()
- {
- /* Gestion de la fenêtre */
- SDLDisplay display("minijeu", 900, 900);
- /* Gestion des touches */
- Input input;
- // Les déclarations de variables se font ici
- ListeCarre listCarre;
- listCarre.add(COLLONE_1, 0, 100);
- listCarre.add(COLLONE_2, 0, 100);
- listCarre.add(COLLONE_3, 0, 100);
- listCarre.add(COLLONE_4, 0, 100);
- listCarre.add(COLLONE_5, 0, 100);
- while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
- {
- // code
- listCarre.descendre(5);
- listCarre.testClic(input);
- LirMus::lirNote(listCarre);
- // affichage
- display.clearScreen(); // "Nettoie" la fenêtre
- FlashRoug::affiche(display);
- display.putRect(150, LIGNE_TEST_CLIC, 900 - 150, 2, Colors::White);
- display.putRect(145, 0, 5, 900, Colors::White);
- display.putRect(160, LIGNE_TEST_CLIC + 10, 130, 130, Colors::Green);
- display.putRect(310, LIGNE_TEST_CLIC + 10, 130, 130, Colors::Blue);
- display.putRect(460, LIGNE_TEST_CLIC + 10, 130, 130, Colors::Yellow);
- display.putRect(610, LIGNE_TEST_CLIC + 10, 130, 130, Colors::Cyan);
- display.putRect(760, LIGNE_TEST_CLIC + 10, 130, 130, Colors::Magenta);
- display.putRect(170, LIGNE_TEST_CLIC + 30, 110, 110, Colors::Black);
- display.putRect(320, LIGNE_TEST_CLIC + 30, 110, 110, Colors::Black);
- display.putRect(470, LIGNE_TEST_CLIC + 30, 110, 110, Colors::Black);
- display.putRect(620, LIGNE_TEST_CLIC + 30, 110, 110, Colors::Black);
- display.putRect(770, LIGNE_TEST_CLIC + 30, 110, 110, Colors::Black);
- display.putRect(300, 0, 1, LIGNE_TEST_CLIC, Colors::White);
- display.putRect(450, 0, 1, LIGNE_TEST_CLIC, Colors::White);
- display.putRect(600, 0, 1, LIGNE_TEST_CLIC, Colors::White);
- display.putRect(750, 0, 1, LIGNE_TEST_CLIC, Colors::White);
- listCarre.afficher(display);
- affichScore(display);
- display.refreshScreen(); // Rafraîchit la fenêtre
- input.flushEvents(); // Met à jour les touches pressées / clics de souris
- SDL_Delay(1);
- }
- cout << Score::getScore() << endl;
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement