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 "SDLDisplay.hpp"
- #include "Input.hpp"
- #include "Colors.hpp"
- #include "RNG.hpp"
- bool RNG::_initialized = false;
- typedef struct barre_s barre_t;
- struct barre_s{
- const int w = 150;
- const int h = 150;
- const int y = 750;
- };
- typedef struct note_s note_t;
- struct note_s{
- const int w = 10;
- const int h = 10;
- int x = 0;
- double v = 1.0;
- int couleur = 0;
- bool i = false;
- };
- void afficher_note(int colonne, int &y, int largeur, int longueur, int vitesse_descente, SDLDisplay &display);
- void afficher_barre(barre_t selectionBarre, SDLDisplay &display);
- void afficher_vie(int vie, SDLDisplay &display);
- void afficher_lettres(SDLDisplay &display);
- int main()
- {
- SDLDisplay display("minijeu", 1000, 900);
- Input input;
- // Les déclarations de variables se font ici
- bool continuer = false;
- int random = 0;
- int vie = 10;
- int score = 0;
- double tempsEcart = 2000;
- double lastTime = SDL_GetTicks();
- double lastTimeNote_1 = SDL_GetTicks();
- double lastTimeNote_2 = SDL_GetTicks();
- double lastTimeNote_3 = SDL_GetTicks();
- double lastTimeNote_4 = SDL_GetTicks();
- double lastTimeNote_5 = SDL_GetTicks();
- double lastTimeNote_6 = SDL_GetTicks();
- barre_t selectionBarre;
- note_t note_1;
- note_t note_2;
- note_t note_3;
- note_t note_4;
- note_t note_5;
- note_t note_6;
- note_2.couleur = 1;
- note_3.couleur = 2;
- note_4.couleur = 3;
- note_5.couleur = 4;
- note_6.couleur = 5;
- while(!continuer)
- {
- display.clearScreen();
- display.putText("Press 'E' to start", 450, 450, Colors::Red);
- if(input.getKeyStateOnce(SDL_SCANCODE_E)){
- continuer = true;
- }
- display.refreshScreen();
- input.flushEvents();
- }
- while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
- {
- display.clearScreen();
- // DEBUT DU CODE
- //FAIRE APPARAITRE LA BARRE EN BAS
- afficher_barre(selectionBarre, display);
- //APPARITION DES NOTES
- 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)){
- random = RNG::generate(6);
- lastTime = SDL_GetTicks();
- }
- //NOTE 1
- if(random == 0){
- note_1.i = true;
- if(SDL_GetTicks()-lastTimeNote_1 >= tempsEcart){
- afficher_note(0, note_1.x, 130, 130, note_1.v, display);
- }
- }
- //NOTE 2
- if(random == 1){
- note_2.i = true;
- if(SDL_GetTicks()-lastTimeNote_2 >= tempsEcart){
- afficher_note(1, note_2.x, 130, 130, note_2.v, display);
- }
- }
- //NOTE 3
- if(random == 2){
- note_3.i = true;
- if(SDL_GetTicks()-lastTimeNote_3 >= tempsEcart){
- afficher_note(2, note_3.x, 130, 130, note_3.v, display);
- }
- }
- //NOTE 4
- if(random == 3){
- note_4.i = true;
- if(SDL_GetTicks()-lastTimeNote_4 >= tempsEcart){
- afficher_note(3, note_4.x, 130, 130, note_4.v, display);
- }
- }
- //NOTE 5
- if(random == 4){
- note_5.i = true;
- if(SDL_GetTicks()-lastTimeNote_5 >= tempsEcart){
- afficher_note(4, note_5.x, 130, 130, note_5.v, display);
- }
- }
- //NOTE 6
- if(random == 5){
- note_6.i = true;
- if(SDL_GetTicks()-lastTimeNote_6 >= tempsEcart){
- afficher_note(5, note_6.x, 130, 130, note_6.v, display);
- }
- }
- //FIN APPARITION DES NOTES
- //RESET LES BOOL
- if((note_1.x >= 650 && note_1.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_Q)){
- note_1.i = false;
- note_1.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_1.v += 0.2;
- }
- }
- if((note_2.x >= 650 && note_2.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_W)){
- note_2.i = false;
- note_2.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_2.v += 0.2;
- }
- }
- if((note_3.x >= 650 && note_3.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_E)){
- note_3.i = false;
- note_3.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_3.v += 0.2;
- }
- }
- if((note_4.x >= 650 && note_4.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_R)){
- note_4.i = false;
- note_4.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_4.v += 0.2;
- }
- }
- if((note_5.x >= 650 && note_5.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_T)){
- note_5.i = false;
- note_5.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_5.v += 0.2;
- }
- }
- if((note_6.x >= 650 && note_6.x < 900) && input.getKeyStateOnce(SDL_SCANCODE_Y)){
- note_6.i = false;
- note_6.x = 0;
- score += 2;
- if(tempsEcart > 100){
- tempsEcart -= 10;
- note_6.v += 0.2;
- }
- }
- if(note_1.x >= 900){
- note_1.i = false;
- note_1.x = 0;
- vie--;
- }
- if(note_2.x >= 900){
- note_2.i = false;
- note_2.x = 0;
- vie--;
- }
- if(note_3.x >= 900){
- note_3.i = false;
- note_3.x = 0;
- vie--;
- }
- if(note_4.x >= 900){
- note_4.i = false;
- note_4.x = 0;
- vie--;
- }
- if(note_5.x >= 900){
- note_5.i = false;
- note_5.x = 0;
- vie--;
- }
- if(note_6.x >= 900){
- note_6.i = false;
- note_6.x = 0;
- vie--;
- }
- if(input.getKeyStateOnce(SDL_SCANCODE_SPACE)){
- note_1.i = false;
- note_2.i = false;
- note_3.i = false;
- note_4.i = false;
- note_5.i = false;
- note_6.i = false;
- }
- if(vie == 0){
- display.clearScreen();
- display.putRect(300, 300, 300, 300, Colors::Red);
- display.refreshScreen();
- SDL_Delay(2000);
- exit(0);
- }
- afficher_vie(vie, display);
- afficher_lettres(display);
- display.refreshScreen();
- input.flushEvents();
- }
- return (0);
- }
- void afficher_barre(barre_t selectionBarre, SDLDisplay &display)
- {
- //std::cout << "ICI C'EST POUR LA BARRE" << std::endl;
- //INITIALISATION DE L'ECRAN
- display.putRect(0, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Blue);
- display.putRect(10, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- display.putRect(150, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Yellow);
- display.putRect(160, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- display.putRect(300, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Red);
- display.putRect(310, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- display.putRect(450, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Orange);
- display.putRect(460, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- display.putRect(600, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Cyan);
- display.putRect(610, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- display.putRect(750, selectionBarre.y, selectionBarre.w, selectionBarre.h, Colors::Violet);
- display.putRect(760, selectionBarre.y+10, selectionBarre.w-20, selectionBarre.h-20, Colors::White);
- //FIN INITIALISATION
- }
- void afficher_note(int colonne, int &y, int largeur, int hauteur, int vitesse_descente, SDLDisplay &display)
- {
- switch(colonne){
- case 0:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Blue);
- break;
- case 1:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Yellow);
- break;
- case 2:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Red);
- break;
- case 3:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Orange);
- break;
- case 4:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Cyan);
- break;
- case 5:
- display.putRect(colonne * 150 + 10, y, largeur, hauteur, Colors::Violet);
- break;
- }
- y += vitesse_descente;
- }
- void afficher_vie(int vie, SDLDisplay &display)
- {
- for(int i (0); i < vie; i++){
- display.putImage("assets/coeur.png", 900, 100 * i);
- }
- }
- void afficher_lettres(SDLDisplay &display)
- {
- display.putImage("assets/A.png",30,760);
- display.putImage("assets/Z.png", 160, 760);
- display.putImage("assets/E.png", 310, 760);
- display.putImage("assets/R.png", 460, 760);
- display.putImage("assets/T.png", 610, 760);
- display.putImage("assets/Y.png", 760, 760);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement