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 "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,
- COLLONE_6
- };
- class FlashRoug
- {
- public:
- FlashRoug(){}
- static void play()
- {
- tempsLast = SDL_GetTicks();
- }
- static void affiche(SDLDisplay & a)
- {
- if(SDL_GetTicks() - tempsLast < 50)
- {
- a.putRect(0, 0, 900, 900, Colors::Red);
- }
- }
- private:
- const int duree = 100;
- static int tempsLast;
- };
- int FlashRoug::tempsLast = 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, y, largeur, hauteur, Colors::Green);
- break;
- case COLLONE_2:
- ecran.putRect(static_cast<int>(collone) * 150, y, largeur, hauteur, Colors::Blue);
- break;
- case COLLONE_3:
- ecran.putRect(static_cast<int>(collone) * 150, y, largeur, hauteur, Colors::Yellow);
- break;
- case COLLONE_4:
- ecran.putRect(static_cast<int>(collone) * 150, y, largeur, hauteur, Colors::Cyan);
- break;
- case COLLONE_5:
- ecran.putRect(static_cast<int>(collone) * 150, y, largeur, hauteur, Colors::Magenta);
- break;
- case COLLONE_6:
- ecran.putRect(static_cast<int>(collone) * 150, y, largeur, hauteur, Colors::Orange);
- break;
- }
- }
- }
- void descendre(int nbr, SDLDisplay & a)
- {
- if(presence)
- {
- if(SDL_GetTicks() - tempsLast > 20)
- {
- y += nbr;
- tempsLast = SDL_GetTicks();
- }
- if(y >= 900)
- {
- presence = false;
- FlashRoug::play();
- }
- }
- }
- bool testPresence()
- {
- return presence;
- }
- void testClic(Input & input, bool & pasFoire)
- {
- if(presence && LIGNE_TEST_CLIC > y && LIGNE_TEST_CLIC < y + hauteur )
- {
- switch(collone)
- {
- case COLLONE_1:
- if(input.getKeyStateOnce(SDL_SCANCODE_Q) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- case COLLONE_2:
- if(input.getKeyStateOnce(SDL_SCANCODE_W) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- case COLLONE_3:
- if(input.getKeyStateOnce(SDL_SCANCODE_E) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- case COLLONE_4:
- if(input.getKeyStateOnce(SDL_SCANCODE_R) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- case COLLONE_5:
- if(input.getKeyStateOnce(SDL_SCANCODE_T) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- case COLLONE_6:
- if(input.getKeyStateOnce(SDL_SCANCODE_T) )
- {
- presence = false;
- pasFoire = true;
- }
- break;
- }
- }
- }
- private:
- Collone collone;
- int y;
- static const int largeur = 150;
- 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() )
- {
- listCarre[i].change(c, y, hauteur);
- fait = true;
- }
- }
- if(!fait)
- {
- listCarre.push_back(Carre {c, y, hauteur});
- }
- }
- void afficher(SDLDisplay & a)
- {
- for(int i = 0 ; i < listCarre.size() ; i++)
- {
- listCarre[i].afficher(a);
- }
- }
- void descendre(int a, SDLDisplay & d)
- {
- for(int i = 0 ; i < listCarre.size() ; i++)
- {
- listCarre[i].descendre(a, d);
- }
- }
- void testClic(Input & in, SDLDisplay & d)
- {
- bool pasFoire;
- for(int i = 0 ; i < listCarre.size() ; i++)
- {
- listCarre[i].testClic(in, pasFoire);
- }
- if(!pasFoire)
- {
- FlashRoug::play();
- }
- }
- private :
- vector<Carre> listCarre;
- };
- 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);
- listCarre.add(COLLONE_6, 0, 100);
- while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
- {
- // code
- listCarre.descendre(5, display);
- listCarre.testClic(input, display);
- // affichage
- display.clearScreen(); // "Nettoie" la fenêtre
- FlashRoug::affiche(display);
- listCarre.afficher(display);
- display.putRect(0, LIGNE_TEST_CLIC, 900, 2, Colors::White);
- display.refreshScreen(); // Rafraîchit la fenêtre
- input.flushEvents(); // Met à jour les touches pressées / clics de souris
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement